Changeset: 32ee2cf72c5d for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=32ee2cf72c5d Modified Files: monetdb5/extras/jaql/jaqlfunc.mal monetdb5/extras/jaql/jaqlgencode.c Branch: default Log Message:
jaql: allow non-BAT arguments to json-producing functions
Functions that produce the 7 JSON BATs cannot be used in batch mode, so
they are allowed to take non-BAT arguments as well. An example of a
valid use for this is the shred() function, that reads JSON data from an
URI.
diffs (106 lines):
diff --git a/monetdb5/extras/jaql/jaqlfunc.mal
b/monetdb5/extras/jaql/jaqlfunc.mal
--- a/monetdb5/extras/jaql/jaqlfunc.mal
+++ b/monetdb5/extras/jaql/jaqlfunc.mal
@@ -78,6 +78,14 @@ function arrayToRecord(kindn:bat[:oid,:b
return (r1,r2,r3,r4,r5,r6,r7);
end arrayToRecord;
+# read JSON data from URI
+function
shred(uri:str)(kind:bat[:oid,:bte],string:bat[:oid,:str],integer:bat[:oid,:lng],double:bat[:oid,:dbl],array:bat[:oid,:oid],object:bat[:oid,:oid],name:bat[:oid,:str]);
+ (r1,r2,r3,r4,r5,r6,r7) := json.shreduri(uri);
+
+ return (r1,r2,r3,r4,r5,r6,r7);
+end shred
+
+
# these are groupable functions, they receive their input as :oid,:any_1
# and return the per :oid group result as :oid,:any_2
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
@@ -4402,9 +4402,13 @@ matchfuncsig(jc *j, Client cntxt, tree *
if (f->argc - f->retc - argoff < 1)
break;
itype = getArgType(s->def, f, f->retc + argoff);
- if (!isaBatType(itype) ||
- getHeadType(itype) != TYPE_oid)
+ if (isaBatType(itype)) {
+ if (getHeadType(itype) != TYPE_oid)
+ break;
+ itype = getTailType(itype);
+ } else if (f->retc != 7) {
break;
+ }
switch ((*coltypes)[i]) {
case j_var:
@@ -4416,14 +4420,14 @@ matchfuncsig(jc *j, Client cntxt, tree *
* the first argument to be a
BAT,
* and of the right type */
if (f->argc - f->retc - argoff
>= 7 &&
-
getTailType(itype) == TYPE_bte)
+ itype ==
TYPE_bte)
{
match = 1;
argoff += 7;
break;
}
- switch (getTailType(itype)) {
+ switch (itype) {
case TYPE_str:
(*dynaarg)[i][1] = 0;
(*coltypes)[i]
= j_sort_arg;
@@ -4456,22 +4460,22 @@ matchfuncsig(jc *j, Client cntxt, tree *
}
break;
case j_str:
- if (getTailType(itype) ==
TYPE_str)
+ if (itype == TYPE_str)
match = 1;
argoff += 1;
break;
case j_num:
- if (getTailType(itype) ==
TYPE_lng)
+ if (itype == TYPE_lng)
match = 1;
argoff += 1;
break;
case j_dbl:
- if (getTailType(itype) ==
TYPE_dbl)
+ if (itype == TYPE_dbl)
match = 1;
argoff += 1;
break;
case j_bool:
- if (getTailType(itype) ==
TYPE_bit)
+ if (itype == TYPE_bit)
match = 1;
argoff += 1;
break;
@@ -6295,6 +6299,24 @@ dumptree(jc *j, Client cntxt, MalBlkPtr
case j_num:
case j_dbl:
case j_bool:
+ if (funcretc == 7) {
+ q =
newInstruction(mb, ASSIGNsymbol);
+ q =
pushReturn(mb, q,
+
newTmpVariable(mb, TYPE_any));
+ if (coltypes[i]
== j_str) {
+ q =
pushStr(mb, q, w->tval1->sval);
+ } else if
(coltypes[i] == j_num) {
+ q =
pushLng(mb, q, w->tval1->nval);
+ } else if
(coltypes[i] == j_dbl) {
+ q =
pushDbl(mb, q, w->tval1->dval);
+ } else /*
j_bool */ {
+ q =
pushBit(mb, q, w->tval1->nval == 1);
+ }
+ a = getArg(q,
0);
+
pushInstruction(mb, q);
+ dynaarg[i][0] =
a;
+ break;
+ }
q = newInstruction(mb,
ASSIGNsymbol);
setModuleId(q, batRef);
setFunctionId(q,
newRef);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list
