Changeset: 43e7f25b6ab1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=43e7f25b6ab1
Added Files:
sql/test/miscellaneous/Tests/alter_table_add_column.sql
sql/test/miscellaneous/Tests/alter_table_add_column.stable.err
sql/test/miscellaneous/Tests/alter_table_add_column.stable.out
sql/test/subquery/Tests/subquery3.stable.err
sql/test/subquery/Tests/subquery3.stable.out
Modified Files:
clients/R/Tests/dbi.stable.err
gdk/gdk_analytic_func.c
sql/backends/monet5/sql_rank.c
sql/backends/monet5/sql_upgrades.c
sql/server/rel_exp.c
sql/server/rel_select.c
sql/server/rel_unnest.c
sql/storage/store.c
sql/test/analytics/Tests/analytics01.sql
sql/test/analytics/Tests/analytics01.stable.out
sql/test/miscellaneous/Tests/All
sql/test/subquery/Tests/subquery3.sql
Branch: default
Log Message:
Merge with Nov2019
diffs (truncated from 2512 to 300 lines):
diff --git a/clients/R/Tests/dbi.stable.err b/clients/R/Tests/dbi.stable.err
--- a/clients/R/Tests/dbi.stable.err
+++ b/clients/R/Tests/dbi.stable.err
@@ -30,8 +30,6 @@ stderr of test 'dbi` in directory 'clien
# 12:27:25 > "R" "--vanilla" "--slave" "--args" "31728"
# 12:27:25 >
-Warning message:
-S3 methods ‘[.fun_list’, ‘[.grouped_df’, ‘all.equal.tbl_df’,
‘anti_join.data.frame’, ‘anti_join.tbl_df’, ‘arrange.data.frame’,
‘arrange.default’, ‘arrange.grouped_df’, ‘arrange.tbl_df’,
‘arrange_.data.frame’, ‘arrange_.tbl_df’, ‘as.data.frame.grouped_df’,
‘as.data.frame.rowwise_df’, ‘as.data.frame.tbl_cube’, ‘as.table.tbl_cube’,
‘as.tbl.data.frame’, ‘as.tbl.tbl’, ‘as.tbl_cube.array’,
‘as.tbl_cube.data.frame’, ‘as.tbl_cube.matrix’, ‘as.tbl_cube.table’,
‘as_tibble.grouped_df’, ‘as_tibble.tbl_cube’, ‘auto_copy.tbl_cube’,
‘auto_copy.tbl_df’, ‘cbind.grouped_df’, ‘collapse.data.frame’,
‘collect.data.frame’, ‘common_by.NULL’, ‘common_by.character’,
‘common_by.default’, ‘common_by.list’, ‘compute.data.frame’,
‘copy_to.DBIConnection’, ‘copy_to.src_local’, ‘default_missing.data.frame’,
‘default_missing.default’, ‘dim.tbl_cube’, ‘distinct.data.f [... truncated]
Identifier(s) "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width",
"Species" contain uppercase or reserved SQL characters and need(s) to be quoted
in queries.
Warning message:
'MonetDBLite::isIdCurrent' is deprecated.
diff --git a/gdk/gdk_analytic_func.c b/gdk/gdk_analytic_func.c
--- a/gdk/gdk_analytic_func.c
+++ b/gdk/gdk_analytic_func.c
@@ -585,7 +585,7 @@ GDKanalyticalnthvalue(BAT *r, BAT *b, BA
#define ANALYTICAL_LAG_IMP(TPE)
\
do { \
- TPE *rp, *rb, *bp, *rend, \
+ TPE *rp, *rb, *bp, *nbp, *rend, \
def = *((TPE *) default_value), next; \
bp = (TPE*)Tloc(b, 0); \
rb = rp = (TPE*)Tloc(r, 0); \
@@ -601,8 +601,9 @@ GDKanalyticalnthvalue(BAT *r, BAT *b, BA
if (*np) { \
ncnt = (np - pnp); \
rp += ncnt; \
+ nbp = bp + ncnt; \
ANALYTICAL_LAG_CALC(TPE); \
- bp += (lag < ncnt) ? lag : 0; \
+ bp = nbp; \
pnp = np; \
} \
} \
diff --git a/sql/backends/monet5/sql_rank.c b/sql/backends/monet5/sql_rank.c
--- a/sql/backends/monet5/sql_rank.c
+++ b/sql/backends/monet5/sql_rank.c
@@ -996,19 +996,25 @@ SQLnth_value(Client cntxt, MalBlkPtr mb,
return MAL_SUCCEED;
}
-#define CHECK_L_VALUE(TPE)
\
- do {
\
- TPE rval = *getArgReference_##TPE(stk, pci, 2);
\
- l_value = is_##TPE##_nil(rval) ? BUN_NONE : (rval > 0 ?
(BUN)rval : (BUN)(-1 * rval)); \
+#define CHECK_L_VALUE(TPE) \
+ do { \
+ TPE rval = *getArgReference_##TPE(stk, pci, 2); \
+ if (!is_##TPE##_nil(rval) && rval < 0) { \
+ gdk_call = dual; \
+ rval *= -1; \
+ } \
+ l_value = is_##TPE##_nil(rval) ? BUN_NONE : (BUN)rval; \
} while(0);
-static str /* the variable m is used to fix the multiplier */
+static str
do_lead_lag(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, const
char* op, const char* desc,
- gdk_return (*func)(BAT *, BAT *, BAT *, BUN, const
void* restrict, int))
+ gdk_return (*func)(BAT *, BAT *, BAT *, BUN, const
void* restrict, int),
+ gdk_return (*dual)(BAT *, BAT *, BAT *, BUN, const
void* restrict, int))
{
int tp1, tp2, tp3, base = 2;
BUN l_value = 1;
const void *restrict default_value;
+ gdk_return (*gdk_call)(BAT *, BAT *, BAT *, BUN, const void* restrict,
int) = func;
(void)cntxt;
if (pci->argc < 4 || pci->argc > 6)
@@ -1079,11 +1085,11 @@ do_lead_lag(Client cntxt, MalBlkPtr mb,
}
}
- gdk_code = func(r, b, p, l_value, default_value, tp1);
+ gdk_code = gdk_call(r, b, p, l_value, default_value, tp1);
BATsetcount(r, cnt);
BBPunfix(b->batCacheid);
- if(gdk_code == GDK_SUCCEED)
+ if (gdk_code == GDK_SUCCEED)
BBPkeepref(*res = r->batCacheid);
else
throw(SQL, op, GDK_EXCEPTION);
@@ -1103,13 +1109,13 @@ do_lead_lag(Client cntxt, MalBlkPtr mb,
str
SQLlag(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- return do_lead_lag(cntxt, mb, stk, pci, "sql.lag", "lag",
GDKanalyticallag);
+ return do_lead_lag(cntxt, mb, stk, pci, "sql.lag", "lag",
GDKanalyticallag, GDKanalyticallead);
}
str
SQLlead(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- return do_lead_lag(cntxt, mb, stk, pci, "sql.lead", "lead",
GDKanalyticallead);
+ return do_lead_lag(cntxt, mb, stk, pci, "sql.lead", "lead",
GDKanalyticallead, GDKanalyticallag);
}
/* we will keep the ordering bat here although is not needed, but maybe later
with varied sized windows */
diff --git a/sql/backends/monet5/sql_upgrades.c
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -2068,6 +2068,13 @@ sql_update_nov2019(Client c, mvc *sql, c
"update sys.functions set system = true where schema_id
= (select id from sys.schemas where name = 'wlr')"
" and name in ('master', 'stop', 'accept', 'replicate',
'beat') and type = %d;\n", (int) F_PROC);
+ /* Fix alter table drop column, missing column number update issue
+ pos += snprintf(buf + pos, bufsize - pos,
+ "update \"_columns\" set \"number\" = ("
+ "select \"rid\" from (select \"id\", row_number() over
(partition by \"table_id\" order by \"id\") - 1 as \"rid\" from \"_columns\")
as \"rids\""
+ " where rids.\"id\" = \"_columns\".\"id\")"
+ " where \"table_id\" in (select \"table_id\" from
\"_columns\" group by \"table_id\", \"number\" having count(*) > 1);\n"); */
+
pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n",
prev_schema);
pos += snprintf(buf + pos, bufsize - pos, "commit;\n");
assert(pos < bufsize);
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
@@ -908,7 +908,7 @@ exps_find_exp( list *l, sql_exp *e)
return NULL;
for(n=l->h; n; n = n->next) {
- if (exp_match(n->data, e))
+ if (exp_match(n->data, e) || exp_refers(n->data, e))
return n->data;
}
return NULL;
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -122,6 +122,8 @@ rel_bound_exp(mvc *sql, sql_rel *rel )
for(n = rel->exps->h; n; n = n->next){
sql_exp *e = n->data;
+ if (exp_is_atom(e))
+ return e;
if (!is_freevar(e))
return exp_ref(sql->sa, e);
}
@@ -1792,6 +1794,9 @@ rel_compare(sql_query *query, sql_rel *r
ls = rel_value_exp(query, &rel, lo, f, ek);
if (!ls)
return NULL;
+ if (ls && rel && exp_has_freevar(sql, ls) && (is_sql_sel(f) ||
is_sql_having(f))) {
+ ls = rel_project_add_exp(sql, rel, ls);
+ }
if (ro->token != SQL_SELECT) {
rs = rel_value_exp(query, &rel, ro, f, ek);
if (ro2) {
@@ -3821,6 +3826,22 @@ rel_check_card(sql_rel *rel, sql_exp *l
return 0;
}
+static sql_rel *
+rel_find_groupby(sql_rel *groupby)
+{
+ if (groupby && !is_processed(groupby) && !is_base(groupby->op)) {
+ while(!is_processed(groupby) && !is_base(groupby->op)) {
+ if (groupby->op == op_groupby || !groupby->l)
+ break;
+ if (groupby->l)
+ groupby = groupby->l;
+ }
+ if (groupby && groupby->op == op_groupby)
+ return groupby;
+ }
+ return NULL;
+}
+
static sql_exp *
rel_binop(sql_query *query, sql_rel **rel, symbol *se, int f, exp_kind ek)
{
@@ -3843,6 +3864,11 @@ rel_binop(sql_query *query, sql_rel **re
l = rel_value_exp(query, rel, dl->next->data.sym, f, iek);
r = rel_value_exp(query, rel, dl->next->next->data.sym, f, iek);
+ if (l && *rel && exp_card(l) > CARD_AGGR && rel_find_groupby(*rel)) {
+ /* TODO fix error */
+ return NULL;
+ }
+
if (!l || !r) {
*rel = orel;
sf = find_func(sql, s, fname, 2, F_AGGR, NULL);
@@ -3861,7 +3887,6 @@ rel_binop(sql_query *query, sql_rel **re
sql->errstr[0] = '\0';
return rel_aggr(query, rel, se, f);
}
-
if (type == F_FUNC) {
sf = find_func(sql, s, fname, 2, F_AGGR, NULL);
if (sf) {
@@ -4014,18 +4039,10 @@ rel_aggr_intern(sql_query *query, sql_re
/* find groupby */
if (groupby && !is_processed(groupby) && !is_base(groupby->op)) {
og = groupby;
- while(!is_processed(groupby) && !is_base(groupby->op)) {
- if (groupby->op == op_groupby || !groupby->l)
- break;
- if (groupby->l)
- groupby = groupby->l;
- }
- if (groupby && groupby->op == op_groupby) {
+ groupby = rel_find_groupby(groupby);
+ if (groupby)
group = 1;
- /* At the end we switch back to the old projection
relation og.
- * During the partitioning and ordering we add the
expressions to the intermediate relations. */
- }
- if (!group)
+ else
groupby = og;
}
@@ -5008,13 +5025,13 @@ rel_order_by(sql_query *query, sql_rel *
if (e)
e = rel_project_add_exp(sql, rel, e);
}
- if (!e && sql->session->status != -ERR_AMBIGUOUS) {
+ if (rel && !e && sql->session->status !=
-ERR_AMBIGUOUS) {
/* reset error */
sql->session->status = 0;
sql->errstr[0] = '\0';
/* check for project->select->groupby */
- if (is_project(rel->op) && is_sql_orderby(f)) {
+ if (rel && is_project(rel->op) &&
is_sql_orderby(f)) {
sql_rel *s = rel->l;
sql_rel *p = rel;
sql_rel *g = s;
@@ -5460,8 +5477,12 @@ rel_rankop(sql_query *query, sql_rel **r
for(n = obe->h ; n ; n = n->next) {
sql_exp *oexp = n->data, *nexp;
- if (is_sql_sel(f) && pp->op == op_project &&
!is_processed(pp) && !rel_find_exp(pp, oexp))
+ if (is_sql_sel(f) && pp->op == op_project &&
!is_processed(pp) && !rel_find_exp(pp, oexp)) {
append(pp->exps, oexp);
+ if (!exp_name(oexp))
+ exp_label(sql->sa, oexp, ++sql->label);
+ oexp = exp_ref(sql->sa, oexp);
+ }
n->data = nexp = opt_groupby_add_exp(sql, p,
group?g:pp, oexp);
if (is_ascending(oexp))
set_direction(nexp, 1);
@@ -5772,7 +5793,7 @@ rel_rankop(sql_query *query, sql_rel **r
call = exp_op(sql->sa, args, wf);
exp_label(sql->sa, call, ++sql->label);
r->l = p;
- list_merge(p->exps, rel_projections(sql, p->l, NULL, 1, 1), NULL);
+ p->exps = list_merge(p->exps, rel_projections(sql, p->l, NULL, 1, 1),
NULL);
append(p->exps, call);
call = exp_ref(sql->sa, call);
if (project_added) {
diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c
--- a/sql/server/rel_unnest.c
+++ b/sql/server/rel_unnest.c
@@ -447,7 +447,19 @@ push_up_project(mvc *sql, sql_rel *rel)
}
append(n->exps, e);
}
- assert(!r->r);
+ if (r->r) {
+ list *exps = r->r, *oexps = n->r =
sa_list(sql->sa);
+
+ for (m=exps->h; m; m = m->next) {
+ sql_exp *e = m->data;
+
+ if (!e->freevar || exp_name(e)) { /*
only skip full freevars */
+ if (exp_has_freevar(sql, e))
+ rel_bind_var(sql,
rel->l, e);
+ }
+ append(oexps, e);
+ }
+ }
/* remove old project */
rel->r = r->l;
r->l = NULL;
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -5887,8 +5887,28 @@ sql_trans_rename_column(sql_trans *tr, s
int
sql_trans_drop_column(sql_trans *tr, sql_table *t, sqlid id, int drop_action)
{
- node *n = list_find_base_id(t->columns.set, id);
- sql_column *col = n->data;
+ node *n = NULL;
+ sql_table *syscolumn = find_sql_table(find_sql_schema(tr, "sys"),
"_columns");
+ sql_column *col = NULL, *cid = find_sql_column(syscolumn, "id"), *cnr =
find_sql_column(syscolumn, "number");
+
+ for (node *nn = t->columns.set->h ; nn ; nn = nn->next) {
+ sql_column *next = (sql_column *) nn->data;
+ if (next->base.id == id) {
+ n = nn;
+ col = next;
+ } else if (col) { /* if the column to be dropped was found,
decrease the column number for others after it */
+ oid rid;
+ next->colnr--;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list