Changeset: ec29946a6608 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec29946a6608
Modified Files:
sql/backends/monet5/rel_bin.c
sql/common/sql_types.c
sql/server/rel_rel.h
sql/server/rel_select.c
sql/server/rel_select.h
sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.sql
sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.err
sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.out
sql/test/emptydb-upgrade-chain-hge/Tests/package.py
sql/test/emptydb-upgrade-chain/Tests/package.py
sql/test/emptydb/Tests/package-hge.py
sql/test/emptydb/Tests/package.py
sql/test/testdb-upgrade-chain-hge/Tests/package.py
sql/test/testdb-upgrade-chain/Tests/package.py
sql/test/testdb/Tests/package-hge.py
sql/test/testdb/Tests/package.py
testing/Mtest.py.in
Branch: default
Log Message:
Merge with Nov2019
diffs (truncated from 559 to 300 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
@@ -1166,11 +1166,6 @@ check_types(backend *be, sql_subtype *ct
int c = 0;
sql_subtype *t = NULL, *st = NULL;
- /*
- if (ct->types)
- return check_table_types(sql, ct->types, s, tpe);
- */
-
st = tail_type(s);
if ((!st || !st->type) && stmt_set_type_param(sql, ct, s) == 0) {
return s;
@@ -1188,14 +1183,17 @@ check_types(backend *be, sql_subtype *ct
}
if (!t) { /* try to convert if needed */
- c = sql_type_convert(st->type->eclass, ct->type->eclass);
- if (!c || (c == 2 && tpe == type_set) ||
- (c == 3 && tpe != type_cast)) {
- s = NULL;
+ if (EC_INTERVAL(st->type->eclass) && (ct->type->eclass ==
EC_NUM || ct->type->eclass == EC_POS) && ct->digits < st->digits) {
+ s = NULL; /* conversion from interval to num depends on
the number of digits */
} else {
- s = stmt_convert(be, s, st, ct, NULL);
+ c = sql_type_convert(st->type->eclass,
ct->type->eclass);
+ if (!c || (c == 2 && tpe == type_set) || (c == 3 && tpe
!= type_cast)) {
+ s = NULL;
+ } else {
+ s = stmt_convert(be, s, st, ct, NULL);
+ }
}
- }
+ }
if (!s) {
stmt *res = sql_error(
sql, 03,
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
@@ -409,7 +409,7 @@ subtype2string(sql_subtype *t)
snprintf(buf, BUFSIZ, "%s(%u)",
t->type->sqlname, t->digits);
} else {
- snprintf(buf, BUFSIZ, "%s", t->type->sqlname);
+ snprintf(buf, BUFSIZ, "%s", t->type->sqlname);
}
return _STRDUP(buf);
}
@@ -440,7 +440,7 @@ int
subaggr_cmp( sql_subaggr *a1, sql_subaggr *a2)
{
if (a1->aggr == a2->aggr)
- return list_cmp(a1->res, a2->res, (fcmp) &subtype_cmp);
+ return list_cmp(a1->res, a2->res, (fcmp) &subtype_cmp);
return -1;
}
@@ -448,7 +448,7 @@ int
subfunc_cmp( sql_subfunc *f1, sql_subfunc *f2)
{
if (f1->func == f2->func)
- return list_cmp(f1->res, f2->res, (fcmp) &subtype_cmp);
+ return list_cmp(f1->res, f2->res, (fcmp) &subtype_cmp);
return -1;
}
@@ -460,7 +460,6 @@ arg_subtype_cmp(sql_arg *a, sql_subtype
return (is_subtype(t, &a->type )?0:-1);
}
-
static sql_subaggr *
_dup_subaggr(sql_allocator *sa, sql_func *a, sql_subtype *member)
{
@@ -507,8 +506,8 @@ sql_bind_aggr(sql_allocator *sa, sql_sch
arg = a->ops->h->data;
if (strcmp(a->base.name, sqlaname) == 0 && (!arg ||
- arg->type.type->eclass == EC_ANY ||
- (type && is_subtype(type, &arg->type ))))
+ arg->type.type->eclass == EC_ANY ||
+ (type && is_subtype(type, &arg->type ))))
return _dup_subaggr(sa, a, type);
n = n->next;
}
@@ -526,8 +525,8 @@ sql_bind_aggr(sql_allocator *sa, sql_sch
arg = a->ops->h->data;
if (strcmp(a->base.name, sqlaname) == 0 && (!arg ||
- arg->type.type->eclass == EC_ANY ||
- (type && is_subtype(type, &arg->type ))))
+ arg->type.type->eclass == EC_ANY ||
+ (type && is_subtype(type, &arg->type ))))
return _dup_subaggr(sa, a, type);
}
}
@@ -547,7 +546,7 @@ sql_bind_aggr_(sql_allocator *sa, sql_sc
sql_func *a = n->data;
if (strcmp(a->base.name, sqlaname) == 0 &&
- list_cmp(a->ops, ops, (fcmp) &arg_subtype_cmp) == 0)
+ list_cmp(a->ops, ops, (fcmp) &arg_subtype_cmp) == 0)
return _dup_subaggr(sa, a, type);
n = n->next;
}
@@ -561,7 +560,7 @@ sql_bind_aggr_(sql_allocator *sa, sql_sc
continue;
if (strcmp(a->base.name, sqlaname) == 0 &&
- list_cmp(a->ops, ops, (fcmp) &arg_subtype_cmp) == 0)
+ list_cmp(a->ops, ops, (fcmp) &arg_subtype_cmp)
== 0)
return _dup_subaggr(sa, a, type);
}
}
@@ -577,7 +576,7 @@ sql_bind_member_aggr(sql_allocator *sa,
sql_func *a = n->data;
if (strcmp(a->base.name, sqlaname) == 0 && list_length(a->ops)
== nrargs &&
- arg_subtype_cmp(a->ops->h->data, type) == 0)
+ arg_subtype_cmp(a->ops->h->data, type) == 0)
return _dup_subaggr(sa, a, NULL);
n = n->next;
}
@@ -591,7 +590,7 @@ sql_bind_member_aggr(sql_allocator *sa,
continue;
if (strcmp(a->base.name, sqlaname) == 0 &&
list_length(a->ops) == nrargs &&
- arg_subtype_cmp(a->ops->h->data, type) == 0)
+ arg_subtype_cmp(a->ops->h->data, type) == 0)
return _dup_subaggr(sa, a, NULL);
}
}
@@ -603,7 +602,6 @@ sql_find_aggr(sql_allocator *sa, sql_sch
{
node *n = aggrs->h;
- (void)s;
while (n) {
sql_func *a = n->data;
@@ -915,7 +913,6 @@ sql_find_funcs(sql_allocator *sa, sql_sc
return res;
}
-
/* find function based on first argument */
sql_subfunc *
sql_bind_member(sql_allocator *sa, sql_schema *s, const char *sqlfname,
sql_subtype *tp, int nrargs, sql_subfunc *prev)
@@ -1003,7 +1000,6 @@ sql_bind_func_(sql_allocator *sa, sql_sc
node *n = funcs->h;
sql_ftype filt = (type == F_FUNC)?F_FILT:type;
- (void)s;
for (; n; n = n->next) {
sql_func *f = n->data;
@@ -1093,7 +1089,6 @@ sql_bind_func_result3(sql_allocator *sa,
return fres;
}
-
static void
sql_create_alias(sql_allocator *sa, const char *name, const char *alias)
{
diff --git a/sql/server/rel_rel.h b/sql/server/rel_rel.h
--- a/sql/server/rel_rel.h
+++ b/sql/server/rel_rel.h
@@ -9,8 +9,9 @@
#ifndef _REL_REL_H_
#define _REL_REL_H_
+#include "sql_mvc.h"
#include "sql_relation.h"
-#include "sql_mvc.h"
+#include "sql_semantic.h"
#define sql_from 1
#define sql_where 2
@@ -57,7 +58,7 @@ extern sql_rel *rel_inplace_setop(sql_re
extern sql_rel *rel_inplace_project(sql_allocator *sa, sql_rel *rel, sql_rel
*l, list *e);
extern sql_rel *rel_inplace_groupby(sql_rel *rel, sql_rel *l, list
*groupbyexps, list *exps );
-extern int rel_convert_types(mvc *sql, sql_rel *ll, sql_rel *rr, sql_exp **L,
sql_exp **R, int scale_fixing, int tpe);
+extern int rel_convert_types(mvc *sql, sql_rel *ll, sql_rel *rr, sql_exp **L,
sql_exp **R, int scale_fixing, check_type tpe);
extern sql_rel *rel_setop(sql_allocator *sa, sql_rel *l, sql_rel *r,
operator_type setop);
extern sql_rel *rel_setop_check_types(mvc *sql, sql_rel *l, sql_rel *r, list
*ls, list *rs, operator_type op);
extern sql_rel *rel_crossproduct(sql_allocator *sa, sql_rel *l, sql_rel *r,
operator_type join);
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
@@ -1307,9 +1307,9 @@ rel_numeric_supertype(mvc *sql, sql_exp
}
sql_exp *
-rel_check_type(mvc *sql, sql_subtype *t, sql_rel *rel, sql_exp *exp, int tpe)
+rel_check_type(mvc *sql, sql_subtype *t, sql_rel *rel, sql_exp *exp,
check_type tpe)
{
- int err = 0;
+ int c, err = 0;
sql_exp* nexp = NULL;
sql_subtype *fromtype = exp_subtype(exp);
@@ -1321,12 +1321,15 @@ rel_check_type(mvc *sql, sql_subtype *t,
return nexp;
if (fromtype && subtype_cmp(t, fromtype) != 0) {
- int c = sql_type_convert(fromtype->type->eclass,
t->type->eclass);
- if (!c ||
- (c == 2 && tpe == type_set) || (c == 3 && tpe != type_cast)){
- err = 1;
+ if (EC_INTERVAL(fromtype->type->eclass) && (t->type->eclass ==
EC_NUM || t->type->eclass == EC_POS) && t->digits < fromtype->digits) {
+ err = 1; /* conversion from interval to num depends on
the number of digits */
} else {
- exp = exp_convert(sql->sa, exp, fromtype, t);
+ c = sql_type_convert(fromtype->type->eclass,
t->type->eclass);
+ if (!c || (c == 2 && tpe == type_set) || (c == 3 && tpe
!= type_cast)) {
+ err = 1;
+ } else {
+ exp = exp_convert(sql->sa, exp, fromtype, t);
+ }
}
}
if (err) {
@@ -1390,7 +1393,7 @@ exp_scale_algebra(mvc *sql, sql_subfunc
}
int
-rel_convert_types(mvc *sql, sql_rel *ll, sql_rel *rr, sql_exp **L, sql_exp
**R, int scale_fixing, int tpe)
+rel_convert_types(mvc *sql, sql_rel *ll, sql_rel *rr, sql_exp **L, sql_exp
**R, int scale_fixing, check_type tpe)
{
sql_exp *ls = *L;
sql_exp *rs = *R;
diff --git a/sql/server/rel_select.h b/sql/server/rel_select.h
--- a/sql/server/rel_select.h
+++ b/sql/server/rel_select.h
@@ -24,7 +24,7 @@ extern sql_exp * rel_value_exp(sql_query
extern sql_exp * rel_value_exp2(sql_query *query, sql_rel **rel, symbol *se,
int f, exp_kind ek, int *is_last);
/* TODO rename to exp_check_type + move to rel_exp.c */
-extern sql_exp *rel_check_type(mvc *sql, sql_subtype *t, sql_rel *rel, sql_exp
*exp, int tpe);
+extern sql_exp *rel_check_type(mvc *sql, sql_subtype *t, sql_rel *rel, sql_exp
*exp, check_type tpe);
extern sql_exp *rel_unop_(sql_query *query, sql_rel *rel, sql_exp *e,
sql_schema *s, char *fname, int card);
extern sql_exp *rel_binop_(sql_query *query, sql_rel *rel, sql_exp *l, sql_exp
*r, sql_schema *s, char *fname, int card);
diff --git a/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.sql
b/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.sql
--- a/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.sql
+++ b/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.sql
@@ -1,4 +1,3 @@
-START TRANSACTION;
CREATE TABLE INTERVAL_TBL (f1 interval second);
INSERT INTO INTERVAL_TBL (f1) VALUES (1), (2), (3), (4);
SELECT count(f1), cast(sum(f1) as bigint), avg(f1), median(f1), max(f1),
min(f1) FROM INTERVAL_TBL;
@@ -6,4 +5,9 @@ SELECT count(f1), cast(sum(f1) as bigint
CREATE TABLE INTERVAL_TBL2 (f1 interval month);
INSERT INTO INTERVAL_TBL2 (f1) VALUES (1), (2), (3), (4);
SELECT count(f1), cast(sum(f1) as bigint), avg(f1), median(f1), max(f1),
min(f1) FROM INTERVAL_TBL2;
-ROLLBACK;
+
+SELECT median_avg(f1) from INTERVAL_TBL; --error, median_avg is not available
yet for sec_interval
+SELECT median_avg(f1) from INTERVAL_TBL2;
+
+DROP TABLE INTERVAL_TBL;
+DROP TABLE INTERVAL_TBL2;
diff --git
a/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.err
b/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.err
--- a/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.err
+++ b/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.err
@@ -23,6 +23,10 @@ stderr of test 'aggregates-intervals.Bug
# 16:49:00 > "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-284678" "--port=34676"
# 16:49:00 >
+MAPI = (monetdb) /var/tmp/mtest-281202/.s.monetdb.31954
+QUERY = SELECT median_avg(f1) from INTERVAL_TBL; --error, median_avg is not
available yet for sec_interval
+ERROR = !SELECT: no such unary operator 'median_avg(sec_interval)'
+CODE = 42000
# 16:49:01 >
# 16:49:01 > "Done."
diff --git
a/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.out
b/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.out
--- a/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.out
+++ b/sql/test/BugTracker-2014/Tests/aggregates-intervals.Bug-3533.stable.out
@@ -81,7 +81,14 @@ stdout of test 'aggregates-intervals.Bug
% bigint, bigint, double, month_interval, month_interval, month_interval
# type
% 1, 2, 24, 1, 1, 1 # length
[ 4, 10, 2.5, 2, 4, 1 ]
-#ROLLBACK;
+#SELECT median_avg(f1) from INTERVAL_TBL2;
+% sys.L2 # table_name
+% L2 # name
+% double # type
+% 24 # length
+[ 2.5 ]
+#DROP TABLE INTERVAL_TBL;
+#DROP TABLE INTERVAL_TBL2;
# 16:49:01 >
# 16:49:01 > "Done."
diff --git a/sql/test/emptydb-upgrade-chain-hge/Tests/package.py
b/sql/test/emptydb-upgrade-chain-hge/Tests/package.py
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list