Changeset: 52ac69f4cbca for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=52ac69f4cbca
Modified Files:
        monetdb5/extras/jaql/Tests/variable00.mal
        monetdb5/extras/jaql/Tests/variable00.stable.out
        monetdb5/extras/jaql/jaql.c
        monetdb5/extras/jaql/jaqlgencode.c
Branch: jacqueline
Log Message:

jaql: make any [*] involving variable return an array

It seems the jaqltool (and the docs) vaguely suggest that any variable
reference with array [*] results in an array.  It seems to work with the
idea that [*] means "match (everything from) an array", but since you
cannot return multiple values, "return as an array".


diffs (truncated from 331 to 300 lines):

diff --git a/monetdb5/extras/jaql/Tests/variable00.mal 
b/monetdb5/extras/jaql/Tests/variable00.mal
--- a/monetdb5/extras/jaql/Tests/variable00.mal
+++ b/monetdb5/extras/jaql/Tests/variable00.mal
@@ -4,6 +4,7 @@ jaql.x("A -> filter $ <= 2;");
 jaql.x("A -> filter each v v.a >= 5;");
 jaql.x("n = [ [3,65,8,72], [5,98,2,65] ];");
 jaql.x("n -> expand -> transform each n (n * 2);");
+jaql.x("n -> transform each n (n);");
 jaql.x("n -> transform each n (n[2]);");
 jaql.x("n -> transform each n (n[8]);");
 jaql.x("n -> transform each n (n[*]);");
diff --git a/monetdb5/extras/jaql/Tests/variable00.stable.out 
b/monetdb5/extras/jaql/Tests/variable00.stable.out
--- a/monetdb5/extras/jaql/Tests/variable00.stable.out
+++ b/monetdb5/extras/jaql/Tests/variable00.stable.out
@@ -23,6 +23,7 @@ function user.main():void;
     jaql.x("A -> filter each v v.a >= 5;");
     jaql.x("n = [ [3,65,8,72], [5,98,2,65] ];");
     jaql.x("n -> expand -> transform each n (n * 2);");
+    jaql.x("n -> transform each n (n);");
     jaql.x("n -> transform each n (n[2]);");
     jaql.x("n -> transform each n (n[8]);");
     jaql.x("n -> transform each n (n[*]);");
@@ -36,12 +37,13 @@ end main;
 [ 1, 2 ]
 [ { "a": 5 } ]
 [ 6, 130, 16, 144, 10, 196, 4, 130 ]
+[ [ 3, 65, 8, 72 ], [ 5, 98, 2, 65 ] ]
 [ 8, 2 ]
 [ null, null ]
-[ 3, 65, 8, 72, 5, 98, 2, 65 ]
+[ [ 3, 65, 8, 72 ], [ 5, 98, 2, 65 ] ]
 [ 65, { "b": 98 } ]
-[ 3, 65, { "b": 8 }, 72, 5, { "b": 98 }, 2, 65 ]
-[ 8, 98 ]
+[ [ 3, 65, { "b": 8 }, 72 ], [ 5, { "b": 98 }, 2, 65 ] ]
+[ [ 8 ], [ 98 ] ]
 [ 8, null ]
 
 # 21:12:04 >  
