Changeset: 0787e491ebc3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0787e491ebc3
Modified Files:
        monetdb5/extras/jaql/jaqlgencode.c
        monetdb5/extras/jaql/json.c
Branch: jacqueline
Log Message:

unwrap: sneakily hide array indirection for caller

When the given array is a single array, return as if the single array
was given.  This allows to transparently handle dynamic array arguments,
e.g. both $ and $[*] now result in the same thing if the elem points to
an array.


diffs (95 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
@@ -3172,15 +3172,7 @@ dumpvariabletransformation(jc *j, Client
                                assert(w->tval1 != NULL);
 
                                switch (w->tval1->type) {
-                                       enum treetype oarrtrg = j_invalid;
                                        case j_var:
-                                               if (w->tval1->tval1 != NULL &&
-                                                               
w->tval1->tval1->type == j_arr_idx)
-                                               {
-                                                       oarrtrg = coltypes[i];
-                                                       coltypes[i] = 
j_json_arr;
-                                               }
-
                                                b = 
dumpvariabletransformation(j, cntxt, mb, w->tval1, elems,
                                                                j1, j2, j3, j4, 
j5, j6, j7);
                                                switch (coltypes[i]) {
@@ -3221,34 +3213,6 @@ dumpvariabletransformation(jc *j, Client
                                                                
pushInstruction(mb, q);
                                                                break;
                                                        case j_sort_arg:
-                                                       case j_json_arr:
-                                                               if (coltypes[i] 
== j_json_arr) {
-                                                                       
coltypes[i] = oarrtrg;
-
-                                                                       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, joinRef);
-                                                                       q = 
pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
-                                                                       q = 
pushArgument(mb, q, b);
-                                                                       q = 
pushArgument(mb, q, *j5);
-                                                                       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);
-                                                               }
-
                                                                q = 
newInstruction(mb, ASSIGNsymbol);
                                                                setModuleId(q, 
batRef);
                                                                
setFunctionId(q, newRef);
diff --git a/monetdb5/extras/jaql/json.c b/monetdb5/extras/jaql/json.c
--- a/monetdb5/extras/jaql/json.c
+++ b/monetdb5/extras/jaql/json.c
@@ -1000,6 +1000,15 @@ JSONunwraptype(str *ret, int *kind, int 
        b = BATselect(BATmirror(jb.array), BUNhead(bi, p), BUNhead(bi, p));
        b = BATsemijoin(jb.kind, b);
        bi = bat_iterator(b);
+
+       /* special case for when the argument is a single array */
+       if (BATcount(b) == 1 && *(bte *)BUNtail(bi, BUNfirst(b)) == 'a') {
+               p = BUNfirst(b);
+               b = BATselect(BATmirror(jb.array), BUNhead(bi, p), BUNhead(bi, 
p));
+               b = BATsemijoin(jb.kind, b);
+               bi = bat_iterator(b);
+       }
+
        BATloop(b, p, q) {
                switch (*(bte *)BUNtail(bi, p)) {
                        case 't':
@@ -1074,12 +1083,20 @@ JSONunwrap(Client cntxt, MalBlkPtr mb, M
        BUNfndOID(p, bi, arrid);
        if (*(bte *)BUNtail(bi, p) != 'a') {
                unloadbats();
-               throw(MAL, "json.wraptype", "JSON value must be an array");
+               throw(MAL, "json.unwrap", "JSON value must be an array");
        }
        b = BATselect(BATmirror(jb.array), BUNhead(bi, p), BUNhead(bi, p));
        b = BATsemijoin(jb.kind, b);
        bi = bat_iterator(b);
 
+       /* special case for when the argument is a single array */
+       if (BATcount(b) == 1 && *(bte *)BUNtail(bi, BUNfirst(b)) == 'a') {
+               p = BUNfirst(b);
+               b = BATselect(BATmirror(jb.array), BUNhead(bi, p), BUNhead(bi, 
p));
+               b = BATsemijoin(jb.kind, b);
+               bi = bat_iterator(b);
+       }
+
        bis = bat_iterator(jb.string);
        bii = bat_iterator(jb.integer);
        bid = bat_iterator(jb.doble);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to