Changeset: b0dc972ef4c0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b0dc972ef4c0
Added Files:
        
sql/test/BugTracker-2019/Tests/remote-table-non-existent-column.Bug-6750.stable.err
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_gencode.c
        sql/test/BugTracker-2015/Tests/schemadiff.Bug-3778.stable.out
        sql/test/BugTracker-2019/Tests/All
Branch: default
Log Message:

Final fix for bug 6750, ie send an extra string with the expected output types 
for the sending relation and verify it at the other side


diffs (truncated from 320 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -11456,7 +11456,8 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "querylog_enable",      "command sql.querylog_enable():void ",  
"QLOGenable;",  ""      ]
 [ "sql",       "querylog_enable",      "command 
sql.querylog_enable(thres:int):void ", "QLOGenableThreshold;", ""      ]
 [ "sql",       "rank", "pattern sql.rank(b:any_1, p:bit, o:bit):int ", 
"SQLrank;",     "return the ranked groups"      ]
-[ "sql",       "register",     "pattern sql.register(mod:str, fname:str, 
rel_stmt:str, sig:str):int ", "RAstatement2;",        "Compile the relational 
statement (rel_smt) and register it as mal function, mod.fname(signature)"      
]
+[ "sql",       "register",     "pattern sql.register(mod:str, fname:str, 
rel_stmt:str, sig:str):int ", "RAstatement2;",        ""      ]
+[ "sql",       "register",     "pattern sql.register(mod:str, fname:str, 
rel_stmt:str, sig:str, typ:str):int ",        "RAstatement2;",        "Compile 
the relational statement (rel_smt) and register it as mal function, 
mod.fname(signature)"      ]
 [ "sql",       "restart",      "unsafe pattern sql.restart(sname:str, 
sequence:str, start:lng):lng ",  "mvc_restart_seq;",     "restart the sequence 
with value start" ]
 [ "sql",       "resultSet",    "unsafe pattern sql.resultSet(tbl:bat[:str], 
attr:bat[:str], tpe:bat[:str], len:bat[:int], scale:bat[:int], cols:any...):int 
", "mvc_row_result_wrap;", "Prepare a table result set for the client 
front-end"   ]
 [ "sql",       "resultSet",    "unsafe pattern sql.resultSet(tbl:str, 
attr:str, tpe:str, len:int, scale:int, eclass:int, val:any):int ",       
"mvc_scalar_value_wrap;",       "Prepare a table result set for the client 
front-end."  ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -15888,7 +15888,8 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "querylog_enable",      "command sql.querylog_enable():void ",  
"QLOGenable;",  ""      ]
 [ "sql",       "querylog_enable",      "command 
sql.querylog_enable(thres:int):void ", "QLOGenableThreshold;", ""      ]
 [ "sql",       "rank", "pattern sql.rank(b:any_1, p:bit, o:bit):int ", 
"SQLrank;",     "return the ranked groups"      ]
-[ "sql",       "register",     "pattern sql.register(mod:str, fname:str, 
rel_stmt:str, sig:str):int ", "RAstatement2;",        "Compile the relational 
statement (rel_smt) and register it as mal function, mod.fname(signature)"      
]
+[ "sql",       "register",     "pattern sql.register(mod:str, fname:str, 
rel_stmt:str, sig:str):int ", "RAstatement2;",        ""      ]
+[ "sql",       "register",     "pattern sql.register(mod:str, fname:str, 
rel_stmt:str, sig:str, typ:str):int ",        "RAstatement2;",        "Compile 
the relational statement (rel_smt) and register it as mal function, 
mod.fname(signature)"      ]
 [ "sql",       "restart",      "unsafe pattern sql.restart(sname:str, 
sequence:str, start:lng):lng ",  "mvc_restart_seq;",     "restart the sequence 
with value start" ]
 [ "sql",       "resultSet",    "unsafe pattern sql.resultSet(tbl:bat[:str], 
attr:bat[:str], tpe:bat[:str], len:bat[:int], scale:bat[:int], cols:any...):int 
", "mvc_row_result_wrap;", "Prepare a table result set for the client 
front-end"   ]
 [ "sql",       "resultSet",    "unsafe pattern sql.resultSet(tbl:str, 
attr:str, tpe:str, len:int, scale:int, eclass:int, val:any):int ",       
"mvc_scalar_value_wrap;",       "Prepare a table result set for the client 
front-end."  ]
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -55,6 +55,8 @@ address RAstatement
 comment "Compile and execute a single 'relational algebra' statement";
 
 pattern register(mod:str, fname:str, rel_stmt:str, sig:str):int
