Changeset: 9549c3a1ab79 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/9549c3a1ab79 Branch: newjson Log Message:
merge with nested diffs (283 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 @@ -2478,7 +2478,7 @@ rel2bin_basetable(backend *be, sql_rel * } else { sql_column *c = find_sql_column(t, oname); - if (c->type.multiset || c->type.type->composite) + if (!c || c->type.multiset || c->type.type->composite) continue; fcol = c; col = stmt_col(be, c, multiset?dels:NULL, dels->partition); @@ -4876,9 +4876,11 @@ rel2bin_project(backend *be, sql_rel *re return NULL; for (en = rel->exps->h; en; en = en->next) { sql_exp *exp = en->data; + /* we need to ouput composite properly, for insert statements sql_subtype *st = exp_subtype(exp); - if (st && st->type->composite) + if (rel->l && st && st->type->composite) continue; + */ int oldvtop = be->mb->vtop, oldstop = be->mb->stop; stmt *s = exp_bin(be, exp, sub, NULL /*psub*/, NULL, NULL, NULL, NULL, 0, 0, 0); @@ -5875,8 +5877,8 @@ rel2bin_insert(backend *be, sql_rel *rel if (!sql_insert_triggers(be, t, updates, 0)) return sql_error(sql, 10, SQLSTATE(27000) "INSERT INTO: triggers failed for table '%s'", t->base.name); - insert = inserts->op4.lval->h->data; - if (insert->nrcols == 0) { + insert = inserts->op4.lval->h?inserts->op4.lval->h->data:NULL; + if (!insert || insert->nrcols == 0) { cnt = stmt_atom_lng(be, 1); } else { cnt = stmt_aggr(be, insert, NULL, NULL, sql_bind_func(sql, "sys", "count", sql_bind_localtype("void"), NULL, F_AGGR, true, true), 1, 0, 1); diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -1046,7 +1046,7 @@ mvc_renumber_bulk(Client cntxt, MalBlkPt if (!bo->tsorted || !BATtkey(bo) || (bcnt && (oi[0] + (int)(bcnt-1)) != oi[bcnt-1]) ) { BAT *lo = NULL; printf("not dense %d\n", oi[0]); - if (BATleftjoin(&lo, NULL, i, bo, NULL, NULL, false, cnt) != GDK_SUCCEED) { + if (BATleftjoin(&lo, NULL, bo, i, NULL, NULL, false, cnt) != GDK_SUCCEED) { BBPreclaim(i); BBPreclaim(bo); BBPreclaim(bn); 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 @@ -3296,7 +3296,7 @@ dump_header(mvc *sql, MalBlkPtr mb, list stmt *c = n->data; sql_subtype *t = tail_type(c); if (t->multiset) { /* properly handle subtable */ - printf("multiset\n"); + printf("%multiset\n"); } sql_alias *tname = table_name(sql->sa, c); const char *_empty = ""; 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 @@ -3712,7 +3712,7 @@ exp_check_composite_type(mvc *sql, sql_s static sql_exp * exp_check_multiset_type(mvc *sql, sql_subtype *t, sql_rel *rel, sql_exp *exp, check_type tpe) { - assert(t->type->composite); + assert(t->type->composite || t->multiset); if (!exp_is_rel(exp) && !is_values(exp)) { sql_subtype *et = exp_subtype(exp); /* hard code conversion from json allowed */ @@ -3720,7 +3720,9 @@ exp_check_multiset_type(mvc *sql, sql_su return exp_convert(sql, exp, et, t); if (et && et->multiset == t->multiset && subtype_cmp(et, t) == 0) return exp; - return sql_error( sql, 03, SQLSTATE(42000) "cannot convert value into composite type '%s'", t->type->base.name); + if (t->type->composite) + return sql_error( sql, 03, SQLSTATE(42000) "cannot convert value into composite type '%s'", t->type->base.name); + return sql_error( sql, 03, SQLSTATE(42000) "cannot convert value into multiset type '%s[]'", t->type->base.name); } list *msvals = NULL; @@ -3757,7 +3759,7 @@ exp_check_type(mvc *sql, sql_subtype *t, sql_exp* nexp = NULL; sql_subtype *fromtype = exp_subtype(exp); - if (t->type->composite) { + if (t->type->composite || t->multiset) { if (t->multiset || !is_row(exp)) return exp_check_multiset_type(sql, t, rel, exp, tpe); return exp_check_composite_type(sql, t, rel, exp, tpe); diff --git a/sql/server/rel_multiset.c b/sql/server/rel_multiset.c --- a/sql/server/rel_multiset.c +++ b/sql/server/rel_multiset.c @@ -244,30 +244,39 @@ fm_project_ms(visitor *v, sql_exp *e, sq e = exp_ref(v->sql, e); sql_exp *mse = exp_column(v->sql->sa, cn, "rowid", inttype, 1,1, 1, 1); mse->alias.label = (++label); - mse->nid = e->alias.label; + mse->nid = mse->alias.label; append(nexps, mse); - for(node *f = t->type->d.fields->h; f; f = f->next) { - sql_arg *field = f->data; + if (t->type->composite) { + for(node *f = t->type->d.fields->h; f; f = f->next) { + sql_arg *field = f->data; - if (field->type.multiset) { - sql_alias *nn = a_create(v->sql->sa, field->name); - nn->parent = cn; - fm_project_ms(v, e, &field->type, nn, nexps); - } else { - mse = exp_column(v->sql->sa, cn, field->name, &field->type, 1,1, 1, 1); - mse->alias.label = (++label); - mse->nid = e->alias.label; - append(nexps, mse); + if (field->type.multiset) { + sql_alias *nn = a_create(v->sql->sa, field->name); + nn->parent = cn; + fm_project_ms(v, e, &field->type, nn, nexps); + } else { + mse = exp_column(v->sql->sa, cn, field->name, &field->type, 1,1, 1, 1); + mse->alias.label = (++label); + mse->nid = mse->alias.label; + append(nexps, mse); + } } + } else { + sql_subtype lt = *t; + lt.multiset = MS_VALUE; + mse = exp_column(v->sql->sa, cn, "elements", <, 1,1, 1, 1); + mse->alias.label = (++label); + mse->nid = mse->alias.label; + append(nexps, mse); } mse = exp_column(v->sql->sa, cn, "multisetid", inttype, 1,1, 1, 1); mse->alias.label = (++label); - mse->nid = e->alias.label; + mse->nid = mse->alias.label; append(nexps, mse); if (t->multiset == MS_ARRAY) { mse = exp_column(v->sql->sa, cn, "multisetnr", inttype, 1,1, 1, 1); mse->alias.label = (++label); - mse->nid = e->alias.label; + mse->nid = mse->alias.label; append(nexps, mse); } } @@ -317,7 +326,7 @@ fm_project(visitor *v, sql_rel *rel) } } else if (rel->l && rel->exps) { /* check for type multiset, expand the column list for the content columns */ bool needed = false; - for(node *n = rel->exps->h; n; n = n->next) { + for(node *n = rel->exps->h; n && !needed; n = n->next) { sql_exp *e = n->data; sql_subtype *t = exp_subtype(e); needed = (t && t->multiset); @@ -336,26 +345,33 @@ fm_project(visitor *v, sql_rel *rel) sql_exp *e = n->data; sql_subtype *t = exp_subtype(e); if (t->multiset) { + sql_alias *cn = a_create(v->sql->sa, e->alias.name); sql_exp *rowid = exps_bind_column(exps, exp_name(e), NULL, NULL, 0); if (!rowid) - rowid = exps_bind_column(exps, "rowid", NULL, NULL, 0); + rowid = exps_bind_column2(exps, cn, "rowid", NULL); rowid = exp_ref(v->sql, rowid); append(nexps, rowid); - for(node *f = t->type->d.fields->h; f; f = f->next) { - sql_arg *field = f->data; - sql_exp *mse = exps_bind_column(exps, field->name, NULL, NULL, 0); + if (t->type->composite) { + for(node *f = t->type->d.fields->h; f; f = f->next) { + sql_arg *field = f->data; + sql_exp *mse = exps_bind_column2(exps, cn, field->name, NULL); + mse = exp_ref(v->sql, mse); + append(nexps, mse); + } + } else { + sql_exp *mse = exps_bind_column2(exps, cn, "elements", NULL); mse = exp_ref(v->sql, mse); append(nexps, mse); } - sql_exp *msid = exps_bind_column(exps, "id", NULL, NULL, 0); + sql_exp *msid = exps_bind_column2(exps, cn, "id", NULL); if (!msid) - msid = exps_bind_column(exps, "multisetid", NULL, NULL, 0); + msid = exps_bind_column2(exps, cn, "multisetid", NULL); msid = exp_ref(v->sql, msid); append(nexps, msid); if (t->multiset == MS_ARRAY) { - sql_exp *msnr = exps_bind_column(exps, "nr", NULL, NULL, 0); + sql_exp *msnr = exps_bind_column2(exps, cn, "nr", NULL); if (!msnr) - msnr = exps_bind_column(exps, "multisetnr", NULL, NULL, 0); + msnr = exps_bind_column2(exps, cn, "multisetnr", NULL); msnr = exp_ref(v->sql, msnr); append(nexps, msnr); } diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -3824,24 +3824,32 @@ sql_trans_create_column_intern(sql_colum if (col->type.type->composite) t->composite=true; - if (tpe->type->composite) { + if (tpe->type->composite || tpe->multiset) { needs_data = false; sql_table *tt = t; if (tpe->multiset) { char buf[16]; snprintf(buf, 16, "%%ms_%d", col->base.id); col->storage_type = _STRDUP(buf); - if ((res = sql_trans_create_table(&tt, tr, t->s, col->storage_type, NULL, tt_table, true, t->persistence, 0, 0, 0)) != LOG_OK) + if ((res = sql_trans_create_table(&tt, tr, t->s, col->storage_type, NULL, tt_table, true, t->persistence, t->commit_action, 0, 0)) != LOG_OK) return res; if (sql_trans_create_sequence(tr, t->s, col->storage_type, 1, 1, GDK_lng_max, 1, 1, false, true) != LOG_OK) return res; } - /* All nested types, need the internal columns for the field contents */ - for (node *n = col->type.type->d.fields->h; n; n = n->next) { - sql_arg *f = n->data; + if (tpe->type->composite) { + /* All nested types, need the internal columns for the field contents */ + for (node *n = col->type.type->d.fields->h; n; n = n->next) { + sql_arg *f = n->data; + sql_column *ic = NULL; + /* how to store names (list) ? */ + if (sql_trans_create_column_intern( &ic, tr, tt, f->name, &f->type, column_intern) < 0) + return -2; + } + } else { sql_column *ic = NULL; - /* how to store names (list) ? */ - if (sql_trans_create_column_intern( &ic, tr, tt, f->name, &f->type, column_intern) < 0) + sql_subtype lt = *tpe; + lt.multiset = MS_VALUE; + if (sql_trans_create_column_intern( &ic, tr, tt, "elements", <, column_intern) < 0) return -2; } if (tpe->multiset == MS_SETOF || tpe->multiset == MS_ARRAY) { /* sets and arrays need oid col */ @@ -3935,24 +3943,32 @@ sql_trans_copy_column( sql_trans *tr, sq if (!isNew(t) && isGlobal(t) && !isGlobalTemp(t) && (res = sql_trans_add_dependency(tr, t->base.id, dml))) return res; - if (c->type.type->composite) { + if (c->type.type->composite || c->type.multiset) { needs_data = false; sql_table *tt = t; if (c->type.multiset) { char buf[16]; snprintf(buf, 16, "%%ms_%d", c->base.id); col->storage_type = _STRDUP(buf); - if ((res = sql_trans_create_table(&tt, tr, t->s, col->storage_type, NULL, tt_table, true, t->persistence, 0, 0, 0)) != LOG_OK) + if ((res = sql_trans_create_table(&tt, tr, t->s, col->storage_type, NULL, tt_table, true, t->persistence, t->commit_action, 0, 0)) != LOG_OK) return res; if (sql_trans_create_sequence(tr, t->s, col->storage_type, 1, 1, GDK_lng_max, 1, 1, false, true) != LOG_OK) return res; } - /* All nested types, need the internal columns for the field contents */ - for (node *n = col->type.type->d.fields->h; n; n = n->next) { - sql_arg *f = n->data; + if (c->type.type->composite) { + /* All nested types, need the internal columns for the field contents */ + for (node *n = col->type.type->d.fields->h; n; n = n->next) { + sql_arg *f = n->data; + sql_column *ic = NULL; + /* how to store names (list) ? */ + if (sql_trans_create_column_intern( &ic, tr, tt, f->name, &f->type, column_intern) < 0) + return -2; + } + } else { sql_column *ic = NULL; - /* how to store names (list) ? */ - if (sql_trans_create_column_intern( &ic, tr, tt, f->name, &f->type, column_intern) < 0) + sql_subtype lt = c->type; + lt.multiset = MS_VALUE; + if (sql_trans_create_column_intern( &ic, tr, tt, "elements", <, column_intern) < 0) return -2; } if (c->type.multiset == MS_SETOF || c->type.multiset == MS_ARRAY) { /* sets and arrays need oid col */ _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org