Changeset: a70bec1fec0e for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a70bec1fec0e Added Files: sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.err sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.out Modified Files: sql/server/sql_atom.c Branch: Mar2018 Log Message:
fixes for bug 6630, ie handle null in atom_* (add,sub,mul) code diffs (222 lines): diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c --- a/sql/server/sql_atom.c +++ b/sql/server/sql_atom.c @@ -1196,6 +1196,7 @@ atom * atom_add(atom *a1, atom *a2) { ValRecord dst; + if ((!EC_COMPUTE(a1->tpe.type->eclass) && (a1->tpe.type->eclass != EC_DEC || a1->tpe.digits != a2->tpe.digits || a1->tpe.scale != a2->tpe.scale)) || a1->tpe.digits < a2->tpe.digits || a1->tpe.type->localtype != a2->tpe.type->localtype) { return NULL; } @@ -1211,6 +1212,8 @@ atom_add(atom *a1, atom *a2) return NULL; a1->data = dst; dst.vtype = TYPE_dbl; + if (a1->isnull || a2->isnull) + a1->isnull = 1; if (VARconvert(&dst, &a1->data, 1) == GDK_SUCCEED) a1->d = dst.val.dval; return a1; @@ -1220,6 +1223,7 @@ atom * atom_sub(atom *a1, atom *a2) { ValRecord dst; + if ((!EC_COMPUTE(a1->tpe.type->eclass) && (a1->tpe.type->eclass != EC_DEC || a1->tpe.digits != a2->tpe.digits || a1->tpe.scale != a2->tpe.scale)) || a1->tpe.digits < a2->tpe.digits || a1->tpe.type->localtype != a2->tpe.type->localtype) { return NULL; } @@ -1237,6 +1241,8 @@ atom_sub(atom *a1, atom *a2) a1 = a2; a1->data = dst; dst.vtype = TYPE_dbl; + if (a1->isnull || a2->isnull) + a1->isnull = 1; if (VARconvert(&dst, &a1->data, 1) == GDK_SUCCEED) a1->d = dst.val.dval; return a1; @@ -1255,6 +1261,10 @@ atom_mul(atom *a1, atom *a2) dst.vtype = v1.vtype = v2.vtype = TYPE_dbl; v1.val.dval = a1->d; v2.val.dval = a2->d; + if (a1->isnull) + return a1; + if (a2->isnull) + return a2; if (VARcalcmul(&dst, &v1, &v2, 1) != GDK_SUCCEED) return NULL; a1->data.vtype = TYPE_dbl; @@ -1268,6 +1278,10 @@ atom_mul(atom *a1, atom *a2) a1 = a2; a2 = t; } + if (a1->isnull || a2->isnull) { + a1->isnull = 1; + return a1; + } dst.vtype = a1->tpe.type->localtype; if (VARcalcmul(&dst, &a1->data, &a2->data, 1) != GDK_SUCCEED) return NULL; @@ -1283,6 +1297,9 @@ int atom_inc( atom *a ) { ValRecord dst; + + if (a->isnull) + return -1; dst.vtype = a->data.vtype; if (VARcalcincr(&dst, &a->data, 1) != GDK_SUCCEED) return -1; @@ -1296,6 +1313,8 @@ atom_inc( atom *a ) int atom_is_zero( atom *a ) { + if (a->isnull) + return 0; switch(a->tpe.type->localtype) { case TYPE_bte: return a->data.val.btval == 0; @@ -1322,6 +1341,8 @@ atom_is_zero( atom *a ) int atom_is_true( atom *a ) { + if (a->isnull) + return 0; switch(a->tpe.type->localtype) { case TYPE_bit: return a->data.val.btval != 0; diff --git a/sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.err b/sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.err @@ -0,0 +1,35 @@ +stderr of test 'sqlitelogictest-cast-null-add.Bug-6630` in directory 'sql/test/BugTracker-2018` itself: + + +# 16:13:37 > +# 16:13:37 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=35639" "--set" "mapi_usock=/var/tmp/mtest-10835/.s.monetdb.35639" "--set" "monet_prompt=" "--forcemito" "--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018" "--set" "embedded_c=true" +# 16:13:37 > + +# builtin opt gdk_dbpath = /home/niels/scratch/rc-monetdb/Linux-x86_64/var/monetdb5/dbfarm/demo +# builtin opt gdk_debug = 0 +# builtin opt gdk_vmtrim = no +# builtin opt monet_prompt = > +# builtin opt monet_daemon = no +# builtin opt mapi_port = 50000 +# builtin opt mapi_open = false +# builtin opt mapi_autosense = false +# builtin opt sql_optimizer = default_pipe +# builtin opt sql_debug = 0 +# cmdline opt gdk_nr_threads = 0 +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 35639 +# cmdline opt mapi_usock = /var/tmp/mtest-10835/.s.monetdb.35639 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018 +# cmdline opt embedded_c = true +# cmdline opt gdk_debug = 553648138 + +# 16:13:37 > +# 16:13:37 > "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-10835" "--port=35639" +# 16:13:37 > + + +# 16:13:37 > +# 16:13:37 > "Done." +# 16:13:37 > + diff --git a/sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.out b/sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2018/Tests/sqlitelogictest-cast-null-add.Bug-6630.stable.out @@ -0,0 +1,90 @@ +stdout of test 'sqlitelogictest-cast-null-add.Bug-6630` in directory 'sql/test/BugTracker-2018` itself: + + +# 16:13:37 > +# 16:13:37 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=35639" "--set" "mapi_usock=/var/tmp/mtest-10835/.s.monetdb.35639" "--set" "monet_prompt=" "--forcemito" "--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018" "--set" "embedded_c=true" +# 16:13:37 > + +# MonetDB 5 server v11.29.8 +# This is an unreleased version +# Serving database 'mTests_sql_test_BugTracker-2018', using 8 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 128bit integers +# Found 15.386 GiB available main-memory. +# Copyright (c) 1993 - July 2008 CWI. +# Copyright (c) August 2008 - 2018 MonetDB B.V., all rights reserved +# Visit https://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://xps13:35639/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-10835/.s.monetdb.35639 +# MonetDB/GIS module loaded +# MonetDB/SQL module loaded + +Ready. + +# 16:13:37 > +# 16:13:37 > "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-10835" "--port=35639" +# 16:13:37 > + +#CREATE TABLE tab1(col0 INTEGER, col1 INTEGER, col2 INTEGER); +#CREATE TABLE tab2(col0 INTEGER, col1 INTEGER, col2 INTEGER); +#INSERT INTO tab1 VALUES(51,14,96), (85,5,59), (91,47,68); +[ 3 ] +#INSERT INTO tab2 VALUES(64,77,40), (75,67,58), (46,51,23); +[ 3 ] +#SELECT 0 + CAST ( NULL AS INTEGER ) + 0; -- NULL +% .L3 # table_name +% L3 # name +% hugeint # type +% 1 # length +[ NULL ] +#SELECT CAST ( 90 + CAST ( NULL AS INTEGER ) + + - 90 AS BIGINT ) FROM tab1 AS cor0 WHERE NULL IS NULL; +% .L3 # table_name +% L3 # name +% bigint # type +% 1 # length +[ NULL ] +[ NULL ] +[ NULL ] +#SELECT CAST ( 24 - CAST ( NULL AS INTEGER ) + - 29 + COUNT ( * ) + - 46 AS BIGINT ) AS col2 FROM tab2; -- NULL +% .L6 # table_name +% col2 # name +% bigint # type +% 1 # length +[ NULL ] +#SELECT DISTINCT CAST ( + 2 + + CAST ( NULL AS INTEGER ) - - ( + 69 ) AS BIGINT ) FROM tab2 AS cor0; -- NULL +% .L3 # table_name +% L3 # name +% bigint # type +% 1 # length +[ NULL ] +#SELECT ALL CAST ( - 8 + CAST ( NULL AS INTEGER ) + 43 AS BIGINT ) FROM tab2 cor0; -- A single column with 3 NULL values +% .L3 # table_name +% L3 # name +% bigint # type +% 1 # length +[ NULL ] +[ NULL ] +[ NULL ] +#SELECT ALL CAST ( 51 + + CAST ( NULL AS INTEGER ) - - - 17 AS BIGINT ) AS col0 FROM tab2; +% .L4 # table_name +% col0 # name +% bigint # type +% 1 # length +[ NULL ] +[ NULL ] +[ NULL ] +#SELECT ALL CAST ( col1 / - - ( + CAST ( NULL AS INTEGER ) ) AS BIGINT ) col0, +# CAST ( 39 + + + CAST ( NULL AS INTEGER ) + + - 10 + col1 / - col0 AS BIGINT ) AS col1 FROM tab2; +% sys.L4, .L10 # table_name +% col0, col1 # name +% bigint, bigint # type +% 1, 1 # length +[ NULL, NULL ] +[ NULL, NULL ] +[ NULL, NULL ] +#DROP TABLE tab1; +#DROP TABLE tab2; + +# 16:13:37 > +# 16:13:37 > "Done." +# 16:13:37 > + _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list