Changeset: 3c66999c81a8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3c66999c81a8
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_round_impl.h
        sql/backends/monet5/sql_statement.c
        sql/server/sql_atom.h
        sql/test/SQLancer/Tests/sqlancer03.stable.err
        sql/test/SQLancer/Tests/sqlancer03.stable.out
Branch: Jun2020
Log Message:

simplified coalesce maping (coalesce(e1,e2) -> ifthenelse(isnil(e1)),e2,e1)
fixed issue with conditional execution were the input condition is a bat
but the current value is a single value.


diffs (260 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
@@ -692,9 +692,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                        int push_cond_exec = 0;
                        stmt *ncond = NULL, *ocond = cond;
 
-                        if (sel && strcmp(sql_func_mod(f->func), "calc") == 0 
&& strcmp(sql_func_imp(f->func), "ifthenelse") != 0)
+                       if (sel && strcmp(sql_func_mod(f->func), "calc") == 0 
&& strcmp(sql_func_imp(f->func), "ifthenelse") != 0)
                                push_cands = 1;
-                        if (strcmp(sql_func_mod(f->func), "calc") == 0 && 
strcmp(sql_func_imp(f->func), "ifthenelse") == 0)
+                       if (strcmp(sql_func_mod(f->func), "calc") == 0 && 
strcmp(sql_func_imp(f->func), "ifthenelse") == 0)
                                push_cond_exec = 1;
 
                        assert(list_length(exps) == list_length(f->func->ops) 
|| f->func->type == F_ANALYTIC || f->func->type == F_LOADER || f->func->vararg 
|| f->func->varres);
@@ -770,7 +770,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                                list_append(l, ocond);
                        }
                        /* single value conditional execution done below */
