Changeset: a8c386663dfe for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8c386663dfe Added Files: sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.sql sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.err sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.out Modified Files: sql/common/sql_types.c sql/include/sql_catalog.h sql/server/rel_select.c sql/storage/store.c sql/test/BugTracker-2012/Tests/All sql/test/BugTracker-2012/Tests/sticky-precision.Bug-2969.stable.out Branch: Apr2012 Log Message:
fixed bug in handeling decimals in user defined functions (bug 2992) diffs (245 lines): 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 @@ -757,7 +757,7 @@ sql_bind_func_(sql_allocator *sa, sql_sc if (IS_FUNC(f)) { /* not needed for PROC/FILT */ /* fix the scale */ digits = f->res.digits; - if (f->fix_scale > SCALE_NONE) { + if (f->fix_scale > SCALE_NONE && f->fix_scale < SCALE_EQ) { for (n = ops->h; n; n = n->next) { sql_subtype *a = n->data; @@ -804,7 +804,7 @@ sql_bind_func_(sql_allocator *sa, sql_sc sql_subfunc *fres = SA_ZNEW(sa, sql_subfunc); fres->func = f; - if (f->fix_scale > SCALE_NONE) { + if (f->fix_scale > SCALE_NONE && f->fix_scale < SCALE_EQ) { for (n = ops->h; n; n = n->next) { sql_subtype *a = n->data; diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h --- a/sql/include/sql_catalog.h +++ b/sql/include/sql_catalog.h @@ -85,6 +85,7 @@ #define SCALE_DIV 4 /* div on the other hand reduces the scales */ #define DIGITS_ADD 5 /* some types grow under functions (concat) */ #define INOUT 6 /* output type equals input type */ +#define SCALE_EQ 7 /* user defined functions need equal scales */ #define TR_OLD 0 #define TR_NEW 1 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 @@ -3432,6 +3432,13 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp if (f->func->fix_scale == SCALE_FIX) { l = exp_fix_scale(sql, t2, l, 0, 0); r = exp_fix_scale(sql, t1, r, 0, 0); + } else if (f->func->fix_scale == SCALE_EQ) { + sql_arg *a1 = f->func->ops->h->data; + sql_arg *a2 = f->func->ops->h->next->data; + t1 = &a1->type; + t2 = &a2->type; + l = exp_fix_scale(sql, t1, l, 0, 0); + r = exp_fix_scale(sql, t2, r, 0, 0); } else if (f->func->fix_scale == SCALE_DIV) { l = exp_scale_algebra(sql, f, l, r); } else if (f->func->fix_scale == SCALE_MUL) { @@ -3478,6 +3485,13 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp if (f->func->fix_scale == SCALE_FIX) { l = exp_fix_scale(sql, t2, l, 0, 0); r = exp_fix_scale(sql, t1, r, 0, 0); + } else if (f->func->fix_scale == SCALE_EQ) { + sql_arg *a1 = f->func->ops->h->data; + sql_arg *a2 = f->func->ops->h->next->data; + t1 = &a1->type; + t2 = &a2->type; + l = exp_fix_scale(sql, t1, l, 0, 0); + r = exp_fix_scale(sql, t2, r, 0, 0); } else if (f->func->fix_scale == SCALE_DIV) { l = exp_scale_algebra(sql, f, l, r); } else if (f->func->fix_scale == SCALE_MUL) { @@ -3540,8 +3554,6 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp return res; } -#define SQLMAXDEPTH ((THREAD_STACK_SIZE/4096)) - static sql_exp * rel_binop(mvc *sql, sql_rel **rel, symbol *se, int f, exp_kind ek) { diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -729,6 +729,7 @@ load_func(sql_trans *tr, sql_schema *s, t->res.scale = t->res.digits = 0; t->res.type = NULL; t->s = s; + t->fix_scale = SCALE_EQ; if (t->sql) { t->query = t->imp; t->imp = NULL; @@ -2041,6 +2042,7 @@ func_dup(sql_trans *tr, int flag, sql_fu f->sql = of->sql; f->side_effect = of->side_effect; f->ops = list_new(sa, of->ops->destroy); + f->fix_scale = of->fix_scale; for(n=of->ops->h; n; n = n->next) list_append(f->ops, arg_dup(sa, n->data)); f->res.type = NULL; @@ -3598,6 +3600,7 @@ create_sql_func(sql_allocator *sa, char t->res.scale = t->res.digits = 0; t->res.type = NULL; t->query = (query)?sa_strdup(sa, query):NULL; + t->fix_scale = SCALE_EQ; if (res) t->res = *res; t->s = NULL; @@ -3622,6 +3625,7 @@ sql_trans_create_func(sql_trans *tr, sql sql = t->sql = (query)?1:0; se = t->side_effect = res?FALSE:TRUE; t->ops = sa_list(tr->sa); + t->fix_scale = SCALE_EQ; for(n=args->h; n; n = n->next) list_append(t->ops, arg_dup(tr->sa, n->data)); t->res.scale = t->res.digits = 0; diff --git a/sql/test/BugTracker-2012/Tests/All b/sql/test/BugTracker-2012/Tests/All --- a/sql/test/BugTracker-2012/Tests/All +++ b/sql/test/BugTracker-2012/Tests/All @@ -30,3 +30,4 @@ segfault_incorrect_head.Bug-3028 table_returning_func_returns_too_many_columns.Bug-3077 table_functions_fail_after_restart-0.Bug-3063 table_functions_fail_after_restart-1.Bug-3063 +user_defined_decimal_function.Bug-2992 diff --git a/sql/test/BugTracker-2012/Tests/sticky-precision.Bug-2969.stable.out b/sql/test/BugTracker-2012/Tests/sticky-precision.Bug-2969.stable.out --- a/sql/test/BugTracker-2012/Tests/sticky-precision.Bug-2969.stable.out +++ b/sql/test/BugTracker-2012/Tests/sticky-precision.Bug-2969.stable.out @@ -56,7 +56,7 @@ Ready. [ 10000000 ] #select bug2969(12.1111,12.1111); % . # table_name -% bug2969_single_value # name +% scale_up_single_value # name % decimal # type % 16 # length [ 10000000 ] diff --git a/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.sql b/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.sql new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.sql @@ -0,0 +1,12 @@ + +create function truncode(lon decimal(9,6), lat decimal(9,6)) + returns int +begin + return 1; +end; + +select truncode(12,12); +select truncode(12.0,12); +select truncode(12.00,12); + +drop function truncode; diff --git a/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.err b/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.err @@ -0,0 +1,37 @@ +stderr of test 'user_defined_decimal_function.Bug-2992` in directory 'test/BugTracker-2012` itself: + + +# 08:33:49 > +# 08:33:49 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "gdk_dbfarm=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB" "--set" "mapi_open=true" "--set" "mapi_port=34635" "--set" "monet_prompt=" "--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_test_BugTracker-2012" "--set" "mal_listing=0" +# 08:33:49 > + +# builtin opt gdk_dbname = demo +# builtin opt gdk_dbfarm = /home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm +# builtin opt gdk_debug = 0 +# builtin opt gdk_alloc_map = no +# 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 gdk_dbfarm = /home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 34635 +# cmdline opt monet_prompt = +# cmdline opt mal_listing = 2 +# cmdline opt gdk_dbname = mTests_test_BugTracker-2012 +# cmdline opt mal_listing = 0 + +# 08:33:49 > +# 08:33:49 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=niels" "--port=34635" +# 08:33:49 > + + +# 08:33:49 > +# 08:33:49 > "Done." +# 08:33:49 > + diff --git a/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.out b/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2012/Tests/user_defined_decimal_function.Bug-2992.stable.out @@ -0,0 +1,54 @@ +stdout of test 'user_defined_decimal_function.Bug-2992` in directory 'test/BugTracker-2012` itself: + + +# 08:33:49 > +# 08:33:49 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "gdk_dbfarm=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB" "--set" "mapi_open=true" "--set" "mapi_port=34635" "--set" "monet_prompt=" "--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_test_BugTracker-2012" "--set" "mal_listing=0" +# 08:33:49 > + +# MonetDB 5 server v11.9.2 +# This is an unreleased version +# Serving database 'mTests_test_BugTracker-2012', using 4 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically linked +# Found 3.778 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2012 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:34635/ +# MonetDB/GIS module loaded +# MonetDB/SQL module loaded + +Ready. + +# 08:33:49 > +# 08:33:49 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=niels" "--port=34635" +# 08:33:49 > + +#create function truncode(lon decimal(9,6), lat decimal(9,6)) +# returns int +#begin +# return 1; +#end; +#select truncode(12,12); +% . # table_name +% truncode_single_value # name +% int # type +% 1 # length +[ 1 ] +#select truncode(12.0,12); +% . # table_name +% truncode_single_value # name +% int # type +% 1 # length +[ 1 ] +#select truncode(12.00,12); +% . # table_name +% scale_up_single_value # name +% int # type +% 1 # length +[ 1 ] +#drop function truncode; + +# 08:33:49 > +# 08:33:49 > "Done." +# 08:33:49 > + _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list