Skip to content

Commit

Permalink
[GR-12293] Look into sqldf package.
Browse files Browse the repository at this point in the history
PullRequest: fastr/1793
  • Loading branch information
tomasstupka committed Nov 21, 2018
2 parents 64a7def + 4ab1fbe commit 3389c8c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Bug fixes:
* `format.POSIXlt` uses the same time zone database as rest of the system. #29
* `dev.control(displaylist = 'inhibit')` caused `ClassCastException`
* `download.file` follows redirects.
* Static members of Java interop objects are not ignroed during printing and deparsing.
* Static members of Java interop objects are not ignored during printing and deparsing.
* fixed internal error in `on.exit(NULL)`
* fixed `mget` to accept also non list values for `ifnotfound`


# 1.0 RC 9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ public Object Rf_allocVector(int mode, long n) {
case LISTSXP:
case LANGSXP:
return RDataFactory.createPairList(ni, type);
case NILSXP:
return RNull.instance;
default:
throw unimplemented("unexpected SEXPTYPE " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode;
import com.oracle.truffle.r.nodes.attributes.TypeFromModeNode;
import com.oracle.truffle.r.nodes.attributes.TypeFromModeNodeGen;
import com.oracle.truffle.r.nodes.binary.CastTypeNode;
import com.oracle.truffle.r.nodes.binary.CastTypeNodeGen;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.builtin.base.Eval.EvalEnvCast;
import com.oracle.truffle.r.nodes.function.PromiseHelperNode;
Expand All @@ -64,7 +66,6 @@
import com.oracle.truffle.r.runtime.data.RPromise;
import com.oracle.truffle.r.runtime.data.RS4Object;
import com.oracle.truffle.r.runtime.data.RSymbol;
import com.oracle.truffle.r.runtime.data.model.RAbstractListVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
Expand Down Expand Up @@ -257,7 +258,6 @@ public abstract static class MGet extends RBuiltinNode.Arg5 {
casts.arg("x").mustBe(stringValue()).asStringVector();
casts.arg("envir").mustBe(instanceOf(REnvironment.class).or(instanceOf(RS4Object.class)), RError.Message.MUST_BE_ENVIRON2, "second argument");
casts.arg("mode").mustBe(stringValue()).asStringVector();
casts.arg("ifnotfound").mustBe(RAbstractListVector.class);
casts.arg("inherits").asLogicalVector().findFirst().map(toBoolean());
}

Expand Down Expand Up @@ -359,6 +359,20 @@ protected RList mget(VirtualFrame frame, RAbstractStringVector xv, RS4Object s4E
return mget(frame, xv, (REnvironment) s4ToEnv.execute(s4Envir), mode, ifNotFound, inherits, argsAndValuesProfile, missingProfile, inheritsProfile);
}

@Specialization
protected RList mget(VirtualFrame frame, RAbstractStringVector xv, REnvironment env, RAbstractStringVector mode, Object ifNotFound, boolean inherits,
@Cached("createBinaryProfile()") ConditionProfile argsAndValuesProfile,
@Cached("createBinaryProfile()") ConditionProfile missingProfile,
@Cached("createBinaryProfile()") ConditionProfile inheritsProfile,
@Cached("createCastType()") CastTypeNode castTypeNode) {
Object l = castTypeNode.execute(ifNotFound, RType.List);
return mget(frame, xv, env, mode, (RList) l, inherits, argsAndValuesProfile, missingProfile, inheritsProfile);
}

protected static CastTypeNode createCastType() {
return CastTypeNodeGen.create();
}

private void doIfNotFound(VirtualFrame frame, State state, int i, String x, RList ifNotFound) {
if (state.ifnFunc != null) {
state.data[i] = call(frame, state.ifnFunc, x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ protected Object onExit(VirtualFrame frame, RPromise expr, boolean add) {
assert expr.getRep() instanceof ConstantNode : "only ConstantNode expected for defaulted promise";
FrameSlotChangeMonitor.setObject(frame, onExitSlot, RDataFactory.createPairList());
} else {
assert !expr.isEvaluated() : "promise cannot already be evaluated";
// if optimized then avaluated already true,
// otherwise he expresion has to be evaluated exactly at this point
assert expr.isOptimized() || !expr.isEvaluated() : "promise cannot already be evaluated";
Object value;
try {
value = FrameSlotChangeMonitor.getObject(onExitSlot, frame);
Expand Down
3 changes: 2 additions & 1 deletion com.oracle.truffle.r.test.packages/gated
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ compare
shinythemes
ROCR
quantmod
reshape2
reshape2
sqldf
3 changes: 2 additions & 1 deletion com.oracle.truffle.r.test.packages/r/install.packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ ignore.suggests <- list(
glmnet = 'knitr', # probably used for vignettes only
PerformanceAnalytics = ignore.all.but('testthat'), # not gated yet. We can run almost all tests except for few examples that use some suggests including data.table
mboost = ignore.all.but('TH.data', 'survival', 'RColorBrewer'), # this pkg has only vignettes and grepping then gave these libs
quantmod = '*' # probably not necessary, the tests output does not contain any 'library', 'require' or 'load' calls
quantmod = '*', # probably not necessary, the tests output does not contain any 'library', 'require' or 'load' calls
sqldf = 'tcltk|RPostgreSQL|RJDBC|rJava|RH2' # tcltk not on CRAN, RPostgreSQL can't be installed, RH2 and RJDBC depend on rJava which can't be installed
)

choice.depends <- function(pkg, choice=c("direct","suggests")) {
Expand Down
2 changes: 1 addition & 1 deletion com.oracle.truffle.r.test.packages/test.mx.args
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-DR:+IgnoreGraphicsCalls
-DR:AdditionalOptions=vdiffr_skip:T
-DR:AdditionalOptions=vdiffr_skip:T;svUnit.recordAll:F;svUnit.minTiming:10000

5 changes: 5 additions & 0 deletions com.oracle.truffle.r.test.packages/test.output.filter
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ ROCR => D/detaching ‘ROCR.hiv’
quantmod => D-2/ PDF device not supported.
quantmod => D/ incomplete final line found
quantmod => s/There were [0-9]+ warnings \(use warnings\(\) to see them\)/

# --------
sqldf => D/A svUnit test suite run in
sqldf => D/test.all (in runit.all.R) run in
sqldf => d/\>
Original file line number Diff line number Diff line change
Expand Up @@ -44058,6 +44058,29 @@ FALSE
...
TRUE

##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget('abc', ifnotfound = 'a')
$abc
[1] "a"


##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget('abc', ifnotfound = NA)
$abc
[1] NA


##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget('abc', ifnotfound = NA_complex_)
$abc
[1] NA


##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget('abc', ifnotfound = c('a1', 'b1'))
Error in mget("abc", ifnotfound = c("a1", "b1")) :
wrong length for 'ifnotfound' argument

##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget('abc', ifnotfound = list(`[`))
$abc
Expand All @@ -44078,6 +44101,20 @@ $abc
NULL


##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget(c('a', 'b'), ifnotfound = c('a1', 'b1'))
$a
[1] "a1"

$b
[1] "b1"


##com.oracle.truffle.r.test.builtins.TestBuiltin_mget.testWithIfnotfound#
#mget(c('a', 'b'), ifnotfound = new.env())
Error in mget(c("a", "b"), ifnotfound = new.env()) :
environments cannot be coerced to other types

##com.oracle.truffle.r.test.builtins.TestBuiltin_min.testMinimum#
#min(c(1,NA,2), na.rm=NA)
[1] 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,13 @@ public void testWithIfnotfound() {
assertEval("mget('abc', ifnotfound = list(`[`))");
assertEval("mget('abc', ifnotfound = list(function(x) cat('NOT FOUND', x, '\\n')))");
assertEval("mget('abc', ifnotfound = list(function(x, y = 'default value') cat('NOT FOUND', x, ',', y, '\\n')))");

assertEval("mget('abc', ifnotfound = NA)");
assertEval("mget('abc', ifnotfound = NA_complex_)");
assertEval("mget('abc', ifnotfound = 'a')");
assertEval("mget('abc', ifnotfound = c('a1', 'b1'))");
assertEval("mget(c('a', 'b'), ifnotfound = c('a1', 'b1'))");
assertEval("mget(c('a', 'b'), ifnotfound = new.env())");

}
}

0 comments on commit 3389c8c

Please sign in to comment.