Changeset: 46f634cbe540 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=46f634cbe540
Added Files:
        sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.sql
        
sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.err
        
sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.out
Modified Files:
        sql/server/rel_select.c
        sql/test/BugTracker-2013/Tests/All
Branch: Feb2013
Log Message:

fixed bug 3342, ie cast a numeric up when a direct aggregation function isn't 
found.


diffs (233 lines):

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
@@ -1904,6 +1904,24 @@ exp_convert_inplace(mvc *sql, sql_subtyp
        return NULL;
 }
 
+static sql_exp *
+rel_numeric_supertype(mvc *sql, sql_exp *e )
+{
+       sql_subtype *tp = exp_subtype(e);
+
+       if (tp->type->eclass == EC_DEC) {
+               sql_subtype *dtp = sql_bind_localtype("dbl");
+
+               return rel_check_type(sql, dtp, e, type_cast);
+       }
+       if (tp->type->eclass == EC_NUM) {
+               sql_subtype *ltp = sql_bind_localtype("lng");
+
+               return rel_check_type(sql, ltp, e, type_cast);
+       }
+       return e;
+}
+
 sql_exp *
 rel_check_type(mvc *sql, sql_subtype *t, sql_exp *exp, int tpe)
 {
@@ -3631,26 +3649,6 @@ static sql_exp *
                        return e;
                }
                a = sql_bind_aggr(sql->sa, s, aname, NULL);
-               /* add aggr expression to the groupby, and return a
-                       column expression */
-
-               /* for correlated selections, we need to count on the
-                  join expression */
-               /*
-               if (groupby->r && exps_intern(groupby->r)) {
-                       sql_rel *i = groupby->l;
-
-                       if (i->exps && f == sql_sel && is_join(i->op)) {
-                               sql_rel *j = i->r;
-
-                               sql_exp *e = j->exps->h->data;
-                               assert(0);
-                               e = exp_column(sql->sa, exp_relname(e), 
exp_name(e), exp_subtype(e), exp_card(e), has_nil(e), 0);
-                               e = exp_aggr1(sql->sa, e, a, distinct, 1, 
groupby->card, 0);
-                               return e;
-                       }
-               }
-               */
                e = exp_aggr(sql->sa, NULL, a, distinct, 0, groupby->card, 0);
                if (*rel == groupby && f == sql_sel) /* selection */
                        return e;
