Changeset: 94fce7127ada for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=94fce7127ada
Modified Files:
monetdb5/extras/jaql/Tests/transform00.mal
monetdb5/extras/jaql/Tests/transform00.stable.out
monetdb5/extras/jaql/jaqlgencode.c
Branch: jacqueline
Log Message:
transform: respect original positions of elements
make sure we keep the original position of elements being transformed
special care for records with absent attributes, jaql seems to hide/omit
them in transformations, where it doesn't in arrays
diffs (truncated from 681 to 300 lines):
diff --git a/monetdb5/extras/jaql/Tests/transform00.mal
b/monetdb5/extras/jaql/Tests/transform00.mal
--- a/monetdb5/extras/jaql/Tests/transform00.mal
+++ b/monetdb5/extras/jaql/Tests/transform00.mal
@@ -4,6 +4,7 @@ jaql.x("[{\"a\": 1}, {\"a\": 2.6}] -> tr
jaql.x("[1,2.2,3] -> transform 2 * $;");
jaql.x("[{\"a\": 1}, {\"a\": 2.5}] -> transform $.a + $.a;");
jaql.x("[{\"a\": 1, \"b\": 3.4}, {\"a\": 2.5, \"b\": 4}] -> transform $.a +
$.b;");
+jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {\"a\":$.a+1};");
jaql.x("[1,2,3] -> transform 2 * ($ * 2);");
jaql.x("[1,2,3] -> transform 2 * 2.0 * $;");
jaql.x("[1,2,3] -> transform ($ * 2.0) / 4;");
@@ -17,3 +18,7 @@ jaql.x("[{\"a\":1},{\"b\":2}] -> transfo
jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {$.a};");
jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {$.b};");
jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {$.a,$.b};");
+jaql.x("[{\"a\":1,\"b\":3},{\"b\":2},{\"a\":4,\"b\":5}] -> transform
{$.a,$.b};");
+
+jaql.x("[{\"b\":3},{\"a\":3.5,\"b\":2}] -> transform {$.a};");
+jaql.x("[{\"b\":3},{\"a\":3.5,\"b\":2}] -> transform [$.a];");
diff --git a/monetdb5/extras/jaql/Tests/transform00.stable.out
b/monetdb5/extras/jaql/Tests/transform00.stable.out
--- a/monetdb5/extras/jaql/Tests/transform00.stable.out
+++ b/monetdb5/extras/jaql/Tests/transform00.stable.out
@@ -23,6 +23,7 @@ function user.main():void;
jaql.x("[1,2.2,3] -> transform 2 * $;");
jaql.x("[{\"a\": 1}, {\"a\": 2.5}] -> transform $.a + $.a;");
jaql.x("[{\"a\": 1, \"b\": 3.4}, {\"a\": 2.5, \"b\": 4}] -> transform $.a
+ $.b;");
+ jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {\"a\":$.a+1};");
jaql.x("[1,2,3] -> transform 2 * ($ * 2);");
jaql.x("[1,2,3] -> transform 2 * 2.0 * $;");
jaql.x("[1,2,3] -> transform ($ * 2.0) / 4;");
@@ -35,6 +36,9 @@ function user.main():void;
jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {$.a};");
jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {$.b};");
jaql.x("[{\"a\":1,\"b\":3},{\"b\":2}] -> transform {$.a,$.b};");
+ jaql.x("[{\"a\":1,\"b\":3},{\"b\":2},{\"a\":4,\"b\":5}] -> transform
{$.a,$.b};");
+ jaql.x("[{\"b\":3},{\"a\":3.5,\"b\":2}] -> transform {$.a};");
+ jaql.x("[{\"b\":3},{\"a\":3.5,\"b\":2}] -> transform [$.a];");
end main;
[ 4, 4, 4 ]
[ { "value": 4 }, { "value": 4 }, { "value": 4 } ]
@@ -42,6 +46,7 @@ end main;
[ 2, 4.400000, 6 ]
[ 2, 5.000000 ]
[ 4.400000, 6.500000 ]
+[ { "a": 2 }, { "a": null } ]
[ 4, 8, 12 ]
[ 4.000000, 8.000000, 12.000000 ]
[ 0.500000, 1.000000, 1.500000 ]
@@ -49,11 +54,14 @@ end main;
[ { "value": 1 }, { "value": 2 }, { "value": 3 } ]
[ { "value": 2 }, { "value": 4 }, { "value": 6 } ]
[ { "a": 1 }, { } ]
-[ { "b": 2 }, { } ]
+[ { }, { "b": 2 } ]
[ { }, { } ]
[ { "a": 1 }, { } ]
[ { "b": 3 }, { "b": 2 } ]
[ { "a": 1, "b": 3 }, { "b": 2 } ]
+[ { "a": 1, "b": 3 }, { "b": 2 }, { "a": 4, "b": 5 } ]
+[ { }, { "a": 3.500000 } ]
+[ [ null ], [ 3.500000 ] ]
# 21:27:13 >
# 21:27:13 > "Done."
diff --git a/monetdb5/extras/jaql/jaqlgencode.c
b/monetdb5/extras/jaql/jaqlgencode.c
--- a/monetdb5/extras/jaql/jaqlgencode.c
+++ b/monetdb5/extras/jaql/jaqlgencode.c
@@ -176,42 +176,8 @@ dumpcomp(MalBlkPtr mb, tree *t, int elem
|| t->tval3->type == j_str || t->tval3->type == j_bool);
if (t->tval1->type == j_operation) {
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, batRef);
- setFunctionId(q, reverseRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, elems);
- a = getArg(q, 0);
- pushInstruction(mb, q);
- b = dumpvariabletransformation(mb, t->tval1, a,
+ a = dumpvariabletransformation(mb, t->tval1, elems,
j1, j2, j3, j4, j5, j6, j7);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, markHRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, a);
- q = pushOid(mb, q, 0);
- a = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, markTRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, b);
- q = pushOid(mb, q, 0);
- b = getArg(q, 0);
- pushInstruction(mb, q);
- /* because transformations must leave the original count in
- * tact, all elems from b originate straight from a, be it that
- * they may be null now */
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, joinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, b);
- q = pushArgument(mb, q, a);
- a = getArg(q, 0);
- pushInstruction(mb, q);
} else {
a = dumprefvar(mb, t->tval1, elems, *j1, *j6, *j7);
}
@@ -232,42 +198,8 @@ dumpcomp(MalBlkPtr mb, tree *t, int elem
c = -1;
break;
case j_operation:
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, batRef);
- setFunctionId(q, reverseRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, elems);
- b = getArg(q, 0);
- pushInstruction(mb, q);
- c = dumpvariabletransformation(mb, t->tval1, b,
+ b = dumpvariabletransformation(mb, t->tval3, elems,
j1, j2, j3, j4, j5, j6, j7);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, markHRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, b);
- q = pushOid(mb, q, 0);
- b = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, markTRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, c);
- q = pushOid(mb, q, 0);
- c = getArg(q, 0);
- pushInstruction(mb, q);
- /* because transformations must leave the original
count in
- * tact, all elems from c originate straight from b, be
it that
- * they may be null now */
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, joinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, c);
- q = pushArgument(mb, q, b);
- b = getArg(q, 0);
- pushInstruction(mb, q);
c = -1;
break;
case j_num:
@@ -834,8 +766,9 @@ dumpnextid(MalBlkPtr mb, int j1)
return a;
}
-/* returns a BAT which is the subset of j1 that refers to the values
+/* returns a BAT which contains the ids of j1 that refer to the values
* returned from the variable and its optional calculation applied to it
+ * the tail is the element id from the head of elems
* the j{1..7} variables are updated to point to the updated BATs as
* insertions of new values (the serialised versions of the variable) */
static int
@@ -851,14 +784,23 @@ dumpvariabletransformation(MalBlkPtr mb,
case j_str:
case j_num:
case j_dbl:
- /* shortcut, simple action */
+ /* fill up elems size of this constant */
a = dumpnextid(mb, *j1);
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, algebraRef);
+ setFunctionId(q, markHRef);
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, elems);
+ q = pushArgument(mb, q, a);
+ c = getArg(q, 0);
+ pushInstruction(mb, q);
+
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, algebraRef);
setFunctionId(q, projectRef);
q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, elems);
+ q = pushArgument(mb, q, c);
if (t->type == j_num) {
q = pushLng(mb, q, t->nval);
} else if (t->type == j_dbl) {
@@ -872,7 +814,7 @@ dumpvariabletransformation(MalBlkPtr mb,
setModuleId(q, algebraRef);
setFunctionId(q, projectRef);
q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, elems);
+ q = pushArgument(mb, q, c);
if (t->type == j_num) {
q = pushChr(mb, q, 'i');
d = *j3;
@@ -883,15 +825,7 @@ dumpvariabletransformation(MalBlkPtr mb,
q = pushChr(mb, q, 's');
d = *j2;
}
- c = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, putName("markH", 5));
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, b);
- q = pushArgument(mb, q, a);
- b = getArg(q, 0);
+ e = getArg(q, 0);
pushInstruction(mb, q);
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, algebraRef);
@@ -909,50 +843,134 @@ dumpvariabletransformation(MalBlkPtr mb,
pushInstruction(mb, q);
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, algebraRef);
- setFunctionId(q, putName("markH", 5));
+ setFunctionId(q, putName("kunion", 6));
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, *j1);
+ q = pushArgument(mb, q, e);
+ *j1 = getArg(q, 0);
+ pushInstruction(mb, q);
+
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, algebraRef);
+ setFunctionId(q, markTRef);
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, elems);
+ q = pushArgument(mb, q, a);
+ b = getArg(q, 0);
+ pushInstruction(mb, q);
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, batRef);
+ setFunctionId(q, reverseRef);
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, b);
+ b = getArg(q, 0);
+ pushInstruction(mb, q);
+
+ return b;
+ case j_var:
+ b = dumprefvar(mb, t, elems, *j1, *j6, *j7);
+
+ /* add back missing vars as null */
+ a = dumpnextid(mb, *j1);
+
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, batRef);
+ setFunctionId(q, mirrorRef);
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, elems);
+ e = getArg(q, 0);
+ pushInstruction(mb, q);
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, batRef);
+ setFunctionId(q, reverseRef);
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, b);
+ d = getArg(q, 0);
+ pushInstruction(mb, q);
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, algebraRef);
+ setFunctionId(q, putName("kdifference", 11));
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, e);
+ q = pushArgument(mb, q, d);
+ c = getArg(q, 0);
+ pushInstruction(mb, q);
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, algebraRef);
+ setFunctionId(q, projectRef);
+ q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+ q = pushArgument(mb, q, c);
+ q = pushChr(mb, q, 'n');
+ c = getArg(q, 0);
+ pushInstruction(mb, q);
+ q = newInstruction(mb, ASSIGNsymbol);
+ setModuleId(q, algebraRef);
+ setFunctionId(q, markHRef);
q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
q = pushArgument(mb, q, c);
q = pushArgument(mb, q, a);
- c = getArg(q, 0);
+ d = getArg(q, 0);
pushInstruction(mb, q);
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, algebraRef);
setFunctionId(q, putName("kunion", 6));
q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
q = pushArgument(mb, q, *j1);
- q = pushArgument(mb, q, c);
+ q = pushArgument(mb, q, d);
*j1 = getArg(q, 0);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list