Changeset: aaf911f0146c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=aaf911f0146c
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: implemented creation of arrays

When creating an array, values need not to be copied.  Special care has
been taken for the case when the same value is referenced more than
once, because this generates identical tuples that sunion (or any GDK
union operation) would eat away.


diffs (145 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
@@ -6,3 +6,4 @@ jaql.x("[{\"a\": 1, \"b\": 3.4}, {\"a\":
 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;");
+jaql.x("[1,2,3] -> transform [$, $];");
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
@@ -25,6 +25,7 @@ function user.main():void;
     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;");
+    jaql.x("[1,2,3] -> transform [$, $];");
 end main;
 [ 4, 4, 4 ]
 [ 1, 2.600000 ]
@@ -34,6 +35,7 @@ end main;
 [ 4, 8, 12 ]
 [ 4.000000, 8.000000, 12.000000 ]
 [ 0.500000, 1.000000, 1.500000 ]
+[ [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] ]
 
 # 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
@@ -556,9 +556,6 @@ dumpvariabletransformation(MalBlkPtr mb,
        InstrPtr q;
        int a, b, c, d, e, f, g;
 
-       (void) f;
-       (void) g;
-
        assert (t != NULL);
 
        switch (t->type) {
@@ -1237,12 +1234,102 @@ dumpvariabletransformation(MalBlkPtr mb,
                        return a;
                }
                case j_json_obj:
+                       g = 1;
                case j_json_arr:
-                       break;
+                       g++;
+                       a = -1;
+                       c = -1;
+                       t = t->tval1;
+                       while (t != NULL) {
+                               b = dumpvariabletransformation(mb, t, elems,
+                                               j1, j2, j3, j4, j5, j6, j7);
+                               if (a == -1)
+                                       a = dumpnextid(mb, *j1);
+                               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);
+                               q = newInstruction(mb, ASSIGNsymbol);
+                               setModuleId(q, algebraRef);
+                               setFunctionId(q, markHRef);
+                               q = pushReturn(mb, q, newTmpVariable(mb, 
TYPE_any));
+                               q = pushArgument(mb, q, b);
+                               q = pushArgument(mb, q, a);
+                               b = getArg(q, 0);
+                               pushInstruction(mb, q);
+                               if (c == -1) {
+                                       c = b;
+                               } else {
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, batRef);
+                                       setFunctionId(q, insertRef);
+                                       /* can't use sunion, this may have 
duplicates [$,$] */
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, c);
+                                       q = pushArgument(mb, q, b);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                               }
+                               t = t->next;
+                       }
+                       if (a == -1)
+                               a = dumpnextid(mb, *j1);
+
+                       if (c != -1) {
+                               /* can have duplicates, see above */
+                               q = newInstruction(mb, ASSIGNsymbol);
+                               setModuleId(q, algebraRef);
+                               setFunctionId(q, copyRef);
+                               q = pushReturn(mb, q, newTmpVariable(mb, 
TYPE_any));
+                               q = pushArgument(mb, q, g == 2 ? *j6 : *j5);
+                               d = getArg(q, 0);
+                               pushInstruction(mb, q);
+                               q = newInstruction(mb, ASSIGNsymbol);
+                               setModuleId(q, batRef);
+                               setFunctionId(q, insertRef);
+                               q = pushReturn(mb, q, newTmpVariable(mb, 
TYPE_any));
+                               q = pushArgument(mb, q, d);
+                               q = pushArgument(mb, q, c);
+                               if (g == 2) {
+                                       *j6 = getArg(q, 0);
+                               } else {
+                                       *j5 = 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, elems);
+                       q = pushArgument(mb, q, a);
+                       d = 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, d);
+                       q = pushChr(mb, q, g == 2 ? 'o' : 'a');
+                       a = 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, a);
+                       *j1 = getArg(q, 0);
+                       pushInstruction(mb, q);
+
+                       return a;
                default:
                        assert(0);
        }
-       return elems;
 }
 
 int
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to