Changeset: f09d1d5bedd4 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f09d1d5bedd4 Modified Files: sql/backends/monet5/sql_execute.c sql/backends/monet5/sql_result.c sql/backends/monet5/sql_result.h sql/backends/monet5/sql_scenario.c Branch: monetdbe-proxy Log Message:
Add support for columnar format in mvc_export_prepare. diffs (292 lines): diff --git a/sql/backends/monet5/sql_execute.c b/sql/backends/monet5/sql_execute.c --- a/sql/backends/monet5/sql_execute.c +++ b/sql/backends/monet5/sql_execute.c @@ -544,7 +544,7 @@ SQLstatementIntern(Client c, str *expr, } if (!err) - err = mvc_export_prepare(m, c->fdout, be->q, ""); + err = mvc_export_prepare(be, c->fdout, ""); } } diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c --- a/sql/backends/monet5/sql_result.c +++ b/sql/backends/monet5/sql_result.c @@ -919,9 +919,130 @@ mvc_export_warning(stream *s, str w) return (1); } +static void +mvc_export_binary_bat(stream *s, BAT* bn) { + bool sendtheap = bn->ttype != TYPE_void && bn->tvarsized; + + mnstr_printf(s, /*JSON*/"{" + "\"version\":1," + "\"ttype\":%d," + "\"hseqbase\":" OIDFMT "," + "\"tseqbase\":" OIDFMT "," + "\"tsorted\":%d," + "\"trevsorted\":%d," + "\"tkey\":%d," + "\"tnonil\":%d," + "\"tdense\":%d," + "\"size\":" BUNFMT "," + "\"tailsize\":%zu," + "\"theapsize\":%zu" + "}\n", + bn->ttype, + bn->hseqbase, bn->tseqbase, + bn->tsorted, bn->trevsorted, + bn->tkey, + bn->tnonil, + BATtdense(bn), + bn->batCount, + (size_t)bn->batCount * Tsize(bn), + sendtheap && bn->batCount > 0 ? bn->tvheap->free : 0 + ); + + if (bn->batCount > 0) { + mnstr_write(s, /* tail */ Tloc(bn, 0), bn->batCount * Tsize(bn), 1); + if (sendtheap) + mnstr_write(s, /* theap */ Tbase(bn), bn->tvheap->free, 1); + } + + mnstr_flush(s); +} + +static int +mvc_export_prepare_columnar(stream *out, cq *q, int nrows, sql_rel *r) { + int error = -1; + + BAT* btype = COLnew(0, TYPE_int, nrows, TRANSIENT); + BAT* bdigits = COLnew(0, TYPE_int, nrows, TRANSIENT); + BAT* bscale = COLnew(0, TYPE_int, nrows, TRANSIENT); + BAT* bschema = COLnew(0, TYPE_str, nrows, TRANSIENT); + BAT* btable = COLnew(0, TYPE_str, nrows, TRANSIENT); + BAT* bcolumn = COLnew(0, TYPE_str, nrows, TRANSIENT); + + node *n; + sql_subtype *t; + sql_arg *a; + if (r && is_project(r->op) && r->exps) { + for (n = r->exps->h; n; n = n->next) { + const char *name, *rname, *schema = NULL; + sql_exp *e = n->data; + + t = exp_subtype(e); + name = exp_name(e); + if (!name && e->type == e_column && e->r) + name = e->r; + rname = exp_relname(e); + if (!rname && e->type == e_column && e->l) + rname = e->l; + + if (!schema) + schema = ""; + + if (!rname) + rname = ""; + + if (!name) + name = ""; + + if ( BUNappend(btype, &t->type->localtype , false) != GDK_SUCCEED || + BUNappend(bdigits, &t->digits , false) != GDK_SUCCEED || + BUNappend(bscale, &t->scale , false) != GDK_SUCCEED || + BUNappend(bschema, &schema , false) != GDK_SUCCEED || + BUNappend(btable, &rname , false) != GDK_SUCCEED || + BUNappend(bcolumn, &name , false) != GDK_SUCCEED) + goto bailout; + } + } + + if (q->f->ops) { + int i; + + for (n = q->f->ops->h, i = 0; n; n = n->next, i++) { + a = n->data; + t = &a->type; + + if ( BUNappend(btype, &t->type->localtype , false) != GDK_SUCCEED || + BUNappend(bdigits, &t->digits , false) != GDK_SUCCEED || + BUNappend(bscale, &t->scale , false) != GDK_SUCCEED || + BUNappend(bschema, &str_nil , false) != GDK_SUCCEED || + BUNappend(btable, &str_nil , false) != GDK_SUCCEED || + BUNappend(bcolumn, &str_nil , false) != GDK_SUCCEED) + goto bailout; + } + } + + mvc_export_binary_bat(out, btype); + mvc_export_binary_bat(out, bdigits); + mvc_export_binary_bat(out, bscale); + mvc_export_binary_bat(out, bschema); + mvc_export_binary_bat(out, btable); + mvc_export_binary_bat(out, bcolumn); + + error = 0; + + bailout: + BBPreclaim(btype); + BBPreclaim(bdigits); + BBPreclaim(bscale); + BBPreclaim(bschema); + BBPreclaim(btable); + BBPreclaim(bcolumn); + return error; +} + int -mvc_export_prepare(mvc *c, stream *out, cq *q, str w) +mvc_export_prepare(backend *b, stream *out, str w) { + cq *q = b->q; node *n; int nparam = q->f->ops ? list_length(q->f->ops) : 0; int nrows = nparam; @@ -931,7 +1052,6 @@ mvc_export_prepare(mvc *c, stream *out, sql_subtype *t; sql_rel *r = q->rel; - (void)c; if(!out || GDKembedded()) return 0; @@ -1003,36 +1123,42 @@ mvc_export_prepare(mvc *c, stream *out, return -1; } - if (r && is_project(r->op) && r->exps) { - for (n = r->exps->h; n; n = n->next) { - const char *name, *rname, *schema = NULL; - sql_exp *e = n->data; + if (b->client->protocol == PROTOCOL_COLUMNAR) { + mvc_export_prepare_columnar(out, q, nrows, r); + } + else { + if (r && is_project(r->op) && r->exps) { + for (n = r->exps->h; n; n = n->next) { + const char *name, *rname, *schema = NULL; + sql_exp *e = n->data; - t = exp_subtype(e); - name = exp_name(e); - if (!name && e->type == e_column && e->r) - name = e->r; - rname = exp_relname(e); - if (!rname && e->type == e_column && e->l) - rname = e->l; + t = exp_subtype(e); + name = exp_name(e); + if (!name && e->type == e_column && e->r) + name = e->r; + rname = exp_relname(e); + if (!rname && e->type == e_column && e->l) + rname = e->l; - if (mnstr_printf(out, "[ \"%s\",\t%u,\t%u,\t\"%s\",\t\"%s\",\t\"%s\"\t]\n", t->type->sqlname, t->digits, t->scale, schema ? schema : "", rname ? rname : "", name ? name : "") < 0) { - return -1; + if (mnstr_printf(out, "[ \"%s\",\t%u,\t%u,\t\"%s\",\t\"%s\",\t\"%s\"\t]\n", t->type->sqlname, t->digits, t->scale, schema ? schema : "", rname ? rname : "", name ? name : "") < 0) { + return -1; + } + } + } + + if (q->f->ops) { + int i; + + for (n = q->f->ops->h, i = 0; n; n = n->next, i++) { + a = n->data; + t = &a->type; + + if (!t || mnstr_printf(out, "[ \"%s\",\t%u,\t%u,\tNULL,\tNULL,\tNULL\t]\n", t->type->sqlname, t->digits, t->scale) < 0) + return -1; } } } - if (q->f->ops) { - int i; - - for (n = q->f->ops->h, i = 0; n; n = n->next, i++) { - a = n->data; - t = &a->type; - - if (!t || mnstr_printf(out, "[ \"%s\",\t%u,\t%u,\tNULL,\tNULL,\tNULL\t]\n", t->type->sqlname, t->digits, t->scale) < 0) - return -1; - } - } if (mvc_export_warning(out, w) != 1) return -1; return 0; @@ -1646,44 +1772,7 @@ mvc_export_table_columnar(stream *s, res return -1; } - BAT* bn = b; - - bool sendtheap = b->ttype != TYPE_void && b->tvarsized; - - mnstr_printf(s, /*JSON*/"{" - "\"version\":1," - "\"ttype\":%d," - "\"hseqbase\":" OIDFMT "," - "\"tseqbase\":" OIDFMT "," - "\"tsorted\":%d," - "\"trevsorted\":%d," - "\"tkey\":%d," - "\"tnonil\":%d," - "\"tdense\":%d," - "\"size\":" BUNFMT "," - "\"tailsize\":%zu," - "\"theapsize\":%zu" - "}\n", - bn->ttype, - bn->hseqbase, bn->tseqbase, - bn->tsorted, bn->trevsorted, - bn->tkey, - bn->tnonil, - BATtdense(bn), - bn->batCount, - (size_t)bn->batCount * Tsize(bn), - sendtheap && bn->batCount > 0 ? bn->tvheap->free : 0 - ); - - if (bn->batCount > 0) { - mnstr_write(s, /* tail */ - Tloc(bn, 0), bn->batCount * Tsize(bn), 1); - if (sendtheap) - mnstr_write(s, /* theap */ - Tbase(bn), bn->tvheap->free, 1); - } - - mnstr_flush(s); + mvc_export_binary_bat(s, b); BBPunfix(b->batCacheid); } diff --git a/sql/backends/monet5/sql_result.h b/sql/backends/monet5/sql_result.h --- a/sql/backends/monet5/sql_result.h +++ b/sql/backends/monet5/sql_result.h @@ -23,7 +23,7 @@ extern int mvc_export_result(backend *b, extern int mvc_export_head(backend *b, stream *s, int res_id, int only_header, int compute_lengths, lng starttime, lng maloptimizer); extern int mvc_export_chunk(backend *b, stream *s, int res_id, BUN offset, BUN nr); -extern int mvc_export_prepare(mvc *c, stream *s, cq *q, str w); +extern int mvc_export_prepare(backend *b, stream *s, str w); extern str mvc_import_table(Client cntxt, BAT ***bats, mvc *c, bstream *s, sql_table *t, const char *sep, const char *rsep, const char *ssep, const char *ns, lng nr, lng offset, int locked, int best, bool from_stdin); extern int mvc_result_table(backend *be, oid query_id, int nr_cols, mapi_query_t type, BAT *order); diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -1150,7 +1150,7 @@ SQLparser(Client c) assert(m->emode == m_prepare); /* For prepared queries, return a table with result set structure*/ /* optimize the code block and rename it */ - err = mvc_export_prepare(m, c->fdout, be->q, ""); + err = mvc_export_prepare(be, c->fdout, ""); } if (!err) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list