Changeset: 338b8492863f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=338b8492863f
Modified Files:
        monetdb5/extras/jaql/jaql.h
        monetdb5/extras/jaql/jaqlgencode.c
Branch: default
Log Message:

jaqlgencode: replace [sk]union with bat.insert

We now assume our JSON BATs are writable, or if not, that we made them
writable just-in-time.  This eliminates the need for kunion and sunion
all the time.

As side-effect of this, the sort01 test now fails, because
algebra.select is not guaranteed to return the elements in the order of
the BAT being selected.

Committing this, because the previous code resulted in compiler
complaints (roX set, but not used).


diffs (truncated from 2138 to 300 lines):

diff --git a/monetdb5/extras/jaql/jaql.h b/monetdb5/extras/jaql/jaql.h
--- a/monetdb5/extras/jaql/jaql.h
+++ b/monetdb5/extras/jaql/jaql.h
@@ -53,6 +53,8 @@ typedef struct _jc {
        void *scanner;
        char explain;
        jvar *vars;
+       int j1, j2, j3, j4, j5, j6 ,j7;
+       char ro1:1, ro2:2, ro3:3, ro4:4, ro5:5, ro6:6, ro7:7;
        int vtop;
 } jc;
 
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
@@ -50,11 +50,37 @@ typedef struct _jgvar {
 
 #define MAXJAQLARG 23
 
-static int dumpvariabletransformation(jc *j, Client cntxt, MalBlkPtr mb, tree 
*t, int elems, int *j1, int *j2, int *j3, int *j4, int *j5, int *j6, int *j7);
+static int dumpvariabletransformation(jc *j, Client cntxt, MalBlkPtr mb, tree 
*t, int elems);
 static int dumpnextid(MalBlkPtr mb, int j1);
 static int matchfuncsig(jc *j, Client cntxt, tree *t, int *coltpos, enum 
treetype (*coltypes)[MAXJAQLARG], int (*dynaarg)[MAXJAQLARG][7]);
 static void conditionalcall(int *ret, MalBlkPtr mb, tree *t, enum treetype 
coltypes[MAXJAQLARG], int dynaarg[MAXJAQLARG][7], int coltpos, InstrPtr q);
 
+/* dumps a algebra.copy for the Xth JSON BAT, if necessary, and sets the
+ * ro bit appropriately afterwards */
+static inline void
+dumpbatwritable(jc *j, MalBlkPtr mb, char X)
+{
+       int *jX = NULL;
+       InstrPtr q;
+
+       switch (X) {
+               case 1:  if (!j->ro1) return; jX = &j->j1; j->ro1 = 0;  break;
+               case 2:  if (!j->ro2) return; jX = &j->j2; j->ro2 = 0;  break;
+               case 3:  if (!j->ro3) return; jX = &j->j3; j->ro3 = 0;  break;
+               case 4:  if (!j->ro4) return; jX = &j->j4; j->ro4 = 0;  break;
+               case 5:  if (!j->ro5) return; jX = &j->j5; j->ro5 = 0;  break;
+               case 6:  if (!j->ro6) return; jX = &j->j6; j->ro6 = 0;  break;
+               case 7:  if (!j->ro7) return; jX = &j->j7; j->ro7 = 0;  break;
+       }
+       q = newInstruction(mb, ASSIGNsymbol);
+       setModuleId(q, algebraRef);
+       setFunctionId(q, copyRef);
+       /* put inplace, because we sometimes use this inside barriers */
+       q = pushReturn(mb, q, *jX);
+       q = pushArgument(mb, q, *jX);
+       pushInstruction(mb, q);
+}
+
 /* returns a bat with subset from kind bat (:oid,:bte) which are
  * referenced by the first array of the JSON structure (oid 0@0 of kind
  * bat, pointing to array, so all oids from array bat that have head oid
@@ -244,7 +270,7 @@ 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(jc *j, MalBlkPtr mb, tree *t, int elems)
 {
        InstrPtr q;
        int a = 0, b = 0, c = 0;
@@ -267,7 +293,7 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
        a = elems;
        for (t = t->tval1; t != NULL; t = t->tval1) {
                if (t->type == j_arr_idx) {
-                       c = dumparrrefvar(mb, t, a, *j5);
+                       c = dumparrrefvar(mb, t, a, j->j5);
                        q = newInstruction(mb, ASSIGNsymbol);
                        setModuleId(q, algebraRef);
                        setFunctionId(q, joinRef);
@@ -281,7 +307,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, *j1);
+                       q = pushArgument(mb, q, j->j1);
                        q = pushArgument(mb, q, b);
                        a = getArg(q, 0);
                        pushInstruction(mb, q);
@@ -300,7 +326,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, j->j6);
                        q = pushArgument(mb, q, a);
                        a = getArg(q, 0);
                        pushInstruction(mb, q);
@@ -323,7 +349,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, j->j7);
                        q = pushArgument(mb, q, a);
                        a = getArg(q, 0);
                        pushInstruction(mb, q);
@@ -350,7 +376,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, *j1);
+                       q = pushArgument(mb, q, j->j1);
                        q = pushArgument(mb, q, b);
                        a = getArg(q, 0);
                        pushInstruction(mb, q);
@@ -359,7 +385,7 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
        if (encapsulate) {
                /* we have to return the results as arrays here, since they are
                 * multi-value (x[*].y) */
-               a = dumpnextid(mb, *j1);
+               a = dumpnextid(mb, j->j1);
                q = newInstruction(mb, ASSIGNsymbol);
                setModuleId(q, algebraRef);
                setFunctionId(q, markTRef);
@@ -385,13 +411,14 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
                b = getArg(q, 0);
                pushInstruction(mb, q);
                /* append to array bat */
+               dumpbatwritable(j, mb, 5);
                q = newInstruction(mb, ASSIGNsymbol);
-               setModuleId(q, algebraRef);
-               setFunctionId(q, putName("sunion", 6));
+               setModuleId(q, batRef);
+               setFunctionId(q, insertRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-               q = pushArgument(mb, q, *j5);
+               q = pushArgument(mb, q, j->j5);
                q = pushArgument(mb, q, b);
-               *j5 = getArg(q, 0);
+               j->j5 = getArg(q, 0);
                pushInstruction(mb, q);
 
                q = newInstruction(mb, ASSIGNsymbol);
@@ -410,13 +437,14 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
                c = getArg(q, 0);
                pushInstruction(mb, q);
                /* append to kind bat */
+               dumpbatwritable(j, mb, 1);
                q = newInstruction(mb, ASSIGNsymbol);
-               setModuleId(q, algebraRef);
-               setFunctionId(q, putName("kunion", 6));
+               setModuleId(q, batRef);
+               setFunctionId(q, insertRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-               q = pushArgument(mb, q, *j1);
+               q = pushArgument(mb, q, j->j1);
                q = pushArgument(mb, q, c);
-               *j1 = getArg(q, 0);
+               j->j1 = getArg(q, 0);
                pushInstruction(mb, q);
        }
        return b;
@@ -425,7 +453,7 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
 /* returns bat with in the head the oids from elems that match the
  * comparison */
 static int
-dumpcomp(jc *j, Client cntxt, MalBlkPtr mb, tree *t, int elems, int *j1, int 
*j2, int *j3, int *j4, int *j5, int *j6, int *j7)
+dumpcomp(jc *j, Client cntxt, MalBlkPtr mb, tree *t, int elems)
 {
        InstrPtr q;
        int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0;
@@ -438,10 +466,9 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                        || t->tval3->type == j_str || t->tval3->type == j_bool);
 
        if (t->tval1->type == j_operation) {
-               a = dumpvariabletransformation(j, cntxt, mb, t->tval1, elems,
-                               j1, j2, j3, j4, j5, j6, j7);
+               a = dumpvariabletransformation(j, cntxt, mb, t->tval1, elems);
        } else {
-               a = dumprefvar(mb, t->tval1, elems, j1, j5, j6, j7);
+               a = dumprefvar(j, mb, t->tval1, elems);
        }
 
        if (t->tval3->type != j_var && t->tval3->type != j_operation) {
@@ -456,12 +483,11 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
 
        switch (t->tval3->type) {
                case j_var:
-                       b = dumprefvar(mb, t->tval3, elems, j1, j5, j6, j7);
+                       b = dumprefvar(j, mb, t->tval3, elems);
                        c = -1;
                        break;
                case j_operation:
-                       b = dumpvariabletransformation(j, cntxt, mb, t->tval3, 
elems,
-                                       j1, j2, j3, j4, j5, j6, j7);
+                       b = dumpvariabletransformation(j, cntxt, mb, t->tval3, 
elems);
                        c = -1;
                        break;
                case j_num:
@@ -470,7 +496,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                        setFunctionId(q, joinRef);
                        q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
                        q = pushArgument(mb, q, a);
-                       q = pushArgument(mb, q, *j3);
+                       q = pushArgument(mb, q, j->j3);
                        b = getArg(q, 0);
                        pushInstruction(mb, q);
                        q = newInstruction(mb, ASSIGNsymbol);
@@ -485,7 +511,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                        setFunctionId(q, joinRef);
                        q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
                        q = pushArgument(mb, q, a);
-                       q = pushArgument(mb, q, *j4);
+                       q = pushArgument(mb, q, j->j4);
                        b = getArg(q, 0);
                        pushInstruction(mb, q);
                        q = newInstruction(mb, ASSIGNsymbol);
@@ -500,7 +526,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                        setFunctionId(q, joinRef);
                        q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
                        q = pushArgument(mb, q, a);
-                       q = pushArgument(mb, q, *j2);
+                       q = pushArgument(mb, q, j->j2);
                        b = getArg(q, 0);
                        pushInstruction(mb, q);
                        q = newInstruction(mb, ASSIGNsymbol);
@@ -515,7 +541,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                        setFunctionId(q, joinRef);
                        q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
                        q = pushArgument(mb, q, a);
-                       q = pushArgument(mb, q, *j1);
+                       q = pushArgument(mb, q, j->j1);
                        b = getArg(q, 0);
                        pushInstruction(mb, q);
                        q = newInstruction(mb, ASSIGNsymbol);
@@ -613,7 +639,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                                assert(0);
                }
        } else {  /* var <cmp> var */
-               int lv[4] = {*j2, *j3, *j4, 0}, *lp = lv;
+               int lv[4] = {j->j2, j->j3, j->j4, 0}, *lp = lv;
                /* FIXME: we need to check that a and b have at most one value
                 * per elem here, further code assumes that, because its
                 * semantically unclear what one should do with multiple values
@@ -647,7 +673,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                setModuleId(q, algebraRef);
                setFunctionId(q, semijoinRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-               q = pushArgument(mb, q, *j1);
+               q = pushArgument(mb, q, j->j1);
                q = pushArgument(mb, q, c);
                c = getArg(q, 0);
                pushInstruction(mb, q);
@@ -671,7 +697,7 @@ dumpcomp(jc *j, Client cntxt, MalBlkPtr 
                setModuleId(q, algebraRef);
                setFunctionId(q, semijoinRef);
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-               q = pushArgument(mb, q, *j1);
+               q = pushArgument(mb, q, j->j1);
                q = pushArgument(mb, q, d);
                d = getArg(q, 0);
                pushInstruction(mb, q);
@@ -1023,11 +1049,12 @@ calculatejoingraph(join_result *jrs)
 }
 
 static void
-dumppredjoin(MalBlkPtr mb, json_var *js, tree *t, int *j1, int *j2, int *j3, 
int *j4, int *j5, int *j6, int *j7)
+dumppredjoin(jc *j, MalBlkPtr mb, json_var *js, tree *t)
 {
        InstrPtr q;
        int a = 0, b = 0, c = 0, d = 0, l = 0, r = 0;
        tree *pred;
+       jc tj;
        json_var *vars, *ljv, *rjv;
        join_result *jrs = NULL, *jrw = NULL, *jrl, *jrr = NULL, *jrn, *jrv, 
*jrp;
 
@@ -1050,7 +1077,11 @@ 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);
+               tj.j1 = ljv->j1;
+               tj.j5 = ljv->j5;
+               tj.j6 = ljv->j6;
+               tj.j7 = ljv->j7;
+               l = dumprefvar(&tj, mb, pred->tval1, a);
 
                q = newInstruction(mb, ASSIGNsymbol);
                setModuleId(q, batRef);
@@ -1062,7 +1093,11 @@ 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);
+               tj.j1 = rjv->j1;
+               tj.j5 = rjv->j5;
+               tj.j6 = rjv->j6;
+               tj.j7 = rjv->j7;
+               r = dumprefvar(&tj, mb, pred->tval3, a);
 
                /* strings */
                q = newInstruction(mb, ASSIGNsymbol);
@@ -1891,7 +1926,7 @@ dumppredjoin(MalBlkPtr mb, json_var *js,
                q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
                q = pushArgument(mb, q, js->j1);
                q = pushArgument(mb, q, vars->j1);
-               *j1 = js->j1 = getArg(q, 0);
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to