+address RAstatement2;
+pattern register(mod:str, fname:str, rel_stmt:str, sig:str, typ:str):int
 address RAstatement2
 comment "Compile the relational statement (rel_smt) and register it as mal 
function, mod.fname(signature)";
 
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -873,13 +873,14 @@ str
 RAstatement2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        int pos = 0;
-       str *mod = getArgReference_str(stk, pci, 1);
-       str *nme = getArgReference_str(stk, pci, 2);
-       str *expr = getArgReference_str(stk, pci, 3);
-       str *sig = getArgReference_str(stk, pci, 4), c = *sig;
+       str mod = *getArgReference_str(stk, pci, 1);
+       str nme = *getArgReference_str(stk, pci, 2);
+       str expr = *getArgReference_str(stk, pci, 3);
+       str sig = *getArgReference_str(stk, pci, 4);
+       str types = pci->argc == 6 ? *getArgReference_str(stk, pci, 5) : NULL;
        backend *be = NULL;
        mvc *m = NULL;
-       str msg;
+       str msg = MAL_SUCCEED;
        sql_rel *rel;
        list *refs, *ops;
        char buf[BUFSIZ];
@@ -892,18 +893,22 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                return msg;
        if (!m->sa)
                m->sa = sa_create();
-       if (!m->sa)
+       if (!m->sa) {
+               sqlcleanup(m, 0);
                return createException(SQL,"RAstatement2",SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+       }
 
        /* keep copy of signature and relational expression */
-       snprintf(buf, BUFSIZ, "%s %s", *sig, *expr);
+       snprintf(buf, BUFSIZ, "%s %s", sig, expr);
 
-       if(!stack_push_frame(m, NULL))
+       if (!stack_push_frame(m, NULL)) {
+               sqlcleanup(m, 0);
                return createException(SQL,"RAstatement2",SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+       }
        ops = sa_list(m->sa);
-       while (c && *c && !isspace((unsigned char) *c)) {
-               char *vnme = c, *tnme;
-               char *p = strchr(++c, (int)' ');
+       while (sig && *sig && !isspace((unsigned char) *sig)) {
+               char *vnme = sig, *tnme;
+               char *p = strchr(++sig, (int)' ');
                int d,s,nr = -1;
                sql_subtype t;
                atom *a;
@@ -917,7 +922,7 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                *p++ = 0;
                tnme = sa_strdup(m->sa, tnme);
                if (!tnme) {
-                       stack_pop_frame(m);
+                       sqlcleanup(m, 0);
                        return 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL);
                }
                d = strtol(p, &p, 10);
@@ -932,32 +937,56 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                 * */
                if (nr >= 0) { 
                        append(ops, exp_atom_ref(m->sa, nr, &t));
-                       if(!sql_set_arg(m, nr, a)) {
-                               stack_pop_frame(m);
+                       if (!sql_set_arg(m, nr, a)) {
+                               sqlcleanup(m, 0);
                                return 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL);
                        }
                } else {
-                       if(!stack_push_var(m, vnme+1, &t)) {
-                               stack_pop_frame(m);
+                       if (!stack_push_var(m, vnme+1, &t)) {
+                               sqlcleanup(m, 0);
                                return 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL);
                        }
                        append(ops, exp_var(m->sa, sa_strdup(m->sa, vnme+1), 
&t, m->frame));
                }
-               c = strchr(p, (int)',');
-               if (c)
-                       c++;
+               sig = strchr(p, (int)',');
+               if (sig)
+                       sig++;
        }
        refs = sa_list(m->sa);
-       rel = rel_read(m, *expr, &pos, refs);
+       rel = rel_read(m, expr, &pos, refs);
        stack_pop_frame(m);
        if (rel)
                rel = sql_processrelation(m, rel, 1);
-       if (!rel || monet5_create_relational_function(m, *mod, *nme, rel, NULL, 
ops, 0) < 0) {
+       if (!rel) {
                if (strlen(m->errstr) > 6 && m->errstr[5] == '!')
                        msg = createException(SQL, "RAstatement2", "%s", 
m->errstr);
                else
                        msg = createException(SQL, "RAstatement2", 
SQLSTATE(42000) "%s", m->errstr);
+       } else if (rel && types && is_simple_project(rel->op)) { /* Test if 
types match */
+               list *types_list = sa_list(m->sa);
+               str token, rest;
+
+               for (token = strtok_r(types, "%%", &rest); token; token = 
strtok_r(NULL, "%%", &rest))
+                       list_append(types_list, token);
+
+               if (list_length(types_list) != list_length(rel->exps))
+                       msg = createException(SQL, "RAstatement2", 
SQLSTATE(42000) "The number of projections don't match between the generated 
plan and the expected one: %d != %d", 
+                                                                 
list_length(types_list), list_length(rel->exps));
+               else {
+                       int i = 1;
+                       for (node *n = rel->exps->h, *m = types_list->h ; n && 
m && !msg ; n = n->next, m = m->next) {
+                               sql_exp *e = (sql_exp *) n->data;
+                               sql_subtype *t = exp_subtype(e);
+                               str got = subtype2string(t), expected = (str) 
m->data;
+
+                               if (strcmp(expected, got) != 0)
+                                       msg = createException(SQL, 
"RAstatement2", SQLSTATE(42000) "Parameter %d has wrong SQL type, expected %s, 
but got %s instead", i, expected, got);
+                               i++;
+                       }
+               }
        }
+       if (!msg && monet5_create_relational_function(m, mod, nme, rel, NULL, 
ops, 0) < 0)
+               msg = createException(SQL, "RAstatement2", "%s", m->errstr);
        rel_destroy(rel);
        sqlcleanup(m, 0);
        return msg;
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -424,7 +424,7 @@ static int
        free(s); 
 
        s = "";
-       if (call && call->type == st_list) {
+       if (call && call->type == st_list) { /* Send existing variables in the 
plan */
                node *n;
 
                buf[0] = 0;
@@ -443,11 +443,36 @@ static int
                }
                s = buf;
        }
-       if(buf) {
+       if (buf) {
                o = newFcnCall(curBlk, remoteRef, putRef);
                o = pushArgument(curBlk, o, q);
                o = pushStr(curBlk, o, s);      /* signature */
                p = pushArgument(curBlk, p, getArg(o,0));
+       } else {
+               GDKfree(lname);
+               sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+               return -1;
+       }
+
+       buf[0] = 0;
+       nr = 0;
+       for (n = r->exps->h; n; n = n->next) { /* Send SQL types of the 
projection's expressions */
+               sql_exp *e = n->data;
+               sql_subtype *t = exp_subtype(e);
+
+               if ((nr + 100) > len) {
+                       buf = GDKrealloc(buf, len*=2);
+                       if(buf == NULL)
+                               break;
+               }
+
+               nr += snprintf(buf+nr, len-nr, "%s%s", subtype2string(t), 
n->next?"%%":"");
+       }
+       if (buf) {
+               o = newFcnCall(curBlk, remoteRef, putRef);
+               o = pushArgument(curBlk, o, q);
+               o = pushStr(curBlk, o, s);      /* SQL types as a single string 
*/
+               p = pushArgument(curBlk, p, getArg(o,0));
                GDKfree(buf);
        } else {
                GDKfree(lname);
diff --git a/sql/test/BugTracker-2015/Tests/schemadiff.Bug-3778.stable.out 
b/sql/test/BugTracker-2015/Tests/schemadiff.Bug-3778.stable.out
--- a/sql/test/BugTracker-2015/Tests/schemadiff.Bug-3778.stable.out
+++ b/sql/test/BugTracker-2015/Tests/schemadiff.Bug-3778.stable.out
@@ -5,31 +5,10 @@ stdout of test 'schemadiff.Bug-3778` in 
 # 15:29:05 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33909" "--set" 
"mapi_usock=/var/tmp/mtest-7442/.s.monetdb.33909" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/ufs/manegold/_/Monet/HG/default/prefix/_/var/MonetDB/mTests_sql_test_BugTracker-2015"
 "--set" "mal_listing=0" "--set" "embedded_r=yes"
 # 15:29:05 >  
 
-# MonetDB 5 server v11.22.0
-# This is an unreleased version
-# Serving database 'mTests_sql_test_BugTracker-2015', using 8 threads
-# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs and 128bit 
integers dynamically linked
-# Found 15.590 GiB available main-memory.
-# Copyright (c) 1993-July 2008 CWI.
-# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved
-# Visit http://www.monetdb.org/ for further information
-# Listening for connection requests on mapi:monetdb://rome.ins.cwi.nl:33909/
-# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-7442/.s.monetdb.33909
-# MonetDB/GIS module loaded
-# Start processing logs sql/sql_logs version 52200
-# Finished processing logs sql/sql_logs
-# MonetDB/SQL module loaded
-# MonetDB/R   module loaded
+(mapi:monetdb://monetdb@localhost/worker_0) Parameter 1 has wrong SQL type, 
expected int(32), but got bigint(64) instead
 
 
-# 11:19:25 >  
-# 11:19:25 >  "/usr/bin/python2" "schemadiff.Bug-3778.SQL.py" 
"schemadiff.Bug-3778"
-# 11:19:25 >  
-
-(mapi:monetdb://monetdb@localhost/worker_0) 'user.l1' undefined in:     
rmt8_X_2_bat_int:bat[:int] := user.l1();
+# 10:44:31 >  
+# 10:44:31 >  "Done."
+# 10:44:31 >  
 
-
-# 11:19:26 >  
-# 11:19:26 >  "Done."
-# 11:19:26 >  
-
diff --git a/sql/test/BugTracker-2019/Tests/All 
b/sql/test/BugTracker-2019/Tests/All
--- a/sql/test/BugTracker-2019/Tests/All
+++ b/sql/test/BugTracker-2019/Tests/All
@@ -6,7 +6,6 @@ subselect-contradiction.Bug-6683
 insert-replica-table.Bug-6684
 subselect-count.Bug-6686
 subselect.Bug-6688
-#timestamptransformation.Bug-6695
 duplicates-not-eliminated-long-CASE-stmt.Bug-6697
 subselect.Bug-6700
 alter_table_set_schema.Bug-6701
@@ -31,7 +30,7 @@ sequence-first-next-value.Bug-6743
 sequences-defaults.Bug-6744
 sequences-types.Bug-6745
 alter_table_drop_column.Bug-6749
-KNOWNFAIL&HAVE_PYMONETDB?remote-table-non-existent-column.Bug-6750
+HAVE_PYMONETDB?remote-table-non-existent-column.Bug-6750
 set-schema-mclient-msg.Bug-6754
 cte-union.Bug-6755
 merge-table-limit.Bug-6756
diff --git 
a/sql/test/BugTracker-2019/Tests/remote-table-non-existent-column.Bug-6750.stable.err
 
b/sql/test/BugTracker-2019/Tests/remote-table-non-existent-column.Bug-6750.stable.err
new file mode 100644
--- /dev/null
+++ 
b/sql/test/BugTracker-2019/Tests/remote-table-non-existent-column.Bug-6750.stable.err
@@ -0,0 +1,41 @@
+stderr of test 'remote-table-non-existent-column.Bug-6750` in directory 
'sql/test/BugTracker-2019` itself:
+
+
+# 10:42:19 >  
+# 10:42:19 >  "/usr/bin/python3" 
"remote-table-non-existent-column.Bug-6750.py" 
"remote-table-non-existent-column.Bug-6750"
+# 10:42:19 >  
+
+(mapi:monetdb://monetdb@localhost/node1) Identifier tab1.col2 doesn't exist
+(mapi:monetdb://monetdb@localhost/node1) Parameter 1 has wrong SQL type, 
expected double(53), but got tinyint(8) instead
+(mapi:monetdb://monetdb@localhost/node1) Merge tables not supported under 
remote connections
+# builtin opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-default/BUILD/var/monetdb5/dbfarm/demo
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_ipv6 = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# builtin opt  raw_strings = false
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 38041
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to