@@ -3683,22 +3681,40 @@ static sql_exp *
 
        a = sql_bind_aggr_(sql->sa, s, aname, exp_types(sql->sa, exps));
        if (!a) { /* find aggr + convert */
-               a = sql_find_aggr(sql->sa, s, aname);
-               if (a) {
-                       node *n, *op = a->aggr->ops->h;
-                       list *nexps = sa_list(sql->sa);
-
-                       for (n = exps->h ; a && op && n; op = op->next, n = 
n->next ) {
-                               sql_arg *arg = op->data;
-                               sql_exp *e = n->data;
-
-                               e = rel_check_type(sql, &arg->type, e, 
type_equal);
-                               if (!e)
-                                       a = NULL;
-                               list_append(nexps, e);
+               /* First try larger numeric type */
+               node *n;
+               list *nexps = sa_list(sql->sa);
+
+               for (n = exps->h ;  n; n = n->next ) {
+                       sql_exp *e = n->data;
+
+                       /* cast up, for now just dec to double */
+                       e = rel_numeric_supertype(sql, e);
+                       if (!e)
+                               break;
+                       list_append(nexps, e);
+               }
+               a = sql_bind_aggr_(sql->sa, s, aname, exp_types(sql->sa, 
nexps));
+               if (a && list_length(nexps))  /* count(col) has |exps| != 
|nexps| */
+                       exps = nexps;
+               if (!a) {
+                       a = sql_find_aggr(sql->sa, s, aname);
+                       if (a) {
+                               node *n, *op = a->aggr->ops->h;
+                               list *nexps = sa_list(sql->sa);
+
+                               for (n = exps->h ; a && op && n; op = op->next, 
n = n->next ) {
+                                       sql_arg *arg = op->data;
+                                       sql_exp *e = n->data;
+
+                                       e = rel_check_type(sql, &arg->type, e, 
type_equal);
+                                       if (!e)
+                                               a = NULL;
+                                       list_append(nexps, e);
+                               }
+                               if (a && list_length(nexps))  /* count(col) has 
|exps| != |nexps| */
+                                       exps = nexps;
                        }
-                       if (a && list_length(nexps))  /* count(col) has |exps| 
!= |nexps| */
-                               exps = nexps;
                }
        }
        /* TODO: convert to single super type (iff |exps| > 1) */
diff --git a/sql/test/BugTracker-2013/Tests/All 
b/sql/test/BugTracker-2013/Tests/All
--- a/sql/test/BugTracker-2013/Tests/All
+++ b/sql/test/BugTracker-2013/Tests/All
@@ -35,3 +35,4 @@ incorrect_subquery_delete.Bug-3315
 qualified_aggrname.Bug-3332
 cannot_use_columns_after_groupby.Bug-3340
 sort_void_crash.Bug-3341
+bogus_aggregation_casts.Bug-3342
diff --git 
a/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.sql 
b/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.sql
@@ -0,0 +1,11 @@
+create table part (p_partkey integer not null, p_name varchar(55) not null, 
p_mfgr char(25) not null, p_brand char(10) not null, p_type varchar(25) not 
null, p_size integer not null, p_container char(10) not null, p_retailprice 
decimal(12,2) not null, p_comment varchar(23) not null);
+copy 5 records into part from stdin;
+1|goldenrod lavender spring chocolate lace|Manufacturer#1|Brand#13|PROMO 
BURNISHED COPPER|7|JUMBO PKG|901.00|ly. slyly ironi|
+2|maroon sky cream royal snow|Manufacturer#1|Brand#13|LARGE BRUSHED BRASS|1|LG 
CASE|902.00|lar accounts amo|
+3|brown blue puff midnight black|Manufacturer#4|Brand#42|STANDARD POLISHED 
BRASS|21|WRAP CASE|903.00|egular deposits hag|
+4|orange goldenrod peach misty seashell|Manufacturer#3|Brand#34|SMALL PLATED 
BRASS|14|MED DRUM|904.00|p furiously r|
+5|midnight linen almond tomato plum|Manufacturer#3|Brand#32|STANDARD POLISHED 
TIN|15|SM PKG|905.00| wake carefully |
+
+select sys.median(cast (p_retailprice as double)) from part;
+select sys.median(p_retailprice) from part;
+drop table part;
diff --git 
a/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.err 
b/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.err
@@ -0,0 +1,35 @@
+stderr of test 'bogus_aggregation_casts.Bug-3342` in directory 
'sql/test/BugTracker-2013` itself:
+
+
+# 21:17:24 >  
+# 21:17:24 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=30271" "--set" 
"mapi_usock=/var/tmp/mtest-12574/.s.monetdb.30271" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013"
 "--set" "mal_listing=0"
+# 21:17:24 >  
+
+# builtin opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = yes
+# 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 = 30271
+# cmdline opt  mapi_usock = /var/tmp/mtest-12574/.s.monetdb.30271
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013
+# cmdline opt  mal_listing = 0
+
+# 21:17:25 >  
+# 21:17:25 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-12574" "--port=30271"
+# 21:17:25 >  
+
+
+# 21:17:25 >  
+# 21:17:25 >  "Done."
+# 21:17:25 >  
+
diff --git 
a/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.out 
b/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/bogus_aggregation_casts.Bug-3342.stable.out
@@ -0,0 +1,53 @@
+stdout of test 'bogus_aggregation_casts.Bug-3342` in directory 
'sql/test/BugTracker-2013` itself:
+
+
+# 21:17:24 >  
+# 21:17:24 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=30271" "--set" 
"mapi_usock=/var/tmp/mtest-12574/.s.monetdb.30271" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013"
 "--set" "mal_listing=0"
+# 21:17:24 >  
+
+# MonetDB 5 server v11.15.12
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2013', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
+# Found 3.775 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2013 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://niels.nesco.mine.nu:30271/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-12574/.s.monetdb.30271
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+
+# 21:17:25 >  
+# 21:17:25 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-12574" "--port=30271"
+# 21:17:25 >  
+
+#create table part (p_partkey integer not null, p_name varchar(55) not null, 
p_mfgr char(25) not null, p_brand char(10) not null, p_type varchar(25) not 
null, p_size integer not null, p_container char(10) not null, p_retailprice 
decimal(12,2) not null, p_comment varchar(23) not null);
+#copy 5 records into part from stdin;
+#1|goldenrod lavender spring chocolate lace|Manufacturer#1|Brand#13|PROMO 
BURNISHED COPPER|7|JUMBO PKG|901.00|ly. slyly ironi|
+#2|maroon sky cream royal snow|Manufacturer#1|Brand#13|LARGE BRUSHED 
BRASS|1|LG CASE|902.00|lar accounts amo|
+#3|brown blue puff midnight black|Manufacturer#4|Brand#42|STANDARD POLISHED 
BRASS|21|WRAP CASE|903.00|egular deposits hag|
+#4|orange goldenrod peach misty seashell|Manufacturer#3|Brand#34|SMALL PLATED 
BRASS|14|MED DRUM|904.00|p furiously r|
+#5|midnight linen almond tomato plum|Manufacturer#3|Brand#32|STANDARD POLISHED 
TIN|15|SM PKG|905.00| wake carefully |
+[ 5    ]
+#select sys.median(cast (p_retailprice as double)) from part;
+% sys.L1 # table_name
+% L1 # name
+% double # type
+% 24 # length
+[ 903  ]
+#select sys.median(p_retailprice) from part;
+% sys.L1 # table_name
+% L1 # name
+% double # type
+% 24 # length
+[ 903  ]
+#drop table part;
+
+# 21:17:25 >  
+# 21:17:25 >  "Done."
+# 21:17:25 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to