Changeset: 1732409fb8fb for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1732409fb8fb Modified Files: monetdb5/extras/jaql/jaql.c monetdb5/extras/jaql/jaqlfunc.mal monetdb5/extras/jaql/jaqlgencode.c monetdb5/extras/jaql/jaqlscenario.c monetdb5/extras/jaql/jaqltree.h monetdb5/extras/jaql/parser/jaql.l monetdb5/extras/jaql/parser/jaql.y Branch: default Log Message:
Merge with Oct2012 branch. diffs (truncated from 339 to 300 lines): 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 @@ -1910,49 +1910,43 @@ JAQLexecute(Client cntxt, MalBlkPtr mb, if (j->err[0] != '\0') break; - if (j->p == NULL) - j->explain = 99; /* jump over switch below */ + if (j->p == NULL) { + /* do nothing */ + } else if (j->plan || j->planf) { + printtree(cntxt->fdout, j->p, 0, j->planf); + mnstr_printf(cntxt->fdout, "\n"); + } else { + str err; + Symbol prg = newFunction(putName("user", 4), putName("jaql", 4), + FUNCTIONsymbol); + /* we do not return anything */ + setVarType(prg->def, 0, TYPE_void); + setVarUDFtype(prg->def, 0); + (void)dumptree(j, cntxt, prg->def, j->p); + pushEndInstruction(prg->def); + /* codegen could report an error */ + if (j->err[0] != '\0') + break; - switch (j->explain) { - case 0: /* normal (execution) mode */ - case 1: /* explain: show MAL-plan */ { - str err; - Symbol prg = newFunction(putName("user", 4), putName("jaql", 4), - FUNCTIONsymbol); - /* we do not return anything */ - setVarType(prg->def, 0, TYPE_void); - setVarUDFtype(prg->def, 0); - (void)dumptree(j, cntxt, prg->def, j->p); - pushEndInstruction(prg->def); - /* codegen could report an error */ - if (j->err[0] != '\0') + chkProgram(cntxt->fdout, cntxt->nspace, prg->def); + if (j->explain) { + printFunction(cntxt->fdout, prg->def, 0, + LIST_MAL_STMT | LIST_MAPI); + } else { + err = (str)runMAL(cntxt, prg->def, 1, 0, 0, 0); + freeMalBlk(prg->def); + if (err != MAL_SUCCEED) { + snprintf(j->err, sizeof(j->err), "%s", err); + GDKfree(err); break; - - chkProgram(cntxt->fdout, cntxt->nspace, prg->def); - if (j->explain == 1) { - printFunction(cntxt->fdout, prg->def, 0, - LIST_MAL_STMT | LIST_MAPI); - } else { - err = (str)runMAL(cntxt, prg->def, 1, 0, 0, 0); - freeMalBlk(prg->def); - if (err != MAL_SUCCEED) { - snprintf(j->err, sizeof(j->err), "%s", err); - GDKfree(err); - break; - } } - } break; - case 2: /* plan */ - case 3: /* planf */ - printtree(cntxt->fdout, j->p, 0, j->explain == 3); - mnstr_printf(cntxt->fdout, "\n"); - break; + } } freetree(j->p); /* reset */ j->p = NULL; j->esc_depth = 0; - j->explain = 0; + j->explain = j->plan = j->planf = j->debug = j->trace = j->mapimode = 0; } while (j->buf[j->pos + (j->tokstart - j->scanbuf)] != '\0' && j->err[0] == '\0'); jaqllex_destroy(j->scanner); 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 @@ -83,7 +83,54 @@ function shred(uri:str)(kind:bat[:oid,:b (r1,r2,r3,r4,r5,r6,r7) := json.shreduri(uri); return (r1,r2,r3,r4,r5,r6,r7); -end shred +end shred; + +# produce a JSON document with trace information +function gettrace()(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 := bat.new(:oid,:bte); + #r2 := bat.new(:oid,:str); + #r3 := bat.new(:oid,:lng); + r4 := bat.new(:oid,:dbl); + #r5 := bat.new(:oid,:oid); + #r6 := bat.new(:oid,:oid); + #r7 := bat.new(:oid,:str); + + r1 := bat.insert(r1, 0@0, 97:bte); # a + + # hardcode info for now, in the future could be argument + t := profiler.getTrace("ticks"); + s := profiler.getTrace("stmt"); + + # build objects + t5 := algebra.markT(t, 1@0); + r5 := algebra.project(0@0, t5); + t6 := bat.reverse(r5); + t7 := algebra.project(t6, 111:bte); # o + + r1 := bat.insert(r1, t7); + + # ticks are lng + n := json.nextid(r1); + r3 := algebra.markH(t, n); + r7 := algebra.project(r3, "ticks"); + t4 := bat.reverse(r3); + r6 := algebra.markH(t4, 1@0); + t1 := algebra.project(r3, 105:bte); # i + r1 := bat.insert(r1, t1); + + # stmt are str + n := json.nextid(r1); + r2 := algebra.markH(s, n); + t8 := algebra.project(r2, "stmt"); + r7 := bat.insert(r7, t8); + t9 := bat.reverse(r2); + r10 := algebra.markH(t9, 1@0); + r6 := bat.insert(r6, r10); + t11 := algebra.project(r2, 115:bte); # s + r1 := bat.insert(r1, t11); + + return (r1,r2,r3,r4,r5,r6,r7); +end gettrace; # these are groupable functions, they receive their input as :oid,:any_1 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 @@ -4963,6 +4963,8 @@ matchfuncsig(jc *j, Client cntxt, tree * * while looking for their uniqueness (like in * Java). */ f = getSignature(s); + if (f->argc - f->retc == 0 && *coltpos == 0) + match = 1; for (i = 0; i < *coltpos; i++) { match = 0; orgoff = argoff; @@ -5075,6 +5077,7 @@ matchfuncsig(jc *j, Client cntxt, tree * if (funcretc == 0) { char argbuf[256]; int pos = 0; + argbuf[0] = '\0'; for (i = 0; i < *coltpos; i++) { if (i > 0) pos += snprintf(argbuf + pos, @@ -5235,11 +5238,29 @@ dumptree(jc *j, Client cntxt, MalBlkPtr { InstrPtr q; int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0; + tree *trout = NULL; /* start with a clean sheet */ j->j1 = j->j2 = j->j3 = j->j4 = j->j5 = j->j6 = j->j7 = 0; j->ro1 = j->ro2 = j->ro3 = j->ro4 = j->ro5 = j->ro6 = j->ro7 = 0; + /* this function is not used recursively, so this is the first thing + * in the resulting MAL plan */ + if (j->trace) { + newStmt(mb, profilerRef, "reset"); + q = newStmt(mb, profilerRef, "setFilter"); + q = pushStr(mb, q, "*"); + q = pushStr(mb, q, "*"); + newStmt(mb, "profiler", "start"); + /* the first jaql tree is the output for the trace, save it for + * later and remove it for plan generation (and the pointer + * given by the caller that it will freetree lateron) */ + trout = t; + t = t->next; + trout->next = NULL; + j->p = t; + } + /* each iteration in this loop is a pipe (a JSON document) * represented by the j1..7 vars */ while (t != NULL) { @@ -5267,7 +5288,7 @@ dumptree(jc *j, Client cntxt, MalBlkPtr q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any)); a = getArg(q, 0); pushInstruction(mb, q); - if (j->explain & 64) { + if (j->mapimode) { q = newInstruction(mb, ASSIGNsymbol); setModuleId(q, putName("json", 4)); setFunctionId(q, putName("exportResult", 12)); @@ -7043,5 +7064,19 @@ dumptree(jc *j, Client cntxt, MalBlkPtr } t = t->next; } + + if (j->trace) { + newStmt(mb, profilerRef, "stop"); + /* call gettrace function, and print it */ + t = append_jaql_pipe( + make_func_call(GDKstrdup("gettrace"), NULL), + trout + ); + j->trace = 0; + dumptree(j, cntxt, mb, t); + j->trace = 1; + freetree(t); + } + return -1; } diff --git a/monetdb5/extras/jaql/jaqlscenario.c b/monetdb5/extras/jaql/jaqlscenario.c --- a/monetdb5/extras/jaql/jaqlscenario.c +++ b/monetdb5/extras/jaql/jaqlscenario.c @@ -182,7 +182,7 @@ JAQLparser(Client c) oldvtop = c->curprg->def->vtop; oldstop = c->curprg->def->stop; j->vtop = oldvtop; - j->explain = 0; + j->explain = j->plan = j->planf = j->debug = j->trace = j->mapimode = 0; j->buf = in->buf + in->pos; j->pos = 0; j->p = NULL; @@ -215,11 +215,11 @@ JAQLparser(Client c) return MAL_SUCCEED; } - if (j->explain < 2 || j->explain == 4) { + if (!j->plan && !j->planf) { Symbol prg = c->curprg; - j->explain |= 64; /* request dumping in MAPI mode */ + j->mapimode = 1; /* request dumping in MAPI mode */ (void)dumptree(j, c, prg->def, j->p); - j->explain &= ~64; + j->mapimode = 0; pushEndInstruction(prg->def); /* codegen could report an error */ if (j->err[0] != '\0') { @@ -271,15 +271,15 @@ JAQLengine(Client c) chkProgram(c->fdout, c->nspace, c->curprg->def); c->glb = 0; - if (j->explain == 1) { + if (j->explain) { printFunction(c->fdout, c->curprg->def, 0, LIST_MAL_STMT | LIST_MAPI); - } else if (j->explain == 2 || j->explain == 3) { + } else if (j->plan || j->planf) { mnstr_printf(c->fdout, "="); - printtree(c->fdout, j->p, 0, j->explain == 3); + printtree(c->fdout, j->p, 0, j->planf); mnstr_printf(c->fdout, "\n"); freetree(j->p); return MAL_SUCCEED; /* don't have a plan generated */ - } else if (j->explain == 4) { + } else if (j->debug) { msg = runMALDebugger(c, c->curprg); } else if (MALcommentsOnly(c->curprg->def)) { msg = MAL_SUCCEED; diff --git a/monetdb5/extras/jaql/jaqltree.h b/monetdb5/extras/jaql/jaqltree.h --- a/monetdb5/extras/jaql/jaqltree.h +++ b/monetdb5/extras/jaql/jaqltree.h @@ -43,7 +43,7 @@ typedef struct _jc { char *tokstart; char err[1024]; void *scanner; - char explain; + char explain:1, debug:2, trace:3, plan:4, planf:5, mapimode:6; 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; diff --git a/monetdb5/extras/jaql/parser/jaql.l b/monetdb5/extras/jaql/parser/jaql.l --- a/monetdb5/extras/jaql/parser/jaql.l +++ b/monetdb5/extras/jaql/parser/jaql.l @@ -115,6 +115,7 @@ explain return EXPLAIN; plan return PLAN; planf return PLANF; debug return DEBUG; +trace return TRACE; /* language constructs */ "->" return ARROW; diff --git a/monetdb5/extras/jaql/parser/jaql.y b/monetdb5/extras/jaql/parser/jaql.y --- a/monetdb5/extras/jaql/parser/jaql.y +++ b/monetdb5/extras/jaql/parser/jaql.y @@ -58,7 +58,7 @@ jaql_import void GDKfree(const char *); %start stmt %token EACH FILTER TRANSFORM EXPAND GROUP INTO BY AS JOIN WHERE IN -%token SORT TOP DESC ASC EXPLAIN PLAN PLANF DEBUG UNROLL PRESERVE +%token SORT TOP DESC ASC EXPLAIN PLAN PLANF DEBUG TRACE UNROLL PRESERVE _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list