-                       if (ocond && !push_cond_exec && !nrcols && 
strcmp(sql_func_mod(f->func), "calc") == 0) {
+                       if (ocond && !ocond->nrcols && !push_cond_exec && 
!nrcols && strcmp(sql_func_mod(f->func), "calc") == 0) {
                                sql_subtype *bt = sql_bind_localtype("bit");
                                sql_subfunc *isnull = 
sql_bind_func(be->mvc->sa, NULL, "isnull", bt, NULL, F_FUNC);
                                sql_subfunc *or = sql_bind_func(be->mvc->sa, 
NULL, "or", bt, bt, F_FUNC);
diff --git a/sql/backends/monet5/sql_round_impl.h 
b/sql/backends/monet5/sql_round_impl.h
--- a/sql/backends/monet5/sql_round_impl.h
+++ b/sql/backends/monet5/sql_round_impl.h
@@ -296,6 +296,8 @@ str_2dec(TYPE *res, const str *val, cons
        if (scale < *sc) {
                /* the current scale is too small, increase it by adding 0's */
                int dff = *sc - scale;  /* CANNOT be 0! */
+               if (dff >= MAX_SCALE)
+                       throw(SQL, STRING(TYPE), SQLSTATE(42000) "Rounding of 
decimal (%s) doesn't fit format (%d.%d)", *val, *d, *sc);
 
                value *= scales[dff];
                scale += dff;
@@ -304,6 +306,10 @@ str_2dec(TYPE *res, const str *val, cons
                /* the current scale is too big, decrease it by correctly 
rounding */
                /* we should round properly, and check for overflow (res >= 
10^digits+scale) */
                int dff = scale - *sc;  /* CANNOT be 0 */
+
+               if (dff >= MAX_SCALE)
+                       throw(SQL, STRING(TYPE), SQLSTATE(42000) "Rounding of 
decimal (%s) doesn't fit format (%d.%d)", *val, *d, *sc);
+
                BIG rnd = scales[dff] >> 1;
 
                if (value > 0)
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
@@ -3079,21 +3079,17 @@ stmt_Nop(backend *be, stmt *ops, sql_sub
 
                nrcols = e1->nrcols>e2->nrcols ? e1->nrcols:e2->nrcols;
                /* nrcols */
-               //coalesce(e1,e2) -> ifthenelse(not(isnil(e1)),e1,e2)
+               //coalesce(e1,e2) -> ifthenelse(isnil(e1),e2,e1)
                if (strcmp(f->func->base.name, "coalesce") == 0) {
                        str mod = (!nrcols)?calcRef:batcalcRef;
                        q = newStmt(mb, e1->nrcols?mod:calcRef, "isnil");
                        q = pushArgument(mb, q, e1->nr);
                        int nr = getDestVar(q);
 
-                       q = newStmt(mb, e1->nrcols?mod:calcRef, "not");
-                       q = pushArgument(mb, q, nr);
-                       nr = getDestVar(q);
-
                        q = newStmt(mb, mod, "ifthenelse");
                        q = pushArgument(mb, q, nr);
+                       q = pushArgument(mb, q, e2->nr);
                        q = pushArgument(mb, q, e1->nr);
-                       q = pushArgument(mb, q, e2->nr);
                }
                //nullif(e1,e2) -> ifthenelse(e1==e2),NULL,e1)
                if (strcmp(f->func->base.name, "nullif") == 0) {
diff --git a/sql/server/sql_atom.h b/sql/server/sql_atom.h
--- a/sql/server/sql_atom.h
+++ b/sql/server/sql_atom.h
@@ -70,9 +70,11 @@ extern int atom_is_false(atom *a);
 extern int atom_is_zero(atom *a);
 
 #ifdef HAVE_HGE
-extern hge scales[39];
+#define MAX_SCALE 39
+extern hge scales[MAX_SCALE];
 #else
-extern lng scales[19];
+#define MAX_SCALE 19
+extern lng scales[MAX_SCALE];
 #endif
 
 extern atom *atom_zero_value(sql_allocator *sa, sql_subtype* tpe);
diff --git a/sql/test/SQLancer/Tests/sqlancer03.stable.err 
b/sql/test/SQLancer/Tests/sqlancer03.stable.err
--- a/sql/test/SQLancer/Tests/sqlancer03.stable.err
+++ b/sql/test/SQLancer/Tests/sqlancer03.stable.err
@@ -9,6 +9,10 @@ MAPI  = (monetdb) /var/tmp/mtest-279965/
 QUERY = select all sum(all cast("concat"(cast("month"(t1.c0) as string), 
r'1313451898') as interval month)) from t1;
 ERROR = !Wrong format (11313451898)
 CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-3257403/.s.monetdb.37811
+QUERY = select cast(group_concat(all r'0.5787210717348131') as decimal) from 
t0 group by - (abs(- (- (1061572565)))), least(t0.c0, 
least(cast(cast(0.09300166 as int) as interval month), t0.c0));
+ERROR = !Rounding of decimal 
(0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131,0.5787210717348131)
 doesn't fit format (18.3)
+CODE  = 42000
 
 # 17:14:16 >  
 # 17:14:16 >  "Done."
diff --git a/sql/test/SQLancer/Tests/sqlancer03.stable.out 
b/sql/test/SQLancer/Tests/sqlancer03.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer03.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer03.stable.out
@@ -478,6 +478,151 @@ stdout of test 'sqlancer03` in directory
 #"1970-01-14 01:01:12.000000"
 [ 4    ]
 #ROLLBACK;
+#START TRANSACTION; -- Unknown barrier type error
+#CREATE TABLE "sys"."t0" ("c0" INTEGER);
+#COPY 13 RECORDS INTO "sys"."t0" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#-952561247
+#668236378
+#-2045848771
+#-1790523044
+#-1543588024
+#-1750414901
+#1790114978
+#-274432932
+#874627516
+#-452950065
+#303960197
+#1
+#20
+[ 13   ]
+#create view v0(c0, c1, c2, c3) as (
+#      select distinct cast(case time '03:52:21' when time '05:04:36' then 
r'0.2' end as date), 
+#      coalesce (t0.c0, length(coalesce (r't%QB', replace(r' ,yO_5G刵i稶bDßᶏ''', 
r'0.8', r'-1e500')))), interval '1' month, timestamp '1970-01-16 13:47:20' from 
t0) with check option;
+#select v0.c0 from v0 join t0 on (0.3) not in 
+#(least(cast(t0.c0 as decimal), 
+#case least(time '19:32:57', time '16:10:04') when coalesce (time '22:25:53', 
time '00:14:31', time '18:12:09', time '01:59:38') 
+#then sql_min(0.7, 0.03) else 0.3 end), coalesce (case - (t0.c0) when 
cast(v0.c2 as real) then abs(0.4) else 0.5 end, cast(t0.c0 as decimal)));
+% .v0 # table_name
+% c0 # name
+% date # type
+% 10 # length
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+[ NULL ]
+#ROLLBACK;
+#START TRANSACTION; --SIGFPE
+#CREATE TABLE "sys"."t0" (
+#      "c0" INTERVAL MONTH NOT NULL,
+#      "c1" DOUBLE        NOT NULL,
+#      "c2" INTERVAL SECOND,
+#      CONSTRAINT "t0_c0_pkey" PRIMARY KEY ("c0"),
+#      CONSTRAINT "t0_c0_unique" UNIQUE ("c0"),
+#      CONSTRAINT "t0_c2_unique" UNIQUE ("c2"),
+#      CONSTRAINT "t0_c1_c2_c0_unique" UNIQUE ("c1", "c2", "c0")
+#);
+#COPY 19 RECORDS INTO "sys"."t0" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#99360484      0.8104160489147377      NULL
+#434886876     2003187499      NULL
+#1868593144    0.605787503265435       -721601140.000
+#1061127048    888903964       1369533413.000
+#-320985624    0.7758661909853402      0.423
+#-559098799    0.589701133253508       40364999.000
+#1065193340    0.41440171821837046     1426163499.000
+#1712034073    0.17915355536697286     -514338316.000
+#1526621371    0.5435870488621911      -3797659.000
+#130081317     0.4014279036721254      NULL
+#2048481116    0.2107093605121693      1704117927.000
+#-2067368391   0.5763887172257189      -452165183.000
+[ 19   ]
+#ROLLBACK;
 #START TRANSACTION; -- Bug 6924
 #CREATE TABLE "sys"."t0" ("a" INTEGER, "b" INTEGER NOT NULL, CONSTRAINT 
"t0_a_b_unique" UNIQUE ("a","b"));
 #COPY 39 RECORDS INTO "sys"."t0" FROM stdin USING DELIMITERS E'\t',E'\n','"';
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to