Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuzatu-Marian committed May 16, 2024
1 parent 8e801bc commit ec4e7d1
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 27 deletions.
9 changes: 8 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ SpotlessTest:

MLTests:
stage: tests3
artifacts:
name: "ML Tests log"
paths:
- target/ml_test.log
when:
always
expire_in: 2 days
script:
- mvn -Dtest=MLTests test
- mvn -Dtest=MLTests test --log-file target/ml_test.log

MLTestsNativeDeactivated:
stage: tests3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.rumbledb.expressions.flowr.WhereClause;
import org.rumbledb.expressions.module.VariableDeclaration;
import org.rumbledb.expressions.primary.FunctionCallExpression;
import org.rumbledb.expressions.primary.InlineFunctionExpression;
import org.rumbledb.expressions.scripting.block.BlockExpression;
import org.rumbledb.expressions.scripting.loops.ReturnStatementClause;
import org.rumbledb.expressions.scripting.statement.StatementsAndExpr;
Expand Down Expand Up @@ -58,6 +59,10 @@ protected ExpressionClassification defaultAction(Node node, ExpressionClassifica
((StatementsAndOptionalExpr) node).setExpressionClassification(expressionClassification);
return expressionClassification;
}
if (node instanceof InlineFunctionExpression) {
((InlineFunctionExpression) node).setExpressionClassification(expressionClassification);
return expressionClassification;
}
if (expressionClassification.isUpdating()) {
throw new InvalidUpdatingExpressionPositionException(
"Operand of expression is Updating when it should be Simple or Vacuous",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,18 @@ public DescendentSequentialProperties visitProlog(Prolog node, DescendentSequent
.forEach(
libraryModule -> visit(libraryModule, argument)
);
node.getFunctionDeclarations()
// Visit variables first as they may be modified in a function.
node.getVariableDeclarations()
.forEach(
functionDeclaration -> visit(
functionDeclaration,
variableDeclaration -> visit(
variableDeclaration,
argument
)
);
node.getVariableDeclarations()
node.getFunctionDeclarations()
.forEach(
variableDeclaration -> visit(
variableDeclaration,
functionDeclaration -> visit(
functionDeclaration,
argument
)
);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/rumbledb/context/VariableValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

public class VariableValues implements Serializable, KryoSerializable {

Expand All @@ -54,7 +53,6 @@ public class VariableValues implements Serializable, KryoSerializable {
private Map<Name, Item> localVariableCounts;
private Map<Name, JavaRDD<Item>> rddVariableValues;
private Map<Name, JSoundDataFrame> dataFrameVariableValues;
private Stack<VariableMapAndPrevValue> variableDeclarationOverwrites;
private boolean nestedQuery;
private VariableValues parent;

Expand All @@ -65,7 +63,6 @@ public VariableValues() {
this.rddVariableValues = new HashMap<>();
this.dataFrameVariableValues = new HashMap<>();
this.nestedQuery = false;
this.variableDeclarationOverwrites = new Stack<>();
}

public VariableValues(VariableValues parent) {
Expand All @@ -78,7 +75,6 @@ public VariableValues(VariableValues parent) {
this.rddVariableValues = new HashMap<>();
this.dataFrameVariableValues = new HashMap<>();
this.nestedQuery = false;
this.variableDeclarationOverwrites = new Stack<>();
}

public VariableValues(
Expand All @@ -96,7 +92,6 @@ public VariableValues(
this.rddVariableValues = rddVariableValues;
this.dataFrameVariableValues = dataFrameVariableValues;
this.nestedQuery = false;
this.variableDeclarationOverwrites = new Stack<>();
}

public void setBindingsFromTuple(FlworTuple tuple, ExceptionMetadata metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ protected void closeLocal() {
if (this.userDefinedFunctionCallIterator != null && this.userDefinedFunctionCallIterator.isOpen()) {
this.userDefinedFunctionCallIterator.close();
}
this.userDefinedFunctionCallIterator = null;
}

public void setNextResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.rumbledb.items.structured.JSoundDataFrame;
import org.rumbledb.runtime.HybridRuntimeIterator;
import org.rumbledb.runtime.RuntimeIterator;
import org.rumbledb.runtime.update.PendingUpdateList;
import sparksoniq.spark.SparkSessionManager;

import java.util.List;
Expand Down Expand Up @@ -155,4 +156,12 @@ public JSoundDataFrame getDataFrame(DynamicContext dynamicContext) {
return exprIterator.getDataFrame(dynamicContext);
}

@Override
public PendingUpdateList getPendingUpdateList(DynamicContext context) {
RuntimeIterator exprIterator = this.children.get(this.children.size() - 1);
if (exprIterator.isUpdating()) {
return exprIterator.getPendingUpdateList(context);
}
return new PendingUpdateList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.rumbledb.context.RuntimeStaticContext;
import org.rumbledb.runtime.AtMostOneItemLocalRuntimeIterator;
import org.rumbledb.runtime.RuntimeIterator;
import org.rumbledb.runtime.update.PendingUpdateList;

import java.util.Collections;

Expand All @@ -31,12 +30,4 @@ public Item materializeFirstItemOrNull(DynamicContext context) {
}
return null;
}

@Override
public PendingUpdateList getPendingUpdateList(DynamicContext context) {
if (!this.exprIterator.isUpdating()) {
return new PendingUpdateList();
}
return this.exprIterator.getPendingUpdateList(context);
}
}
68 changes: 68 additions & 0 deletions src/test/resources/queries/user-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"user_id": "583c3ac3f38e84297c002546",
"email": "[email protected]",
"name": "[email protected]",
"given_name": "Hello",
"family_name": "Test",
"nickname": "test",
"last_ip": "94.121.163.63",
"logins_count": 15,
"created_at": "2016-11-28T14:10:11.338Z",
"updated_at": "2016-12-02T01:17:29.310Z",
"last_login": "2016-12-02T01:17:29.310Z",
"email_verified": true
},
{
"user_id": "583c5484cb79a5fe593425a9",
"email": "[email protected]",
"name": "[email protected]",
"given_name": "Hello1",
"family_name": "Test1",
"nickname": "test1",
"last_ip": "94.121.168.53",
"logins_count": 1,
"created_at": "2016-11-28T16:00:04.209Z",
"updated_at": "2016-11-28T16:00:47.203Z",
"last_login": "2016-11-28T16:00:47.203Z",
"email_verified": true
},
{
"user_id": "583c57672c7686377d2f66c9",
"email": "[email protected]",
"name": "[email protected]",
"given_name": "John",
"family_name": "Dough",
"nickname": "aaa",
"last_ip": "94.121.168.53",
"logins_count": 2,
"created_at": "2016-11-28T16:12:23.777Z",
"updated_at": "2016-11-28T16:12:52.353Z",
"last_login": "2016-11-28T16:12:52.353Z",
"email_verified": true
},
{
"user_id": "5840b954da0529cd293d76fe",
"email": "[email protected]",
"name": "[email protected]",
"given_name": "Jane",
"family_name": "Dough",
"nickname": "a",
"last_ip": "94.121.163.63",
"logins_count": 3,
"created_at": "2016-12-01T23:59:16.473Z",
"updated_at": "2016-12-01T23:59:53.474Z",
"last_login": "2016-12-01T23:59:53.474Z",
"email_verified": true
},
{
"user_id": "584a9d13e808bcf75f05f580",
"email": "[email protected]",
"name": "[email protected]",
"given_name": "Dummy",
"family_name": "User",
"created_at": "2016-12-09T12:01:23.787Z",
"updated_at": "2016-12-09T12:01:23.787Z",
"email_verified": false
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(:JIQS: ShouldRun; Output="({ "label" : 0, "name" : "a", "age" : 20, "weight" : 50, "prediction" : 0.1830300025234468 }, { "label" : 1, "name" : "b", "age" : 21, "weight" : 55.3, "prediction" : 1.120615775223607 }, { "label" : 2, "name" : "c", "age" : 22, "weight" : 60.6, "prediction" : 2.058201547923767 }, { "label" : 3, "name" : "d", "age" : 23, "weight" : 65.9, "prediction" : 2.995787320623929 }, { "label" : 4, "name" : "e", "age" : 24, "weight" : 70.3, "prediction" : 3.852389790502542 }, { "label" : 5, "name" : "f", "age" : 25, "weight" : 75.6, "prediction" : 4.789975563202702 })" :)
(:JIQS: ShouldRun; Output="({ "label" : 0, "name" : "a", "age" : 20, "weight" : 50, "prediction" : 0.18303001 }, { "label" : 1, "name" : "b", "age" : 21, "weight" : 55.3, "prediction" : 1.1206157 }, { "label" : 2, "name" : "c", "age" : 22, "weight" : 60.6, "prediction" : 2.0582016 }, { "label" : 3, "name" : "d", "age" : 23, "weight" : 65.9, "prediction" : 2.9957874 }, { "label" : 4, "name" : "e", "age" : 24, "weight" : 70.3, "prediction" : 3.8523898 }, { "label" : 5, "name" : "f", "age" : 25, "weight" : 75.6, "prediction" : 4.7899756 })" :)
declare function local:round($i as double) as float {
float($i)
};
let $data := annotate(
json-file("../../../../queries/rumbleML/sample-ml-data-flat.json"),
{ "label": "integer", "binaryLabel": "integer", "name": "string", "age": "double", "weight": "double", "booleanCol": "boolean", "nullCol": "null", "stringCol": "string", "stringArrayCol": ["string"], "intArrayCol": ["integer"], "doubleArrayCol": ["double"], "doubleArrayArrayCol": [["double"]] }
Expand All @@ -20,5 +23,5 @@ return {
"name": $result.name,
"age": $result.age,
"weight": $result.weight,
"prediction": $result.prediction
"prediction": local:round($result.prediction)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(:JIQS: ShouldRun; Output="({ "label" : 0, "name" : "a", "age" : 20, "weight" : 50, "prediction" : 0.3713412984815463 }, { "label" : 1, "name" : "b", "age" : 21, "weight" : 55.3, "prediction" : 1.2326248933307706 }, { "label" : 2, "name" : "c", "age" : 22, "weight" : 60.6, "prediction" : 2.0939084881799968 }, { "label" : 3, "name" : "d", "age" : 23, "weight" : 65.9, "prediction" : 2.955192083029223 }, { "label" : 4, "name" : "e", "age" : 24, "weight" : 70.3, "prediction" : 3.742824821064616 }, { "label" : 5, "name" : "f", "age" : 25, "weight" : 75.6, "prediction" : 4.604108415913839 })" :)
(:JIQS: ShouldRun; Output="({ "label" : 0, "name" : "a", "age" : 20, "weight" : 50, "prediction" : 0.3713413 }, { "label" : 1, "name" : "b", "age" : 21, "weight" : 55.3, "prediction" : 1.2326249 }, { "label" : 2, "name" : "c", "age" : 22, "weight" : 60.6, "prediction" : 2.0939085 }, { "label" : 3, "name" : "d", "age" : 23, "weight" : 65.9, "prediction" : 2.955192 }, { "label" : 4, "name" : "e", "age" : 24, "weight" : 70.3, "prediction" : 3.7428248 }, { "label" : 5, "name" : "f", "age" : 25, "weight" : 75.6, "prediction" : 4.6041083 })" :)
declare function local:round($i as double) as float {
float($i)
};
let $data := annotate(
json-file("../../../../queries/rumbleML/sample-ml-data-flat.json"),
{ "label": "integer", "binaryLabel": "integer", "name": "string", "age": "double", "weight": "double", "booleanCol": "boolean", "nullCol": "null", "stringCol": "string", "stringArrayCol": ["string"], "intArrayCol": ["integer"], "doubleArrayCol": ["double"], "doubleArrayArrayCol": [["double"]] }
Expand All @@ -20,5 +23,5 @@ return {
"name": $result.name,
"age": $result.age,
"weight": $result.weight,
"prediction": $result.prediction
"prediction": local:round($result.prediction)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(:JIQS: ShouldRun; Output="10000" :)
(:JIQS: ShouldRun; Output="100" :)
exit returning count(
let $j := 10000
let $j := 100
return annotate(for $i in 1 to $j return {"foo" : "bar"},{"foo":"string"})
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(:JIQS: ShouldRun; Output="{ "name" : "[email protected]", "user_id" : "583c57672c7686377d2f66c9", "failed" : false, "email_verified" : true, "access-attempt" : "2016-11-28T16:00:47.203Z" }" :)
declare function local:validate-and-log($username as xs:string) {
variable $user-doc := json-doc("../../../queries/user-names.json");
variable $log as object := {};
variable $user-entry := {
"access-attempt": fn:current-time(),
"name": "[email protected]",
"user_id": "583c57672c7686377d2f66c9",
"email_verified": false,
"failed": false
};
variable $changed := false;
if ($username eq $user-doc[[3]].name) then {
replace json value of $user-entry.email_verified with true;
replace json value of $user-entry.access-attempt with "2016-11-28T16:00:47.203Z";
$changed := true;
} else {
replace json value of $user-entry.failed with true;
}
if ($changed eq true) then {
insert json $user-entry into $log;
} else {
exit returning {"failure": true};
}
$log
};
local:validate-and-log("[email protected]")
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(:JIQS: ShouldNotCompile; Error="XPST0008"; ErrorMetadata="LINE:14:COLUMN:27:" :)
declare function local:validate-and-return($username as xs:string) {
variable $user-doc := json-doc("../../../queries/user-names.json");
variable $log as object := {};
variable $user-entry := {
"access-attempt": fn:current-time(),
"name": "[email protected]",
"user_id": "583c57672c7686377d2f66c9",
"email_verified": false,
"failed": false
};
variable $changed := false;
variable $counter := 1;
while ($counter < size($usernames)) {
if ($username eq $user-doc[[$counter]].name) then {
replace json value of $user-entry.email_verified with true;
replace json value of $user-entry.access-attempt with "2016-11-28T16:00:47.203Z";
$changed := true;
} else {
replace json value of $user-entry.failed with true;
}
$counter := $counter + 1;
}
if ($changed eq true) then {
insert json $user-entry into $log;
} else {
exit returning {"failure": true};
}
$log
};
variable $usernames := ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"];
variable $counter := 1;
variable $res := ();
while ($counter < size($usernames)) {
variable $change := local:validate-and-return($usernames[[$counter]]);
if (keys($change)[[1]] eq ["failure"]) then {
exit returning "failure";
} else $res := ($res, $change);
$counter := $counter + 1;
}
$res
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(:JIQS: ShouldRun; Output="({ "name" : "[email protected]", "failed" : false, "email_verified" : true, "access-attempt" : "2016-11-28T16:00:47.203Z" }, { "name" : "[email protected]", "failed" : false, "email_verified" : true, "access-attempt" : "2016-11-28T16:00:47.203Z" }, { "name" : "[email protected]", "failed" : false, "email_verified" : true, "access-attempt" : "2016-11-28T16:00:47.203Z" }, { "name" : "[email protected]", "failed" : false, "email_verified" : true, "access-attempt" : "2016-11-28T16:00:47.203Z" }, { "name" : "[email protected]", "failed" : false, "email_verified" : true, "access-attempt" : "2016-11-28T16:00:47.203Z" })" :)
declare function local:validate-and-return($username as xs:string) {
variable $user-doc := json-doc("../../../queries/user-names.json");
variable $log as object := {};
variable $user-entry := {
"access-attempt": fn:current-time(),
"name": $username,
"email_verified": false,
"failed": false
};
variable $changed := false;
variable $counter := 1;
while ($counter lt (size($user-doc) + 1)) {
if ($username eq $user-doc[[$counter]].name) then {
replace json value of $user-entry.email_verified with true;
replace json value of $user-entry.access-attempt with "2016-11-28T16:00:47.203Z";
$changed := true;
break loop;
} else {
$counter := $counter + 1;
continue loop;
}
}
if ($changed eq true) then {
insert json $user-entry into $log;
} else {
exit returning {"failure": true};
}
$log
};
variable $usernames := ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"];
variable $counter := 1;
variable $res := ();
while ($counter lt (size($usernames) + 1)) {
variable $change := local:validate-and-return($usernames[[$counter]]);
if (keys($change)[[1]] eq ["failure"]) then {
exit returning "failure";
} else $res := ($res, $change);
$counter := $counter + 1;
}
$res

0 comments on commit ec4e7d1

Please sign in to comment.