Changeset: 56503ef3c1fa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=56503ef3c1fa
Modified Files:
        sql/server/rel_exp.c
        sql/server/rel_select.c
        sql/test/miscellaneous/Tests/simple_selects.sql
        sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: Jun2020
Log Message:

Small bugfix, if the returning type of a function bounds to any type and it's 
not set, set it to one of the arguments


diffs (79 lines):

diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -281,6 +281,7 @@ exp_convert(sql_allocator *sa, sql_exp *
 sql_exp * 
 exp_op( sql_allocator *sa, list *l, sql_subfunc *f )
 {
+       sql_subtype *fres;
        sql_exp *e = exp_create(sa, e_func);
        if (e == NULL)
                return NULL;
@@ -288,7 +289,14 @@ exp_op( sql_allocator *sa, list *l, sql_
        if (!l || list_length(l) == 0) 
                e->card = CARD_ATOM; /* unop returns a single atom */
        e->l = l;
-       e->f = f; 
+       e->f = f;
+
+       fres = exp_subtype(e);
+        /* corner case if the output of the function is void, set the type to 
one of the inputs */
+       if (!f->func->varres && list_length(l) > 0 && list_length(f->func->res) 
== 1 && fres && !subtype_cmp(fres, sql_bind_localtype("void"))) {
+               sql_subtype *t = exp_subtype(l->t->data);
+               f->res->h->data = sql_create_subtype(sa, t->type, t->digits, 
t->scale);
+       }
        return e;
 }
 
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
@@ -1914,9 +1914,7 @@ static sql_exp*
        int table_func = (ek.card == card_relation);
        sql_ftype type = (ek.card == card_loader)?F_LOADER:((ek.card == 
card_none)?F_PROC:
                   ((ek.card == card_relation)?F_UNION:F_FUNC));
-       sql_ftype filt = (type == F_FUNC)?F_FILT:type;
-
-       (void)filt;
+
        (void)nr_args;
        (void)obj_type;
        f = bind_func_(sql, s, fname, tl, type);
diff --git a/sql/test/miscellaneous/Tests/simple_selects.sql 
b/sql/test/miscellaneous/Tests/simple_selects.sql
--- a/sql/test/miscellaneous/Tests/simple_selects.sql
+++ b/sql/test/miscellaneous/Tests/simple_selects.sql
@@ -151,3 +151,6 @@ create view iambad as select * from _tab
 set current_timezone = null; --error, default global variables cannot be null
 set current_timezone = 11111111111111; --error, value too big
 set current_schema = null; --error, default global variables cannot be null
+
+select greatest(null, null);
+select sql_min(null, null);
diff --git a/sql/test/miscellaneous/Tests/simple_selects.stable.out 
b/sql/test/miscellaneous/Tests/simple_selects.stable.out
--- a/sql/test/miscellaneous/Tests/simple_selects.stable.out
+++ b/sql/test/miscellaneous/Tests/simple_selects.stable.out
@@ -362,6 +362,24 @@ stdout of test 'simple_selects` in direc
 % 1 # length
 [ 0    ]
 #drop table x;
+#declare table x (a int);
+#drop table if exists x;
+#create table myx (a boolean);
+#create table myy (a interval second);
+#drop table myx;
+#drop table myy;
+#select greatest(null, null);
+% . # table_name
+% %1 # name
+% char # type
+% 0 # length
+[ NULL ]
+#select sql_min(null, null);
+% . # table_name
+% %1 # name
+% char # type
+% 0 # length
+[ NULL ]
 
 # 17:31:38 >  
 # 17:31:38 >  "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to