Changeset: 05d75f608597 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=05d75f608597
Modified Files:
        monetdb5/extras/jaql/jaqlgencode.c
        monetdb5/extras/jaql/jaqltests/Tests/in.jaql
        monetdb5/extras/jaql/jaqltests/Tests/in.stable.out
Branch: Jul2012
Log Message:

in: implemented x IN <var>

We can now perform more-or-less "contains", on an array from the JSON
input, by e.g. writing "3 in $".


diffs (224 lines):

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
@@ -499,21 +499,22 @@ dumpin(jc *j, Client cntxt, MalBlkPtr mb
                                (t->tval1->type == j_var || t->tval1->type == 
j_operation))
                        || (t->tval3->type == j_var &&
                                (t->tval1->type == j_var || t->tval1->type == 
j_operation
-                                || t->tval3->type == j_num || t->tval3->type 
== j_dbl
-                                || t->tval3->type == j_str || t->tval3->type 
== j_bool))
+                                || t->tval1->type == j_num || t->tval1->type 
== j_dbl
+                                || t->tval1->type == j_str || t->tval1->type 
== j_bool
+                                || t->tval1->type == j_null))
                  );
 
-       if (t->tval1->type == j_operation) {
-               a = dumpvariabletransformation(j, cntxt, mb, t->tval1, elems);
-       } else if (t->tval1->type == j_var) {
-               a = dumprefvar(j, mb, t->tval1, elems);
-       } else /* literal */ {
-               /* FIXME: hmm? */
-               a = -1;
-       }
-
        switch (t->tval3->type) {
                case j_json_arr:
+                       if (t->tval1->type == j_operation) {
+                               a = dumpvariabletransformation(j, cntxt, mb, 
t->tval1, elems);
+                       } else if (t->tval1->type == j_var) {
+                               a = dumprefvar(j, mb, t->tval1, elems);
+                       } else /* literal */ {
+                               a = -1;
+                               assert(0);
+                       }
+
                        /* we will create 4 BATs, one for kind matches (t, f, 
n),
                         * and one for num, dbl and str each */
                        q = newInstruction(mb, ASSIGNsymbol);
@@ -773,6 +774,161 @@ dumpin(jc *j, Client cntxt, MalBlkPtr mb
                        pushInstruction(mb, q);
 
                        break;
+               case j_var:
+                       a = dumprefvar(j, mb, t->tval3, elems);
+
+                       /* take all arrays from a */
+                       q = newInstruction(mb, ASSIGNsymbol);
+                       setModuleId(q, algebraRef);
+                       setFunctionId(q, semijoinRef);
+                       q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+                       q = pushArgument(mb, q, j->j1);
+                       q = pushArgument(mb, q, a);
+                       b = getArg(q, 0);
+                       pushInstruction(mb, q);
+                       q = newInstruction(mb, ASSIGNsymbol);
+                       setModuleId(q, algebraRef);
+                       setFunctionId(q, uselectRef);
+                       q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+                       q = pushArgument(mb, q, b);
+                       q = pushBte(mb, q, 'a');
+                       b = getArg(q, 0);
+                       pushInstruction(mb, q);
+                       /* get contents of arrays */
+                       q = newInstruction(mb, ASSIGNsymbol);
+                       setModuleId(q, algebraRef);
+                       setFunctionId(q, semijoinRef);
+                       q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+                       q = pushArgument(mb, q, j->j5);
+                       q = pushArgument(mb, q, b);
+                       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);
+                       /* keep original element mapping */
+                       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);
+                       b = getArg(q, 0);
+                       pushInstruction(mb, q);
+                       
+                       switch (t->tval1->type) {
+                               case j_str:
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, semijoinRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, j->j2);
+                                       q = pushArgument(mb, q, b);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, uselectRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, c);
+                                       q = pushStr(mb, q, t->tval1->sval);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       break;
+                               case j_num:
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, semijoinRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, j->j3);
+                                       q = pushArgument(mb, q, b);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, uselectRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, c);
+                                       q = pushLng(mb, q, t->tval1->nval);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       break;
+                               case j_dbl:
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, semijoinRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, j->j3);
+                                       q = pushArgument(mb, q, b);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, uselectRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, c);
+                                       q = pushDbl(mb, q, t->tval1->dval);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       break;
+                               case j_bool:
+                               case j_null:
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, semijoinRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, j->j1);
+                                       q = pushArgument(mb, q, b);
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       q = newInstruction(mb, ASSIGNsymbol);
+                                       setModuleId(q, algebraRef);
+                                       setFunctionId(q, uselectRef);
+                                       q = pushReturn(mb, q, 
newTmpVariable(mb, TYPE_any));
+                                       q = pushArgument(mb, q, c);
+                                       q = pushBte(mb, q, t->tval1->type == 
j_null ? 'n' :
+                                                       t->tval1->nval ? 't' : 
'f');
+                                       c = getArg(q, 0);
+                                       pushInstruction(mb, q);
+                                       break;
+                               default:
+                                       assert(0);
+                       }
+
+                       /* map matches back on original elements */
+                       q = newInstruction(mb, ASSIGNsymbol);
+                       setModuleId(q, algebraRef);
+                       setFunctionId(q, semijoinRef);
+                       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);
+
+                       /* eliminate any duplicates due to multiple entries in 
the
+                        * arrays for elements matching, and get elem ids on the
+                        * left */
+                       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, kuniqueRef);
+                       q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
+                       q = pushArgument(mb, q, b);
+                       b = getArg(q, 0);
+                       pushInstruction(mb, q);
+
+                       g = b;
+                       break;
                default:
                        assert(0);
        }
diff --git a/monetdb5/extras/jaql/jaqltests/Tests/in.jaql 
b/monetdb5/extras/jaql/jaqltests/Tests/in.jaql
--- a/monetdb5/extras/jaql/jaqltests/Tests/in.jaql
+++ b/monetdb5/extras/jaql/jaqltests/Tests/in.jaql
@@ -4,3 +4,5 @@
 ["fabian","niels"] -> filter $ in ["niels","martin"];
 [3,"bla",4.3] -> filter $ in [4.3,"bla"];
 [true, true, false, null, true] -> filter $ in [true, null];
+
+[{"a":[1,2], "b":"bla,bla"}, {"a":[2,3], "b":"no,no"}, {"a":[4]}] -> filter 2 
in $.a;
diff --git a/monetdb5/extras/jaql/jaqltests/Tests/in.stable.out 
b/monetdb5/extras/jaql/jaqltests/Tests/in.stable.out
--- a/monetdb5/extras/jaql/jaqltests/Tests/in.stable.out
+++ b/monetdb5/extras/jaql/jaqltests/Tests/in.stable.out
@@ -48,6 +48,12 @@ Ready.
 % clob # type
 % 26 # length
 [ true, true, null, true ]
+#[{"a":[1,2], "b":"bla,bla"}, {"a":[2,3], "b":"no,no"}, {"a":[4]}] -> filter 2 
in $.a;
+% .json # table_name
+% json # name
+% clob # type
+% 70 # length
+[ { "a": [ 1, 2 ], "b": "bla,bla" }, { "a": [ 2, 3 ], "b": "no,no" } ]
 
 # 20:32:01 >  
 # 20:32:01 >  "Done."
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to