diff --git a/monetdb5/extras/jaql/jaql.c b/monetdb5/extras/jaql/jaql.c
--- a/monetdb5/extras/jaql/jaql.c
+++ b/monetdb5/extras/jaql/jaql.c
@@ -219,7 +219,7 @@ make_jaql_transform(tree *var, tree *tmp
        }
 
        if (tmpl->type == j_var && tmpl->tval1 == NULL && tmpl->tval2 == NULL) {
-               /* simple variable, hence not performing any change, so null-op 
*/
+               /* simple variable, hence not performing any change so null-op 
*/
                freetree(var);
                freetree(tmpl);
                return NULL;
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
@@ -112,17 +112,26 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
        q = pushBte(mb, q, 'a');  /* deref requires array */
        a = getArg(q, 0);
        pushInstruction(mb, q);
-       q = newInstruction(mb, ASSIGNsymbol);
-       setModuleId(q, algebraRef);
-       setFunctionId(q, semijoinRef);
-       q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-       q = pushArgument(mb, q, j5);
-       q = pushArgument(mb, q, a);
-       a = getArg(q, 0);
-       pushInstruction(mb, q);
 
-       if (t->nval == -1) {
-               /* all array members (like expand) */
+       if (t->tval2->nval == -1 && t->tval1 == NULL) {
+               /* all array members (return as a single array) */
+               q = newInstruction(mb, ASSIGNsymbol);
+               setModuleId(q, batRef);
+               setFunctionId(q, mirrorRef);
+               q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+               q = pushArgument(mb, q, a);
+               b = getArg(q, 0);
+               pushInstruction(mb, q);
+       } else if (t->tval2->nval == -1 && t->tval1 != NULL) {
+               /* all array members of which objects will be dereferenced */
+               q = newInstruction(mb, ASSIGNsymbol);
+               setModuleId(q, algebraRef);
+               setFunctionId(q, semijoinRef);
+               q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+               q = pushArgument(mb, q, j5);
+               q = pushArgument(mb, q, a);
+               a = getArg(q, 0);
+               pushInstruction(mb, q);
                q = newInstruction(mb, ASSIGNsymbol);
                setModuleId(q, batRef);
                setFunctionId(q, reverseRef);
@@ -133,6 +142,14 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
        } else {
                /* xth array member */
                q = newInstruction(mb, ASSIGNsymbol);
+               setModuleId(q, algebraRef);
+               setFunctionId(q, semijoinRef);
+               q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+               q = pushArgument(mb, q, j5);
+               q = pushArgument(mb, q, a);
+               a = getArg(q, 0);
+               pushInstruction(mb, q);
+               q = newInstruction(mb, ASSIGNsymbol);
                setModuleId(q, batRef);
                setFunctionId(q, reverseRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
@@ -179,8 +196,8 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
                setFunctionId(q, selectRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
                q = pushArgument(mb, q, b);
-               q = pushOid(mb, q, (oid)t->nval);
-               q = pushOid(mb, q, (oid)t->nval);
+               q = pushOid(mb, q, (oid)t->tval2->nval);
+               q = pushOid(mb, q, (oid)t->tval2->nval);
                b = getArg(q, 0);
                pushInstruction(mb, q);
                q = newInstruction(mb, ASSIGNsymbol);
@@ -223,16 +240,17 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
  * in the tail, the oid of the corresponding element from elems
  * (typically array bat, head oid 0@0) */
 static int
-dumprefvar(MalBlkPtr mb, tree *t, int elems, int j1, int j5, int j6, int j7)
+dumprefvar(MalBlkPtr mb, tree *t, int elems, int *j1, int *j5, int *j6, int 
*j7)
 {
        InstrPtr q;
        int a, b, c;
+       char encapsulate = 0;
 
        assert(t && t->type == j_var);
 
        if (t->tval1 == NULL) {
                if (t->tval2 != NULL) {
-                       b = dumparrrefvar(mb, t->tval2, elems, j5);
+                       b = dumparrrefvar(mb, t, elems, *j5);
                } else {
                        /* just var, has no derefs or anything, so all */
                        q = newInstruction(mb, ASSIGNsymbol);
@@ -268,7 +286,7 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
                setModuleId(q, algebraRef);
                setFunctionId(q, semijoinRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-               q = pushArgument(mb, q, j6);
+               q = pushArgument(mb, q, *j6);
                q = pushArgument(mb, q, a);
                a = getArg(q, 0);
                pushInstruction(mb, q);
@@ -291,7 +309,7 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
                setModuleId(q, algebraRef);
                setFunctionId(q, semijoinRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-               q = pushArgument(mb, q, j7);
+               q = pushArgument(mb, q, *j7);
                q = pushArgument(mb, q, a);
                a = getArg(q, 0);
                pushInstruction(mb, q);
@@ -317,13 +335,13 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
                        setModuleId(q, algebraRef);
                        setFunctionId(q, semijoinRef);
                        q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-                       q = pushArgument(mb, q, j1);
+                       q = pushArgument(mb, q, *j1);
                        q = pushArgument(mb, q, b);
                        a = getArg(q, 0);
                        pushInstruction(mb, q);
                }
                if (t->tval2 != NULL) {
-                       c = dumparrrefvar(mb, t->tval2, a, j5);
+                       c = dumparrrefvar(mb, t, a, *j5);
                        q = newInstruction(mb, ASSIGNsymbol);
                        setModuleId(q, algebraRef);
                        setFunctionId(q, joinRef);
@@ -337,12 +355,77 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
                        setModuleId(q, algebraRef);
                        setFunctionId(q, semijoinRef);
                        q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-                       q = pushArgument(mb, q, j1);
+                       q = pushArgument(mb, q, *j1);
                        q = pushArgument(mb, q, b);
                        a = getArg(q, 0);
                        pushInstruction(mb, q);
+                       if (t->tval1 != NULL && t->tval2->nval == -1)
+                               encapsulate = 1;
                }
        }
+       if (encapsulate) {
+               /* we have to return the results as arrays here, since they are
+                * multi-value (x[*].y) */
+               a = dumpnextid(mb, *j1);
+               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);
+               c = getArg(q, 0);
+               pushInstruction(mb, q);
+
+               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, c);
+               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);
+               /* append to array bat */
+               q = newInstruction(mb, ASSIGNsymbol);
+               setModuleId(q, algebraRef);
+               setFunctionId(q, putName("sunion", 6));
+               q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+               q = pushArgument(mb, q, *j5);
+               q = pushArgument(mb, q, b);
+               *j5 = 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, c);
+               b = 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, b);
+               q = pushBte(mb, q, 'a');
+               c = getArg(q, 0);
+               pushInstruction(mb, q);
+               /* append to kind bat */
+               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);
+               *j1 = getArg(q, 0);
+               pushInstruction(mb, q);
+       }
        return b;
 }
 
@@ -365,7 +448,7 @@ dumpcomp(MalBlkPtr mb, tree *t, int elem
                a = dumpvariabletransformation(mb, t->tval1, elems,
                                j1, j2, j3, j4, j5, j6, j7);
        } else {
-               a = dumprefvar(mb, t->tval1, elems, *j1, *j5, *j6, *j7);
+               a = dumprefvar(mb, t->tval1, elems, j1, j5, j6, j7);
        }
 
        if (t->tval3->type != j_var && t->tval3->type != j_operation) {
@@ -380,7 +463,7 @@ dumpcomp(MalBlkPtr mb, tree *t, int elem
 
        switch (t->tval3->type) {
                case j_var:
-                       b = dumprefvar(mb, t->tval3, elems, *j1, *j5, *j6, *j7);
+                       b = dumprefvar(mb, t->tval3, elems, j1, j5, j6, j7);
                        c = -1;
                        break;
                case j_operation:
@@ -974,7 +1057,7 @@ dumppredjoin(MalBlkPtr mb, json_var *js,
                }
                locate_var(ljv, pred->tval1->sval);
                a = dumpwalkvar(mb, ljv->j1, ljv->j5);
-               l = dumprefvar(mb, pred->tval1, a, ljv->j1, ljv->j5, ljv->j6, 
ljv->j7);
+               l = dumprefvar(mb, pred->tval1, a, &ljv->j1, &ljv->j5, 
&ljv->j6, &ljv->j7);
 
                q = newInstruction(mb, ASSIGNsymbol);
                setModuleId(q, batRef);
@@ -986,7 +1069,7 @@ dumppredjoin(MalBlkPtr mb, json_var *js,
 
                locate_var(rjv, pred->tval3->sval);
                a = dumpwalkvar(mb, rjv->j1, rjv->j5);
-               r = dumprefvar(mb, pred->tval3, a, rjv->j1, rjv->j5,  rjv->j6, 
rjv->j7);
+               r = dumprefvar(mb, pred->tval3, a, &rjv->j1, &rjv->j5, 
&rjv->j6, &rjv->j7);
 
                /* strings */
                q = newInstruction(mb, ASSIGNsymbol);
@@ -2060,7 +2143,7 @@ dumpvariabletransformation(MalBlkPtr mb,
 
                        return b;
                case j_var:
-                       b = dumprefvar(mb, t, elems, *j1, *j5, *j6, *j7);
+                       b = dumprefvar(mb, t, elems, j1, j5, j6, j7);
 
                        /* add back missing vars as null */
                        a = dumpnextid(mb, *j1);
@@ -2831,7 +2914,7 @@ dumpvariabletransformation(MalBlkPtr mb,
                                 * instead it shows empty pairs instead of 
null, but it
                                 * however does for arrays, so we filter them 
out here if
                                 * they weren't a real null (jaql tool crashes 
on that) */
-                               a = dumprefvar(mb, t->tval1, elems, *j1, *j5, 
*j6, *j7);
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to