Changeset: de62fbf5eea9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/de62fbf5eea9
Modified Files:
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/rel_tvtree.c
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_statement.c
        sql/server/rel_basetable.c
        sql/server/rel_exp.c
        sql/server/rel_updates.c
        sql/server/sql_parser.y
        sql/storage/bat/bat_storage.c
        sql/storage/store.c
        sql/test/nested/Tests/vector_basic.test
Branch: nested
Log Message:

layout vectors similar to composite types


diffs (truncated from 476 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
@@ -501,7 +501,7 @@ output_vector(allocator*ma, char **buf, 
 {
        int first = 1;
        (*buf)[fill++] = '\'';
-       (*buf)[fill++] = '{';
+       (*buf)[fill++] = '(';
        (*buf)[fill] = 0;
        for (size_t i = 0; fill > 0 && i < nr_attrs; i++) {
                if (!first)
@@ -511,7 +511,7 @@ output_vector(allocator*ma, char **buf, 
        }
        if (fill < 0)
                return fill;
-       (*buf)[fill++] = '}';
+       (*buf)[fill++] = ')';
        (*buf)[fill++] = '\'';
        (*buf)[fill] = 0;
        return fill;
@@ -529,7 +529,7 @@ output_line_complex(allocator *ma, char 
 
                if (f->ms_vector) {
                        int nr_attrs = f->nrfields - 1;
-                       fill = output_vector(ma, buf, len, fill, localbuf, 
locallen, fmt + j + 1, nr_attrs-2);
+                       fill = output_vector(ma, buf, len, fill, localbuf, 
locallen, fmt + j + 1, nr_attrs);
                        f = fmt + j + nr_attrs; /* closing bracket */
                        j += nr_attrs + 1;
                } else if (f->multiset) {
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
@@ -2676,7 +2676,7 @@ rel2bin_subtable(backend *be, sql_table 
        list *l = sa_list(sql->sa);
        stmt *col = NULL;
 
-       if (c->type.multiset) {
+       if (c->type.multiset && (c->type.multiset != MS_VECTOR)) {
                t = mvc_bind_table(sql, c->t->s, c->storage_type);
                if (!t)
                        return NULL;
@@ -2715,7 +2715,9 @@ rel2bin_subtable(backend *be, sql_table 
                                if (!s)
                                        return s;
                                s->nested = true;
-                               if (s && s->type == st_list && 
c->type.multiset) { /* keep rowid at the end */
+                               if (s && s->type == st_list
+                                               && c->type.multiset
+                                               && (c->type.multiset != 
MS_VECTOR)) { /* keep rowid at the end */
                                        stmt *ls = s->op4.lval->t->data;
                                        stmt *ns = stmt_col(be, c, dels, 
dels->partition);
                                        ns->subtype = ls->subtype; // TODO find 
correct type of rowid/msid (don't use msnr type
@@ -2723,7 +2725,8 @@ rel2bin_subtable(backend *be, sql_table 
                                        s->nr = ns->nr;
                                        s->subtype = *exp_subtype(exp);
                                        s->multiset = s->subtype.multiset;
-                               } else if (s && s->type == st_list && 
c->type.type->composite) {
+                               } else if (s && s->type == st_list
+                                               && (c->type.type->composite || 
c->type.multiset != MS_VECTOR)) {
                                        s->subtype = *exp_subtype(exp);
                                }
                        } else {
@@ -2809,7 +2812,9 @@ rel2bin_basetable(backend *be, sql_rel *
                                if (!s)
                                        return s;
                                s->nested = true;
-                               if (s && s->type == st_list && 
c->type.multiset) { /* keep rowid at the end */
+                               if (s && s->type == st_list
+                                               && c->type.multiset
+                                               && c->type.multiset != 
MS_VECTOR) { /* keep rowid at the end */
                                        stmt *ls = s->op4.lval->t->data;
                                        stmt *ns = (c == fcol) ? col : 
stmt_col(be, c, complex?dels:NULL, dels->partition);
                                        ns->subtype = ls->subtype; // TODO find 
correct type of rowid/msid (don't use msnr type
@@ -2817,7 +2822,8 @@ rel2bin_basetable(backend *be, sql_rel *
                                        s->nr = ns->nr;
                                        s->subtype = *exp_subtype(exp);
                                        s->multiset = s->subtype.multiset;
-                               } else if (s && s->type == st_list && 
c->type.type->composite) {
+                               } else if (s && s->type == st_list
+                                               && (c->type.type->composite || 
c->type.multiset == MS_VECTOR)) {
                                        s->subtype = *exp_subtype(exp);
                                }
                        } else {
@@ -6128,6 +6134,23 @@ insert_composite(backend *be, stmt **upd
        return n;
 }
 
+static inline node *
+insert_vector(stmt **updates, node *n, node *m)
+{
+       stmt *input_tuple = m->data;
+
+       while(input_tuple->type == st_alias)
+               input_tuple = input_tuple->op1;
+       assert(input_tuple->type == st_list);
+       if (input_tuple->type != st_list)
+               return NULL;
+       for(m = input_tuple->op4.lval->h; n && m; n = n->next, m = m->next) {
+               sql_column *c = n->data;
+               updates[c->colnr] = m->data;
+       }
+       return n;
+}
+
 static stmt *
 insert_ms(backend *be, sql_table *st, sql_subtype *ct, stmt *ms)
 {
@@ -6256,7 +6279,10 @@ rel2bin_insert_ms(backend *be, sql_rel *
        for (n = ol_first_node(t->columns), m = inserts->op4.lval->h; n && m; ) 
{
                sql_column *c = n->data;
 
-               if (c->type.multiset) {
+               if (c->type.multiset == MS_VECTOR) {
+                       n = insert_vector(updates, n->next, m);
+                       m = m->next;
+               } else if (c->type.multiset) {
                        sql_table *st = mvc_bind_table(sql, t->s, 
c->storage_type);
                        if (!st)
                                return sql_error(sql, 10, SQLSTATE(27000) 
"INSERT INTO: sub table '%s' missing", c->storage_type);
diff --git a/sql/backends/monet5/rel_tvtree.c b/sql/backends/monet5/rel_tvtree.c
--- a/sql/backends/monet5/rel_tvtree.c
+++ b/sql/backends/monet5/rel_tvtree.c
@@ -58,12 +58,12 @@ tv_node(allocator *sa, sql_subtype *st, 
                        }
                return n;
         case TV_VECTOR:
-                       n->rid = sa_list(sa);
-                       n->msid = sa_list(sa);
                        n->ctl = sa_list(sa);
-                       sn = tv_node(sa, st, TV_BASIC);
-                       sn->st = st;
-                       append(n->ctl, sn);
+                       for (unsigned int i=0; i < st->digits; i++) {
+                               sql_subtype *_st = sql_create_subtype(sa, 
st->type, 0, 0);
+                               sn = tv_node(sa, _st, TV_BASIC);
+                               append(n->ctl, sn);
+                       }
                        return n;
         case TV_MSET:
                        n->msnr = sa_list(sa);
@@ -261,7 +261,6 @@ tv_parse_values_(backend *be, tv_tree *t
                        break;
                case TV_MSET:
                case TV_SETOF:
-               case TV_VECTOR:
                        //assert(is_convert(value->type));
                        assert(value->f);
                        uc = value;
@@ -275,6 +274,7 @@ tv_parse_values_(backend *be, tv_tree *t
                 return mset_value_from_array_constructor(be, t, uc, left, sel);
             break;
                case TV_COMP:
+               case TV_VECTOR:
                        if (is_convert(value->type))
                                /* VALUES ('(1,"alice")') */
                                return comp_value_from_literal(be, t, value, 
left, sel);
@@ -350,24 +350,6 @@ tv_generate_stmts(backend *be, tv_tree *
        switch (t->tvt) {
                case TV_BASIC:
                        return stmt_append_bulk(be, stmt_temp(be, t->st), 
t->vals);
-               case TV_VECTOR:
-                       /* vals (in the child tree) */
-                       assert(list_length(t->ctl) == 1);
-                       s = stmt_list(be, sa_list(be->mvc->sa));
-                       ct = t->ctl->h->data;
-                       for (node *n = ct->vals->h; n; n = n->next) {
-                               tmp = stmt_temp(be, tail_type(n->data));
-                               ap = stmt_append(be, tmp, n->data);
-                               append(s->op4.lval, ap);
-                       }
-                       /* msid */
-                       tmp = stmt_temp(be, tail_type(t->msid->h->data));
-                       ap = stmt_append(be, tmp, t->msid->h->data);
-                       append(s->op4.lval, ap);
-                       /* we've appended in the stmt_list so update nrcols */
-                       stmt_set_nrcols(s);
-                       s->subtype = *t->st;
-                       return s;
                case TV_MSET:
                case TV_SETOF:
                        /* vals (in the child tree) */
@@ -406,6 +388,7 @@ tv_generate_stmts(backend *be, tv_tree *
                        s->subtype = *t->st;
                        return s;
                case TV_COMP:
+               case TV_VECTOR:
                        sl = sa_list(be->mvc->sa);
                        /* gather all the composite (sub)field's statements */
                        for (node *n = t->ctl->h; n; n = n->next)
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
@@ -1726,8 +1726,9 @@ next_col(res_col *c)
                        res = 3;
                        break;
                case MS_VECTOR:
-                       res = c->type.digits + 1; // all the dimensions + ms_id
-                       break;
+                       res = c->type.digits + 1; // all dimensions
+                       c->nrfields = res;
+                       return res;
                default:
                        res = 2; // MS_SETOF?
        }
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
@@ -4280,7 +4280,7 @@ composite_type_resultsize(sql_subtype *t
 
        if (t->multiset) {
                if (t->multiset == MS_VECTOR) {
-                       return 1 + t->digits;
+                       return t->digits;
                } else {
                        nr += 2 + (t->multiset == MS_ARRAY);
                }
@@ -4326,7 +4326,7 @@ composite_type_result(backend *be, Instr
                        tps[i].st = *t;
                        tps[i++].multiset = false;
                }
-               if (t->multiset) { /* msid */
+               if (t->multiset && (t->multiset != MS_VECTOR)) { /* msid */
                        q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(TYPE_int)));
                        tps[i].st = *sql_fetch_localtype(TYPE_int);
                        tps[i++].multiset = true;
diff --git a/sql/server/rel_basetable.c b/sql/server/rel_basetable.c
--- a/sql/server/rel_basetable.c
+++ b/sql/server/rel_basetable.c
@@ -149,6 +149,44 @@ rel_base_use_all( mvc *sql, sql_rel *rel
        }
 }
 
+
+static node *
+rel_nested_basetable_add_vector_cols(mvc *sql, rel_base_t *ba, sql_column *c, 
node *cn, list *exps)
+{
+       sql_alias *atname = a_create(sql->sa, c->base.name);
+       atname->parent = ba->name;
+       int i = sql->nid;
+       prop *p = NULL;
+       sql_exp *e = NULL;
+
+       unsigned int ncols = c->type.digits;
+       sql->nid += ncols;
+       for (unsigned int k = 0; k < ncols; k++, i++) {
+               sql_column *c = cn->data;
+               if (!column_privs(sql, c, PRIV_SELECT))
+                       continue;
+               e = exp_alias(sql, atname, c->base.name, atname, c->base.name, 
&c->type, CARD_MULTI, c->null, is_column_unique(c), 1);
+               if (e == NULL)
+                       return NULL;
+               e->nid = -(i);
+               e->alias.label = e->nid;
+               if (c->t->pkey && ((sql_kc*)c->t->pkey->k.columns->h->data)->c 
== c) {
+                       p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p);
+                       p->value.pval = c->t->pkey;
+               } else if (c->unique == 2) {
+                       p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p);
+                       p->value.pval = NULL;
+               }
+               set_intern(e);
+               set_basecol(e);
+               sql_column_get_statistics(sql, c, e);
+               append(exps, e);
+               cn = cn->next;
+       }
+       return cn;
+
+}
+
 static rel_base_t* rel_nested_basetable_add_cols(mvc *sql, rel_base_t *pba, 
char *colname, sql_table *t, list *exps);
 
 static node *
@@ -304,7 +342,14 @@ rel_nested_basetable(mvc *sql, sql_table
                sql_column *c = cn->data;
                if (!column_privs(sql, c, PRIV_SELECT))
                        continue;
-               if (c->type.multiset) {
+               if (c->type.multiset == MS_VECTOR) {
+                       e = exp_alias(sql, atname, c->base.name, atname, 
c->base.name, &c->type, CARD_MULTI, c->null, is_column_unique(c), 0);
+                       if (e)
+                               e->f = sa_list(sql->sa);
+                       if (!e || !e->f)
+                               return NULL;
+                       cn = rel_nested_basetable_add_vector_cols(sql, ba, c, 
cn->next, e->f);
+               } else if (c->type.multiset) {
                        e = exp_alias(sql, atname, c->base.name, atname, 
c->base.name, &c->type, CARD_MULTI, c->null, is_column_unique(c), 0);
                        prop *p = p = prop_create(sql->sa, PROP_NESTED, e->p);
                        p->value.pval = c;
diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -3955,6 +3955,28 @@ exp_check_composite_type(mvc *sql, sql_s
 }
 
 static sql_exp *
+exp_check_vector_type(mvc *sql, sql_subtype *t, sql_rel *rel, sql_exp *exp, 
check_type tpe)
+{
+       assert(t->multiset == MS_VECTOR);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to