Changeset: 96c6a859807f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/96c6a859807f Modified Files: monetdb5/modules/mal/tablet.c monetdb5/modules/mal/tablet.h sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_result.c sql/include/sql_catalog.h sql/server/rel_basetable.c sql/server/rel_multiset.c sql/storage/bat/bat_storage.c sql/storage/bat/res_table.c sql/storage/store.c sql/test/nested/Tests/webclicks.test Branch: nested Log Message:
handle complex type output (wip) diffs (truncated from 513 to 300 lines): diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c --- a/monetdb5/modules/mal/tablet.c +++ b/monetdb5/modules/mal/tablet.c @@ -283,9 +283,14 @@ static int multiset_size( Column *fmt) { int nrattrs = 1 + (fmt->multiset == MS_ARRAY); - //if (fmt[1]) { /* todo check composite types */ + if (fmt[0].composite) { + nrattrs += fmt[0].composite; + for (int i = 0; i<fmt[0].composite; i++) + if (fmt[i+1].multiset) + nrattrs += multiset_size(fmt+(i+1)); + } else { nrattrs ++; - //} + } return nrattrs; } @@ -293,8 +298,24 @@ static inline ssize_t output_line_multiset(char **buf, size_t *len, ssize_t fill, char **localbuf, size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs); static ssize_t +output_line_composite(char **buf, size_t *len, ssize_t fill, char **localbuf, size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs, int composite) +{ + (void)composite; + (*buf)[fill++] = '('; + if (!fmt->multiset) { + fmt++; + nr_attrs--; + } + if ((fill = output_line_multiset(buf, len, fill, localbuf, locallen, fmt, fd, nr_attrs)) < 0) { + return -1; + } + (*buf)[fill++] = ')'; + return fill; +} + +static ssize_t output_multiset_value(char **buf, size_t *len, ssize_t fill, char **localbuf, size_t *locallen, - Column *fmt, stream *fd, BUN nr_attrs, int multiset, int id) + Column *fmt, stream *fd, BUN nr_attrs, int multiset, int composite, int id) { nr_attrs -= (multiset == MS_ARRAY)?2:1; Column *msid = fmt + nr_attrs; @@ -303,8 +324,14 @@ output_multiset_value(char **buf, size_t for (; *idp == id; idp++, msid->p++) { if (!first) (*buf)[fill++] = ','; - if ((fill = output_line_multiset(buf, len, fill, localbuf, locallen, fmt, fd, nr_attrs)) < 0) { - break; + if (composite) { + if ((fill = output_line_composite(buf, len, fill, localbuf, locallen, fmt, fd, nr_attrs, composite)) < 0) { + break; + } + } else { + if ((fill = output_line_multiset(buf, len, fill, localbuf, locallen, fmt, fd, nr_attrs)) < 0) { + break; + } } first = 0; } @@ -332,7 +359,7 @@ output_line_multiset(char **buf, size_t (*buf)[fill++] = '\''; (*buf)[fill++] = '{'; (*buf)[fill] = 0; - fill = output_multiset_value(buf, len, fill, localbuf, locallen, fmt + i + 1, fd, nr_attrs, f->multiset, *(int*)p); + fill = output_multiset_value(buf, len, fill, localbuf, locallen, fmt + i + 1, fd, nr_attrs, f->multiset, f->composite, *(int*)p); (*buf)[fill++] = '}'; (*buf)[fill++] = '\''; (*buf)[fill] = 0; diff --git a/monetdb5/modules/mal/tablet.h b/monetdb5/modules/mal/tablet.h --- a/monetdb5/modules/mal/tablet.h +++ b/monetdb5/modules/mal/tablet.h @@ -44,6 +44,7 @@ typedef struct Column_t { unsigned int width; /* actual column width */ unsigned int maxwidth; /* permissible width */ int multiset; /* multiset */ + int composite; /* 0 no composite type else number of composite fields */ int fieldstart; /* Fixed character field load positions */ int fieldwidth; int scale, precision; diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -2443,6 +2443,26 @@ rel2bin_sql_table(backend *be, sql_table return stmt_list(be, l); } +typedef struct subtable_e { + sql_table *t; + int nr; + stmt *dels; +} subtable_e; + +static sql_column * +subtable_e_find(subtable_e *sts, const char *name, int nr, stmt **dels) +{ + for(int i = 0; i < nr; i++) { + sql_table *t = sts[i].t; + sql_column *c = find_sql_column(t, name); + if (c) { + *dels = sts[i].dels; + return c; + } + } + return NULL; +} + static stmt * rel2bin_basetable(backend *be, sql_rel *rel) { @@ -2454,7 +2474,17 @@ rel2bin_basetable(backend *be, sql_rel * stmt *dels = stmt_tid(be, t, rel->flag == REL_PARTITION), *odels = dels, *col = NULL; node *en; list *subtables = rel_base_subtables(rel); - node *stn = NULL; + int nr = list_length(subtables); + subtable_e *sts = NULL; + if (nr) { + sts = (subtable_e*)sa_alloc(be->mvc->sa, sizeof(subtable_e)*nr); + int i = 0; + for(node *n = subtables->h; n; n = n->next, i++) { + sts[i].t = n->data; + sts[i].nr = 0; + sts[i].dels = stmt_tid(be, sts[i].t, rel->flag == REL_PARTITION); + } + } bool multiset = t->multiset; if (l == NULL || dels == NULL) @@ -2508,23 +2538,17 @@ rel2bin_basetable(backend *be, sql_rel * continue; s = (i == fi) ? col : stmt_idx(be, i, multiset?dels:NULL, dels->partition); } else { - sql_column *c = find_sql_column(t, oname); - if (!c && stn) { - t = bt; + sql_column *c = find_sql_column(bt, oname); + if (c) { dels = odels; - c = find_sql_column(t, oname); + } else if (sts) { + c = subtable_e_find(sts, oname, nr, &dels); } + assert(c); if (!c->type.multiset && c->type.type->composite) continue; s = (c == fcol) ? col : stmt_col(be, c, multiset?dels:NULL, dels->partition); - if (c->type.multiset) { - if (!stn) - stn = subtables->h; - t = stn->data; - dels = stmt_tid(be, t, rel->flag == REL_PARTITION); - stn = stn->next; - } } s = stmt_alias(be, s, exp->alias.label, rname, exp_name(exp)); list_append(l, s); 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 @@ -1246,10 +1246,15 @@ mvc_export_table_columnar(stream *s, res } static int -multiset_size(res_col *c) +complex_type_size(res_col *c) { if (c->type.multiset) { - return 1+(c->type.multiset == MS_ARRAY?3:2); + int res = (c->type.multiset == MS_ARRAY?2:1); + if (c->type.type->composite) + res += list_length(c->type.type->d.fields); + else + res ++; + return res; } return 0; } @@ -1286,7 +1291,7 @@ mvc_export_table_(mvc *m, int output_for fmt[0].ws = 0; fmt[0].nullstr = NULL; - int multiset = 0; + int complex_type = 0; for (i = 1; i <= t->nr_cols; i++) { res_col *c = t->cols + (i - 1); @@ -1311,11 +1316,12 @@ mvc_export_table_(mvc *m, int output_for fmt[i].rsep = rsep; } fmt[i].multiset = c->type.multiset; - multiset += multiset_size(c); - if (multiset>1) { - fmt[i].sep = NULL; - fmt[i].seplen = 0; - multiset--; + fmt[i].composite = c->type.type->composite?list_length(c->type.type->d.fields):0; + complex_type += complex_type_size(c); + if (complex_type>1) { + fmt[i].sep = NULL;// ", "; + fmt[i].seplen = 0;//2; + complex_type--; } if (json) { res_col *p = t->cols + (i - 1); @@ -1353,7 +1359,10 @@ mvc_export_table_(mvc *m, int output_for fmt[i].data = NULL; fmt[i].len = 0; fmt[i].ws = 0; - fmt[i].quote = ssep ? ssep[0] : 0; + if (complex_type) + fmt[i].quote = '"'; + else + fmt[i].quote = ssep ? ssep[0] : 0; fmt[i].nullstr = ns; if (c->type.type->eclass == EC_DEC) { fmt[i].tostr = &dec_tostr; @@ -1651,9 +1660,19 @@ mvc_export_affrows(backend *b, stream *s } static inline int -skip_multiset(res_col *c) +next_col(res_col *c) { - return (c->type.multiset==MS_VALUE)?0:(c->type.multiset==MS_ARRAY)?3:2; + int res = (c->type.multiset==MS_VALUE)?0:(c->type.multiset==MS_ARRAY)?3:2; + if (c->type.type->composite) { + int nr = list_length(c->type.type->d.fields); + res += nr; + for(int i = 0; i < nr; i++) { + res += next_col(c+i+1); + } + } else { + res++; + } + return res; } int @@ -1716,20 +1735,20 @@ mvc_export_head(backend *b, stream *s, i if (mnstr_write(s, "\n% ", 3, 1) != 1) return -4; - for (i = 0; i < t->nr_cols; i++) { + for (i = 0; i < t->nr_cols; ) { res_col *c = t->cols + i; size_t len = strlen(c->tn); if (len && mnstr_write(s, c->tn, len, 1) != 1) return -4; - i += skip_multiset(c); - if (i + 1 < t->nr_cols && mnstr_write(s, ",\t", 2, 1) != 1) + i += next_col(c); + if (i < t->nr_cols && mnstr_write(s, ",\t", 2, 1) != 1) return -4; } if (mnstr_write(s, " # table_name\n% ", 16, 1) != 1) return -4; - for (i = 0; i < t->nr_cols; i++) { + for (i = 0; i < t->nr_cols; ) { res_col *c = t->cols + i; if (strpbrk(c->name, ", \t#\"\\")) { @@ -1750,40 +1769,40 @@ mvc_export_head(backend *b, stream *s, i if (mnstr_write(s, c->name, strlen(c->name), 1) != 1) return -4; } + i += next_col(c); - i += skip_multiset(c); - if (i + 1 < t->nr_cols && mnstr_write(s, ",\t", 2, 1) != 1) + if (i < t->nr_cols && mnstr_write(s, ",\t", 2, 1) != 1) return -4; } if (mnstr_write(s, " # name\n% ", 10, 1) != 1) return -4; - for (i = 0; i < t->nr_cols; i++) { + for (i = 0; i < t->nr_cols; ) { res_col *c = t->cols + i; - if (c->type.multiset) { + if (c->type.multiset || c->type.type->composite) { if (mnstr_write(s, "varchar", 7, 1) != 1) return -4; } else if (mnstr_write(s, c->type.type->base.name, strlen(c->type.type->base.name), 1) != 1) return -4; //if (c->type.multiset && mnstr_write(s, "[]", 2, 1) != 1) //return -4; - i += skip_multiset(c); - if (i + 1 < t->nr_cols && mnstr_write(s, ",\t", 2, 1) != 1) + i += next_col(c); + if (i < t->nr_cols && mnstr_write(s, ",\t", 2, 1) != 1) return -4; } _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org