Changeset: 09a6d8142c12 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/09a6d8142c12
Modified Files:
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_statement.c
        sql/storage/bat/res_table.c
        sql/test/nested/Tests/simple.test
Branch: nested
Log Message:

more output of nested types


diffs (289 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
@@ -284,9 +284,9 @@ static int
 multiset_size( Column *fmt)
 {
        int nrattrs = (fmt->multiset==MS_VALUE)?0:(fmt->multiset==MS_ARRAY)?3:2;
+       if (fmt->virt)
+               nrattrs++;
        if (fmt->composite) {
-               if (fmt->virt)
-                       nrattrs++;
                int o = 0;
                for (int i = 0; i<fmt->composite; i++) {
                        int j = multiset_size(fmt+(o+1));
@@ -300,21 +300,19 @@ multiset_size( Column *fmt)
 }
 
 static inline ssize_t
-output_line_complex(char **buf, size_t *len, ssize_t fill, char **localbuf, 
size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs, bool inms);
+output_line_complex(char **buf, size_t *len, ssize_t fill, char **localbuf, 
size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs, int composite, bool 
inms);
 
 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)
+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, bool 
inms)
 {
-       (void)composite;
        (*buf)[fill++] = '(';
        if (fmt->virt) {
                fmt++;
                nr_attrs--;
        }
-       if ((fill = output_line_complex(buf, len, fill, localbuf, locallen, 
fmt, fd, nr_attrs, false)) < 0) {
+       if ((fill = output_line_complex(buf, len, fill, localbuf, locallen, 
fmt, fd, nr_attrs, composite, inms)) < 0) {
                return -1;
        }
-       (*buf)[fill++] = ')';
        return fill;
 }
 
@@ -330,11 +328,11 @@ output_multiset_value(char **buf, size_t
                if (!first)
                        (*buf)[fill++] = ',';
                if (composite) {
-                       if ((fill = output_line_composite(buf, len, fill, 
localbuf, locallen, fmt, fd, nr_attrs, composite)) < 0) {
+                       if ((fill = output_line_composite(buf, len, fill, 
localbuf, locallen, fmt, fd, nr_attrs, composite, true)) < 0) {
                                break;
                        }
                } else {
-                       if ((fill = output_line_complex(buf, len, fill, 
localbuf, locallen, fmt, fd, nr_attrs, true)) < 0) {
+                       if ((fill = output_line_complex(buf, len, fill, 
localbuf, locallen, fmt, fd, nr_attrs, 0, true)) < 0) {
                                break;
                        }
                }
@@ -345,17 +343,17 @@ output_multiset_value(char **buf, size_t
 
 static inline ssize_t
 output_line_complex(char **buf, size_t *len, ssize_t fill, char **localbuf, 
size_t *locallen,
-                                 Column *fmt, stream *fd, BUN nr_attrs, bool 
inms)
+                                 Column *fmt, stream *fd, BUN nr_attrs, int 
composite, bool inms)
 {
        BUN j;
-       int composite = 0;
 
        for (j = 0; j < nr_attrs; ) {
                Column *f = fmt + j;
                const char *p;
                ssize_t l = 0;
 
-               if (f->virt && f->composite > 1) {
+               if (f->virt && !f->multiset && f->composite > 1) {
+                       assert(composite == 0);
                        (*buf)[fill++] = '\'';
                        (*buf)[fill++] = '(';
                        (*buf)[fill] = 0;
@@ -364,16 +362,16 @@ output_line_complex(char **buf, size_t *
                        continue;
                }
                if (f->multiset && !inms) {
-                               int nr_attrs = multiset_size(f);
+                               int nr_attrs = multiset_size(f)-1;
                                p = BUNtail(fmt[j+nr_attrs].ci, 
fmt[j+nr_attrs].p);
 
-                               if (!composite)
+                               if (!composite && !inms)
                                        (*buf)[fill++] = '\'';
                                (*buf)[fill++] = '{';
                                (*buf)[fill] = 0;
                                fill = output_multiset_value(buf, len, fill, 
localbuf, locallen, fmt + j + 1, fd, nr_attrs-1, f->multiset, f->composite, 
*(int*)p);
                                (*buf)[fill++] = '}';
-                               if (!composite)
+                               if (!composite && !inms)
                                        (*buf)[fill++] = '\'';
                                (*buf)[fill] = 0;
                                fmt[j+nr_attrs].p++;
@@ -417,7 +415,8 @@ output_line_complex(char **buf, size_t *
                                (*buf)[fill] = 0;
                        } else {
                                (*buf)[fill++] = ')';
-                               (*buf)[fill++] = '\'';
+                               if (!inms)
+                                       (*buf)[fill++] = '\'';
                                (*buf)[fill] = 0;
                                strncpy(*buf + fill, f->sep, f->seplen);
                                fill += f->seplen;
@@ -604,7 +603,7 @@ output_complex(Tablet *as, stream *fd, b
                        res = -5;                       /* "Query aborted" */
                        break;
                }
-               if ((res = output_line_complex(&buf, &len, 0, &localbuf, 
&locallen, as->format, fd, as->nr_attrs, false)) < 0) {
+               if ((res = output_line_complex(&buf, &len, 0, &localbuf, 
&locallen, as->format, fd, as->nr_attrs, 0, false)) < 0) {
                        break;
                }
                if (fd && mnstr_write(fd, buf, 1, res) != res)
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
@@ -316,7 +316,7 @@ statment_score(stmt *c)
        if (c->nrcols != 0) /* no need to create an extra intermediate */
                score += 200;
 
-       if (!t)
+       if (!t || c->nested)
                return score;
        switch (ATOMstorage(t->type->localtype)) { /* give preference to 
smaller types */
                case TYPE_bte:
@@ -354,7 +354,7 @@ static stmt *
 bin_find_smallest_column(backend *be, stmt *sub)
 {
        stmt *res = sub->op4.lval->h->data;
-       int best_score = statment_score(sub->op4.lval->h->data);
+       int best_score = statment_score(res);
 
        if (sub->op4.lval->h->next)
                for (node *n = sub->op4.lval->h->next ; n ; n = n->next) {
@@ -2682,6 +2682,12 @@ rel2bin_basetable(backend *be, sql_rel *
                                        list_append(s->op4.lval, ns);
                                        s->nr = ns->nr;
                                        s->multiset = c->type.multiset;
+                               } else if (s && s->type == st_list && 
c->type.type->composite) {
+                                       stmt *ns = stmt_none(be);
+                                       ns->type = st_alias;
+                                       ns->op4.typeval = *exp_subtype(exp);
+                                       ns->virt = true;
+                                       list_append(s->op4.lval, ns);
                                }
                        } else {
                                s = (c == fcol) ? col : stmt_col(be, c, 
complex?dels:NULL, dels->partition);
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
@@ -1410,7 +1410,8 @@ mvc_export_table_(mvc *m, int output_for
 
                        if (c->multiset) {
                                /* c rowid */
-                               i += output_complex_type(t->cols + i + 1, fmt + 
i + 2,  c->composite?list_length(c->type.type->d.fields):1, true, false);
+                               i++;
+                               i += output_complex_type(t->cols + i, fmt + i + 
1,  c->composite?list_length(c->type.type->d.fields):1, true, false);
                                i++;
                                if (c->multiset == MS_ARRAY)
                                        i++;
@@ -1694,9 +1695,9 @@ static inline int
 next_col(res_col *c)
 {
        int res = 
(c->type.multiset==MS_VALUE)?0:(c->type.multiset==MS_ARRAY)?3:2;
+       if (c->virt)
+               res++;
        if (c->type.type->composite) {
-               if (c->virt)
-                       res++;
                int nr = list_length(c->type.type->d.fields);
                /* needs fix ie needs to jump id,nr cols etc */
                int o = 0;
@@ -1718,13 +1719,32 @@ count_cols(res_table *t)
 
        for(int i = 0; i < t->nr_cols; ) {
                res_col *c = t->cols + i;
-               if (!c->virt)
+               //if (!c->virt || !c->multiset)
                        res++;
                i += next_col(c);
        }
        return res;
 }
 
+static BUN
+count_rows(res_table *t) /* find real output column size */
+{
+       int res = 0;
+       res_col *c = t->cols;
+
+       if (c->virt) {
+               if (c->multiset)
+                       res = next_col(c) - 1;
+               else
+                       res++;
+       }
+       c = t->cols + res;
+       if (c->cached)
+               return BATcount((BAT*)c->p);
+       else
+               return BATcount(BBPquickdesc(c->b));
+}
+
 int
 mvc_export_head(backend *b, stream *s, int res_id, int only_header, int 
compute_lengths, lng starttime, lng maloptimizer)
 {
@@ -1736,8 +1756,10 @@ mvc_export_head(backend *b, stream *s, i
        if (!s || !t)
                return 0;
 
-       if (t->complex_type)
+       if (t->complex_type) {
                t->nr_output_cols = count_cols(t);
+               t->nr_rows = count_rows(t);
+       }
        /* query type: Q_TABLE || Q_PREPARE */
        assert(t->query_type == Q_TABLE || t->query_type == Q_PREPARE);
        if (mnstr_write(s, "&", 1, 1) != 1 || mvc_send_int(s, (int) 
t->query_type) != 1 || mnstr_write(s, " ", 1, 1) != 1)
diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -3300,6 +3300,8 @@ nested_dump_header(mvc *sql, MalBlkPtr m
                stmt *c = n->data;
                sql_subtype *t = tail_type(c);
                bool virt = (!c->q && c->type == st_alias && !c->op1 && 
c->multiset);
+               if (!c->nested && c->virt)
+                       continue;
 
                sql_alias *tname = table_name(sql->sa, c);
                const char *_empty = "";
@@ -4873,7 +4875,7 @@ tail_type(stmt *st)
                        st = st->op1;
                        continue;
                case st_list:
-                       st = st->op4.lval->h->data;
+                       st = st->op4.lval->t->data;
                        continue;
                case st_bat:
                        return &st->op4.cval->type;
diff --git a/sql/storage/bat/res_table.c b/sql/storage/bat/res_table.c
--- a/sql/storage/bat/res_table.c
+++ b/sql/storage/bat/res_table.c
@@ -82,9 +82,16 @@ res_col_create(sql_trans *tr, res_table 
                b = (BAT*)val;
                if (b && t->nr_rows == BUN_NONE && !c->virt && t->cur_col == 
t->output_col)
                        t->nr_rows = BATcount(b);
+               /*
                else if (c->virt) {
-                       t->output_col = 4;
+                       if (c->multiset && c->type.type->composite)
+                               t->output_col = c->multiset + 
c->type.type->composite + 1;
+                       else if (c->multiset)
+                               t->output_col = c->multiset + 2;
+                       else
+                               t->output_col++;
                }
+               */
        } else { // wrap scalar values in BATs for result consistency
                b = COLnew(0, mtype, 1, TRANSIENT);
                if (b == NULL) {
diff --git a/sql/test/nested/Tests/simple.test 
b/sql/test/nested/Tests/simple.test
--- a/sql/test/nested/Tests/simple.test
+++ b/sql/test/nested/Tests/simple.test
@@ -15,6 +15,12 @@ right
 left
 right
 
+query T nosort
+select * from foo
+----
+("left", "right")
+("left", "right")
+
 query I nosort
 select count(*) from foo
 ----
@@ -34,6 +40,11 @@ right
 left
 right
 
+query T nosort
+select * from bar;
+----
+{("left", "right"),("left", "right")}
+
 query I nosort
 select count(*) from bar, unnest(p)
 ----
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to