Changeset: 8973901f9bea for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8973901f9bea
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/rel_tvtree.c
sql/backends/monet5/rel_tvtree.h
sql/server/rel_exp.c
sql/server/sql_parser.y
sql/server/sql_scan.c
sql/storage/store.c
Branch: nested
Log Message:
insert of vector type poc
diffs (229 lines):
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
@@ -6174,8 +6174,8 @@ insert_ms(backend *be, sql_table *st, sq
pos = stmt_claim(be, st, cnt);
int mvc_var = be->mvc_var;
- stmt *rowids = m->data;
stmt *msid = updates[len-1 -((ct->multiset == MS_ARRAY)?1:0)];
+ stmt *rowids = m ? m->data : msid;
/* nrowids = next_value_for(rowids, "schema?", st->base.name) */
InstrPtr r = newStmt(be->mb, batsqlRef, "next_value_ms");
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
@@ -23,6 +23,8 @@ tv_get_type(sql_subtype *st)
if (st->multiset) {
if (st->multiset == MS_ARRAY)
return TV_MSET;
+ if (st->multiset == MS_VECTOR)
+ return TV_VECTOR;
if (st->multiset == MS_SETOF)
return TV_SETOF;
} else if (st->type->composite)
@@ -41,6 +43,7 @@ tv_node(allocator *sa, sql_subtype *st,
n->tvt = tvt;
n->rid_idx = 0;
n->ctl = n->rid = n->msid = n->msnr = n->vals = NULL;
+ tv_tree *sn = NULL;
/* allocate only the lists that we need based on the tv-tree type */
switch (n->tvt) {
@@ -54,6 +57,14 @@ tv_node(allocator *sa, sql_subtype *st,
append(n->ctl, tv_node(sa, &sfa->type,
tv_get_type(&sfa->type)));
}
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);
+ return n;
case TV_MSET:
n->msnr = sa_list(sa);
/* fall through */
@@ -65,7 +76,6 @@ tv_node(allocator *sa, sql_subtype *st,
/* For MSET/SETOF we make a new child node for the
values
* NOTE: the ->st of the child is the same as this node
so
* we need to **EXPLICITLY** specify the tv_type */
- tv_tree *sn;
if (st->type->composite)
sn = tv_node(sa, st, TV_COMP);
else
@@ -251,6 +261,7 @@ 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;
@@ -306,7 +317,7 @@ tv_parse_values(backend *be, tv_tree *t,
*/
bool single_row_val = false;
single_row_val |= col_vals->row;
- if ((t->tvt == TV_MSET) || (t->tvt == TV_SETOF)) {
+ if ((t->tvt == TV_MSET) || (t->tvt == TV_SETOF) || (t->tvt ==
TV_VECTOR)) {
// single value MSET/SETOF of basic type
single_row_val |= !((sql_exp*)vals->h->data)->f;
// single value MSET/SETOF of composite type
@@ -334,15 +345,34 @@ tv_generate_stmts(backend *be, tv_tree *
{
stmt *ap, *tmp, *s;
list *sl;
+ tv_tree *ct = NULL;
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) */
assert(list_length(t->ctl) == 1);
- tv_tree *ct = t->ctl->h->data;
+ ct = t->ctl->h->data;
tmp = tv_generate_stmts(be, ct);
/* if the lower tv node does NOT returns a list (e.g.
because
diff --git a/sql/backends/monet5/rel_tvtree.h b/sql/backends/monet5/rel_tvtree.h
--- a/sql/backends/monet5/rel_tvtree.h
+++ b/sql/backends/monet5/rel_tvtree.h
@@ -36,7 +36,8 @@ typedef enum tv_type {
TV_BASIC, // basic type
TV_COMP, // composite type
TV_MSET, // multiset of composite type
- TV_SETOF // setof of composite type
+ TV_SETOF, // setof of composite type
+ TV_VECTOR
} tv_type;
typedef struct type_values_tree {
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
@@ -401,8 +401,21 @@ nested_exps(mvc *sql, sql_subtype *t, sq
append(nested, e);
}
} else {
- sql_exp *e = exp_alias(sql, atname, MSEL_NAME, atname, MSEL_NAME, t,
CARD_MULTI, true, false, 1);
- append(nested, e);
+ if (t->multiset == MS_VECTOR) {
+ uint8_t localtype = t->type->localtype;
+ sql_subtype *it = sql_fetch_localtype(localtype);
+ size_t ncols = t->digits;
+ for (size_t idx=0; idx < ncols; idx++) {
+ char *buf = ma_alloc(sql->sa, 20);
+ snprintf(buf, 20, "vec_idx_%zu", idx);
+ sql_exp *e = exp_alias(sql, atname, buf,
atname, buf, it, CARD_MULTI, true, false, 1);
+ set_intern(e);
+ append(nested, e);
+ }
+ } else {
+ sql_exp *e = exp_alias(sql, atname, MSEL_NAME, atname,
MSEL_NAME, t, CARD_MULTI, true, false, 1);
+ append(nested, e);
+ }
}
sql_subtype *it = sql_fetch_localtype(MSID_TYPE);
if (t->multiset) {
@@ -416,7 +429,7 @@ nested_exps(mvc *sql, sql_subtype *t, sq
set_intern(e);
append(nested, e);
}
- if (t->multiset) {
+ if (t->multiset && (t->multiset != MS_VECTOR)) {
sql_exp *e = exp_alias(sql, atname, "rowid", atname, "rowid",
it, CARD_MULTI, true, false, 1);
set_intern(e);
append(nested, e);
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -654,7 +654,7 @@ int yydebug=1;
%token <sval> ASYMMETRIC SYMMETRIC ORDER ORDERED BY IMPRINTS
%token <sval> ESCAPE UESCAPE HAVING sqlGROUP ROLLUP CUBE sqlNULL
%token <sval> GROUPING SETS FROM FOR MATCH
-%token <sval> SETOF ARRAY
+%token <sval> SETOF ARRAY VECTOR
%token <sval> EXTRACT
@@ -6553,9 +6553,11 @@ posint:
;
data_type:
- simple_data_type opt_array_bounds { $$ = $1; if ($2)
$$.multiset = MS_ARRAY; }
- | SETOF simple_data_type opt_array_bounds { $$ = $2;
$$.multiset = MS_SETOF; }
- | simple_data_type ARRAY '[' posint ']' { $$ = $1;
$$.multiset = MS_ARRAY; }
+ simple_data_type opt_array_bounds { $$ = $1; if ($2)
$$.multiset = MS_ARRAY;/* if ($2 &&
+$2->h->data.i_val >= 0) $$.digits = $2->h->data.i_val;*/ }
+ | SETOF simple_data_type opt_array_bounds { $$ = $2;
$$.multiset = MS_SETOF; /* ignore array size or give error ?*/ }
+ | simple_data_type ARRAY '[' posint ']' { $$ = $1;
$$.multiset = MS_ARRAY; $$.digits = $4; }
+ | simple_data_type VECTOR '[' posint ']' { $$ = $1;
$$.multiset = MS_VECTOR; $$.digits= $4; }
| SETOF simple_data_type ARRAY '[' posint ']' { $$ = $2;
$$.multiset = MS_SETOF; }
| simple_data_type ARRAY { $$ = $1;
$$.multiset = MS_ARRAY; }
| SETOF simple_data_type ARRAY { $$ = $2;
$$.multiset = MS_SETOF; }
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -661,6 +661,7 @@ scanner_init_keywords(void)
failed += keywords_insert("SETOF", SETOF);
failed += keywords_insert("ARRAY", ARRAY);
+ failed += keywords_insert("VECTOR", VECTOR);
return failed;
}
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -4194,6 +4194,20 @@ sql_trans_copy_column( sql_trans *tr, sq
if (sql_trans_create_column_intern( &ic, tr,
tt, f->name, &f->type, column_intern) < 0)
return -2;
}
+ } else if (c->type.multiset == MS_VECTOR) {
+ uint8_t localtype = c->type.type->localtype;
+ // should be flt or dbl
+ assert(localtype==TYPE_flt || localtype==TYPE_dbl);
+ size_t ncols = c->type.digits;
+ sql_subtype tp = *sql_fetch_localtype(localtype);
+ for (size_t idx=0; idx < ncols; idx++) {
+ char buf[24];
+ snprintf(buf, 24, "vec_idx_%zu", idx);
+ sql_column *ic = NULL;
+ if (sql_trans_create_column_intern( &ic, tr,
tt, buf, &tp, column_intern) < 0)
+ return -2;
+ }
+
} else {
sql_column *ic = NULL;
sql_subtype lt = c->type;
@@ -4201,7 +4215,7 @@ sql_trans_copy_column( sql_trans *tr, sq
if (sql_trans_create_column_intern( &ic, tr, tt,
MSEL_NAME, <, column_intern) < 0)
return -2;
}
- if (c->type.multiset == MS_SETOF || c->type.multiset ==
MS_ARRAY) { /* sets and arrays need oid col */
+ if (c->type.multiset > MS_VALUE) { /* sets, arrays, vectors
need oid col */
char *name = MSID_NAME;
sql_subtype tp = *sql_fetch_localtype(MSID_TYPE);
sql_column *ic = NULL;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]