Changeset: 35e721177c7a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=35e721177c7a
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_rank.c
sql/common/sql_types.c
sql/server/rel_select.c
Branch: default
Log Message:
fixes some issues with window functions which need a input column, just
because they need to know the input size, for those we now have a internal
(virtual) function 'star'. Also fixed some small issues with the window
functions.
diffs (96 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
@@ -781,7 +781,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l
}
}
assert(!e->r);
- if (exps) {
+ if (strcmp(sql_func_mod(f->func), "") == 0 &&
strcmp(sql_func_imp(f->func), "") == 0 && strcmp(f->func->base.name, "star") ==
0)
+ return left->op4.lval->h->data;
+ else if (exps) {
unsigned nrcols = 0;
int single_value = (fe->card <= CARD_ATOM);
int push_cond_exec = 0, coalesce = 0;
@@ -812,10 +814,10 @@ exp_bin(backend *be, sql_exp *e, stmt *l
if (rows && en == exps->h && f->func->type !=
F_LOADER)
es = stmt_const(be, rows, es);
else if (f->func->type == F_ANALYTIC &&
es->nrcols == 0) {
- if (en == exps->h)
+ if (en == exps->h && left->nrcols)
es = stmt_const(be,
bin_first_column(be, left), es); /* ensure the first argument is a column */
if (!f->func->s &&
!strcmp(f->func->base.name, "window_bound")
- && exps->h->next &&
list_length(f->func->ops) == 6 && en == exps->h->next)
+ && exps->h->next &&
list_length(f->func->ops) == 6 && en == exps->h->next && left->nrcols)
es = stmt_const(be,
bin_first_column(be, left), es);
}
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
@@ -5988,7 +5988,7 @@ static mel_func sql_init_funcs[] = {
pattern("batsql", "first_value", SQLfirst_value, false, "return the first
value of groups", args(1,4,
batargany("",1),batargany("b",1),batarg("s",lng),batarg("e",lng))),
pattern("sql", "last_value", SQLlast_value, false, "return the last value of
groups", args(1,4, argany("",1),argany("b",1),arg("s",lng),arg("e",lng))),
pattern("batsql", "last_value", SQLlast_value, false, "return the last value
of groups", args(1,4,
batargany("",1),batargany("b",1),batarg("s",lng),batarg("e",lng))),
- pattern("sql", "nth_value", SQLnth_value, false, "return the nth value of
each group", args(1,5,
argany("",1),argany("b",1),argany("n",2),arg("s",lng),arg("e",lng))),
+ pattern("sql", "nth_value", SQLnth_value, false, "return the nth value of
each group", args(1,5,
argany("",1),argany("b",1),argany("n",1),arg("s",lng),arg("e",lng))),
pattern("batsql", "nth_value", SQLnth_value, false, "return the nth value of
each group", args(1,5,
batargany("",1),batargany("b",1),argany("n",2),batarg("s",lng),batarg("e",lng))),
pattern("batsql", "nth_value", SQLnth_value, false, "return the nth value of
each group", args(1,5,
batargany("",1),argany("b",1),batargany("n",2),arg("s",lng),arg("e",lng))),
pattern("batsql", "nth_value", SQLnth_value, false, "return the nth value of
each group", args(1,5,
batargany("",1),batargany("b",1),batargany("n",2),batarg("s",lng),batarg("e",lng))),
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
@@ -1922,7 +1922,7 @@ SQLstrgroup_concat(Client cntxt, MalBlkP
str *res = (str*) getArgReference(stk, pci, 0);
str in = *getArgReference_str(stk, pci, 1);
- if (pci->argc == 4) {
+ if (pci->argc == 5) {
str sep = *getArgReference_str(stk, pci, 2);
size_t l1 = strNil(in) ? 0 : strlen(in), l2 =
strNil(sep) ? 0 : strlen(sep);
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -1293,6 +1293,8 @@ sqltypeinit( sql_allocator *sa)
/* nullif and coalesce don't have a backend implementation */
sql_create_func(sa, "nullif", "", "", TRUE, FALSE, SCALE_FIX, 0, ANY,
2, ANY, ANY);
sql_create_func(sa, "coalesce", "", "", TRUE, FALSE, SCALE_FIX, 0, ANY,
2, ANY, ANY);
+ /* needed for count(*) and window functions without input col */
+ sql_create_func(sa, "star", "", "", TRUE, FALSE, SCALE_FIX, 0, ANY, 0);
/* sum for numerical and decimals */
sql_create_aggr(sa, "sum", "aggr", "sum", FALSE, LargestINT, 1, BTE);
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
@@ -4745,12 +4745,9 @@ rel_rankop(sql_query *query, sql_rel **r
distinct = dn->next->data.i_val;
if (extra_input) { /* pass an input column for analytic
functions that don't require it */
- in = rel_first_column(sql, p);
- if (!in)
- return NULL;
- in = exp_ref(sql, in);
+ sql_subfunc *star = sql_bind_func(sql->sa, s, "star",
NULL, NULL, F_FUNC);
+ in = exp_op(sql->sa, NULL, star);
append(fargs, in);
- in = exp_ref_save(sql, in);
}
if (dl)
for (dargs = dl->h ; dargs ; dargs = dargs->next) {
@@ -4829,12 +4826,10 @@ rel_rankop(sql_query *query, sql_rel **r
GDKfree(uaname);
return NULL;
}
-
- in = rel_first_column(sql, p);
- in = exp_ref(sql, in);
+ sql_subfunc *star = sql_bind_func(sql->sa, s, "star",
NULL, NULL, F_FUNC);
+ in = exp_op(sql->sa, NULL, star);
append(fargs, in);
append(fargs, exp_atom_bool(sql->sa, 0)); /* don't
ignore nills */
- in = exp_ref_save(sql, in);
}
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list