Changeset: 6af2e3003431 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6af2e3003431
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        clients/Tests/exports.stable.out
        monetdb5/optimizer/opt_prelude.c
        monetdb5/optimizer/opt_prelude.h
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_statement.c
        sql/test/miscellaneous/Tests/declared_tables.sql
Branch: Jun2020
Log Message:

Fixed code generation for declared tables inside SQL UDFs. Also added some 
missing MAL functions declarations in the MAL namespace


diffs (truncated from 313 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
@@ -14040,6 +14040,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "bind_idxbat",  "pattern sql.bind_idxbat(mvc:int, schema:str, 
table:str, index:str, access:int):bat[:any_1] ",  "mvc_bind_idxbat_wrap;",      
  "Bind the 'schema.table.index' BAT with access kind:\n\t0 - base table\n\t1 - 
inserts\n\t2 - updates"   ]
 [ "sql",       "bind_idxbat",  "pattern sql.bind_idxbat(mvc:int, schema:str, 
table:str, index:str, access:int, part_nr:int, nr_parts:int) (uid:bat[:oid], 
uval:bat[:any_1]) ", "mvc_bind_idxbat_wrap;",        "Bind the 
'schema.table.index' BAT with access kind:\n\t0 - base table\n\t1 - 
inserts\n\t2 - updates"   ]
 [ "sql",       "bind_idxbat",  "pattern sql.bind_idxbat(mvc:int, schema:str, 
table:str, index:str, access:int, part_nr:int, nr_parts:int):bat[:any_1] ",     
  "mvc_bind_idxbat_wrap;",        "Bind the 'schema.table.index' BAT with 
access kind:\n\t0 - base table\n\t1 - inserts\n\t2 - updates"   ]
+[ "sql",       "clear",        "unsafe command sql.clear(b:bat[:any_1]):lng ", 
"mvc_clear_wrap;",      "Clear input BAT."      ]
 [ "sql",       "clear_table",  "unsafe pattern sql.clear_table(sname:str, 
tname:str):lng ",    "mvc_clear_table_wrap;",        "Clear the table 
sname.tname."  ]
 [ "sql",       "commit",       "pattern sql.commit():void ",   "SQLcommit;",   
"Trigger the commit operation for a MAL block"  ]
 [ "sql",       "copy_from",    "unsafe pattern sql.copy_from(t:ptr, sep:str, 
rsep:str, ssep:str, ns:str, fname:str, nr:lng, offset:lng, locked:int, 
best:int, fwf:str, onclient:int):bat[:any]... ",   "mvc_import_table_wrap;",    
   "Import a table from bstream s with the \n\tgiven tuple and seperators 
(sep/rsep)"      ]
@@ -14077,7 +14078,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "dec_round",    "command sql.dec_round(v:int, r:int):int ",     
"int_dec_round_wrap;",  "round off the value v to nearests multiple of r"       
]
 [ "sql",       "dec_round",    "command sql.dec_round(v:lng, r:lng):lng ",     
"lng_dec_round_wrap;",  "round off the value v to nearests multiple of r"       
]
 [ "sql",       "dec_round",    "command sql.dec_round(v:sht, r:sht):sht ",     
"sht_dec_round_wrap;",  "round off the value v to nearests multiple of r"       
]
-[ "sql",       "delete",       "unsafe pattern sql.delete(mvc:int, sname:str, 
tname:str, b:any):int ", "mvc_delete_wrap;",     "Delete a row from a table. 
Returns sequence number for order dependece."       ]
+[ "sql",       "delete",       "unsafe pattern sql.delete(mvc:int, sname:str, 
tname:str, b:any):int ", "mvc_delete_wrap;",     "Delete a row from a table. 
Returns sequence number for order dependency."      ]
 [ "sql",       "delta",        "command sql.delta(col:bat[:any_3], 
uid:bat[:oid], uval:bat[:any_3]):bat[:any_3] ",     "DELTAbat2;",   "Return 
column bat with delta's applied."       ]
 [ "sql",       "delta",        "command sql.delta(col:bat[:any_3], 
uid:bat[:oid], uval:bat[:any_3], ins:bat[:any_3]):bat[:any_3] ",    
"DELTAbat;",    "Return column bat with delta's applied."       ]
 [ "sql",       "deltas",       "pattern sql.deltas(schema:str) (ids:bat[:int], 
cleared:bat[:bit], readonly:bat[:lng], inserted:bat[:lng], updated:bat[:lng], 
deleted:bat[:lng], tr_level:bat[:int]) ", "mvc_delta_values;",    "Return the 
delta values sizes of all columns of the schema's tables, plus the current 
transaction level"       ]
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
@@ -19493,6 +19493,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "bind_idxbat",  "pattern sql.bind_idxbat(mvc:int, schema:str, 
table:str, index:str, access:int):bat[:any_1] ",  "mvc_bind_idxbat_wrap;",      
  "Bind the 'schema.table.index' BAT with access kind:\n\t0 - base table\n\t1 - 
inserts\n\t2 - updates"   ]
 [ "sql",       "bind_idxbat",  "pattern sql.bind_idxbat(mvc:int, schema:str, 
table:str, index:str, access:int, part_nr:int, nr_parts:int) (uid:bat[:oid], 
uval:bat[:any_1]) ", "mvc_bind_idxbat_wrap;",        "Bind the 
'schema.table.index' BAT with access kind:\n\t0 - base table\n\t1 - 
inserts\n\t2 - updates"   ]
 [ "sql",       "bind_idxbat",  "pattern sql.bind_idxbat(mvc:int, schema:str, 
table:str, index:str, access:int, part_nr:int, nr_parts:int):bat[:any_1] ",     
  "mvc_bind_idxbat_wrap;",        "Bind the 'schema.table.index' BAT with 
access kind:\n\t0 - base table\n\t1 - inserts\n\t2 - updates"   ]
+[ "sql",       "clear",        "unsafe command sql.clear(b:bat[:any_1]):lng ", 
"mvc_clear_wrap;",      "Clear input BAT."      ]
 [ "sql",       "clear_table",  "unsafe pattern sql.clear_table(sname:str, 
tname:str):lng ",    "mvc_clear_table_wrap;",        "Clear the table 
sname.tname."  ]
 [ "sql",       "commit",       "pattern sql.commit():void ",   "SQLcommit;",   
"Trigger the commit operation for a MAL block"  ]
 [ "sql",       "copy_from",    "unsafe pattern sql.copy_from(t:ptr, sep:str, 
rsep:str, ssep:str, ns:str, fname:str, nr:lng, offset:lng, locked:int, 
best:int, fwf:str, onclient:int):bat[:any]... ",   "mvc_import_table_wrap;",    
   "Import a table from bstream s with the \n\tgiven tuple and seperators 
(sep/rsep)"      ]
@@ -19534,7 +19535,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "dec_round",    "command sql.dec_round(v:int, r:int):int ",     
"int_dec_round_wrap;",  "round off the value v to nearests multiple of r"       
]
 [ "sql",       "dec_round",    "command sql.dec_round(v:lng, r:lng):lng ",     
"lng_dec_round_wrap;",  "round off the value v to nearests multiple of r"       
]
 [ "sql",       "dec_round",    "command sql.dec_round(v:sht, r:sht):sht ",     
"sht_dec_round_wrap;",  "round off the value v to nearests multiple of r"       
]
-[ "sql",       "delete",       "unsafe pattern sql.delete(mvc:int, sname:str, 
tname:str, b:any):int ", "mvc_delete_wrap;",     "Delete a row from a table. 
Returns sequence number for order dependece."       ]
+[ "sql",       "delete",       "unsafe pattern sql.delete(mvc:int, sname:str, 
tname:str, b:any):int ", "mvc_delete_wrap;",     "Delete a row from a table. 
Returns sequence number for order dependency."      ]
 [ "sql",       "delta",        "command sql.delta(col:bat[:any_3], 
uid:bat[:oid], uval:bat[:any_3]):bat[:any_3] ",     "DELTAbat2;",   "Return 
column bat with delta's applied."       ]
 [ "sql",       "delta",        "command sql.delta(col:bat[:any_3], 
uid:bat[:oid], uval:bat[:any_3], ins:bat[:any_3]):bat[:any_3] ",    
"DELTAbat;",    "Return column bat with delta's applied."       ]
 [ "sql",       "deltas",       "pattern sql.deltas(schema:str) (ids:bat[:int], 
cleared:bat[:bit], readonly:bat[:lng], inserted:bat[:lng], updated:bat[:lng], 
deleted:bat[:lng], tr_level:bat[:int]) ", "mvc_delta_values;",    "Return the 
delta values sizes of all columns of the schema's tables, plus the current 
transaction level"       ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -2043,6 +2043,7 @@ int bstream_destroy_wrap(Bstream *BS);
 str bstream_destroy_wrapwrap(void *ret, Bstream *BS);
 int bstream_read_wrap(int *res, Bstream *BS, int *size);
 str bstream_read_wrapwrap(int *res, Bstream *BS, int *size);
+str bulk_rotate_xor_hashRef;
 str calcRef;
 str callMAL(Client cntxt, MalBlkPtr mb, MalStkPtr *glb, ValPtr argv[], char 
debug);
 str callString(Client c, str s, int listing);
@@ -2054,6 +2055,7 @@ int chkInstruction(Module s, MalBlkPtr m
 str chkProgram(Module s, MalBlkPtr mb);
 str chkTypes(Module s, MalBlkPtr mb, int silent);
 str cleanupTraces(Client cntxt);
+str clearRef;
 void clearTrace(Client cntxt);
 void clearVariable(MalBlkPtr mb, int varid);
 str clear_tableRef;
@@ -2214,6 +2216,7 @@ malType getType(MalBlkPtr mb, str nme);
 str getTypeIdentifier(malType tpe);
 str getTypeName(malType tpe);
 lng getUserTime(void);
+str getVariableRef;
 lng getVolume(MalStkPtr stk, InstrPtr pci, int rd);
 int getprofilerlimit(void);
 Module globalModule(str nme);
@@ -2224,6 +2227,7 @@ str groupRef;
 str group_concatRef;
 str groupbyRef;
 str groupdoneRef;
+str growRef;
 int hasCommonResults(InstrPtr p, InstrPtr q);
 int hasSameArguments(MalBlkPtr mb, InstrPtr p, InstrPtr q);
 int hasSameSignature(MalBlkPtr mb, InstrPtr p, InstrPtr q);
diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -68,9 +68,11 @@ str bindRef;
 str blockRef;
 str bpmRef;
 str bstreamRef;
+str bulk_rotate_xor_hashRef;
 str calcRef;
 str capiRef;
 str catalogRef;
+str clearRef;
 str clear_tableRef;
 str closeRef;
 str columnBindRef;
@@ -135,6 +137,7 @@ str first_valueRef;
 str generatorRef;
 str getRef;
 str getTraceRef;
+str getVariableRef;
 str grant_functionRef;
 str grantRef;
 str grant_rolesRef;
@@ -142,6 +145,7 @@ str groupbyRef;
 str group_concatRef;
 str groupdoneRef;
 str groupRef;
+str growRef;
 str hashRef;
 str hgeRef;
 str identityRef;
@@ -370,9 +374,11 @@ void optimizerInit(void)
        blockRef = putName("block");
        bpmRef = putName("bpm");
        bstreamRef = putName("bstream");
+       bulk_rotate_xor_hashRef = putName("bulk_rotate_xor_hash");
        calcRef = putName("calc");
        capiRef = putName("capi");
        catalogRef = putName("catalog");
+       clearRef = putName("clear");
        clear_tableRef = putName("clear_table");
        closeRef = putName("close");
        columnBindRef = putName("columnBind");
@@ -437,6 +443,7 @@ void optimizerInit(void)
        generatorRef = putName("generator");
        getRef = putName("get");
        getTraceRef = putName("getTrace");
+       getVariableRef = putName("getVariable");
        grant_functionRef = putName("grant_function");
        grantRef = putName("grant");
        grant_rolesRef = putName("grant_roles");
@@ -444,6 +451,7 @@ void optimizerInit(void)
        group_concatRef = putName("group_concat");
        groupdoneRef = putName("groupdone");
        groupRef = putName("group");
+       growRef = putName("grow");
        hashRef = putName("hash");
        hgeRef = putName("hge");
        identityRef = putName("identity");
diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h
--- a/monetdb5/optimizer/opt_prelude.h
+++ b/monetdb5/optimizer/opt_prelude.h
@@ -64,9 +64,11 @@ mal_export  str bindRef;
 mal_export  str blockRef;
 mal_export  str bpmRef;
 mal_export  str bstreamRef;
+mal_export  str bulk_rotate_xor_hashRef;
 mal_export  str calcRef;
 mal_export  str capiRef;
 mal_export  str catalogRef;
+mal_export  str clearRef;
 mal_export  str clear_tableRef;
 mal_export  str closeRef;
 mal_export  str columnBindRef;
@@ -132,6 +134,7 @@ mal_export  str first_valueRef;
 mal_export  str generatorRef;
 mal_export  str getRef;
 mal_export  str getTraceRef;
+mal_export  str getVariableRef;
 mal_export  str grant_functionRef;
 mal_export  str grantRef;
 mal_export  str grant_rolesRef;
@@ -139,6 +142,7 @@ mal_export  str groupbyRef;
 mal_export  str group_concatRef;
 mal_export  str groupdoneRef;
 mal_export  str groupRef;
+mal_export  str growRef;
 mal_export  str hashRef;
 mal_export  str hgeRef;
 mal_export  str identityRef;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -1644,13 +1644,28 @@ mvc_grow_wrap(Client cntxt, MalBlkPtr mb
        for(;cnt>0; cnt--, v++) {
                if (BUNappend(tid, &v, false) != GDK_SUCCEED) {
                        BBPunfix(Tid);
-                       throw(SQL, "sql", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                       throw(SQL, "sql.grow", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                }
        }
        BBPunfix(Tid);
        return MAL_SUCCEED;
 }
 
+str
+mvc_clear_wrap(lng *res, const bat *col)
+{
+       BAT *tid = 0;
+
+       *res = 0;
+       if ((tid = BATdescriptor(*col)) == NULL)
+               throw(SQL, "sql.clear", SQLSTATE(HY005) "Cannot access 
descriptor");
+
+       *res = (lng) BATcount(tid);
+       BATclear(tid, true);
+       BBPunfix(tid->batCacheid);
+       return MAL_SUCCEED;
+}
+
 /*mvc_append_wrap(int *bid, str *sname, str *tname, str *cname, ptr d) */
 str
 mvc_append_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h
--- a/sql/backends/monet5/sql.h
+++ b/sql/backends/monet5/sql.h
@@ -67,6 +67,7 @@ sql5_export str SQLshutdown_wrap(Client 
 sql5_export str SQLtransaction2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 sql5_export str SQLcatalog(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
 
+sql5_export str mvc_clear_wrap(lng *res, const bat *col);
 sql5_export str mvc_grow_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 sql5_export str mvc_append_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 sql5_export str mvc_append_column(sql_trans *t, sql_column *c, BAT *ins);
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
@@ -283,6 +283,10 @@ pattern grow(tid:bat[:oid], :any_1):int
 address mvc_grow_wrap
 comment "Resize the tid column of a declared table.";
 
+unsafe command clear(b:bat[:any_1]):lng
+address mvc_clear_wrap
+comment "Clear input BAT.";
+
 pattern append(mvc:int, sname:str, tname:str, cname:str, ins:any):int
 address mvc_append_wrap
 comment "Append to the column tname.cname (possibly optimized to replace the 
insert bat of tname.cname. Returns sequence number for order dependence.";
@@ -304,7 +308,7 @@ comment "Return the tables tid column.";
 
 unsafe pattern delete(mvc:int, sname:str, tname:str, b:any):int
 address mvc_delete_wrap
-comment "Delete a row from a table. Returns sequence number for order 
dependece.";
+comment "Delete a row from a table. Returns sequence number for order 
dependency.";
 
 unsafe pattern resultSet(tbl:str, attr:str, tpe:str, len:int, scale:int, 
eclass:int, val:any) :int 
 address mvc_scalar_value_wrap
diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -330,7 +330,7 @@ stmt_var(backend *be, const char *varnam
        if (level == 1 ) { /* global */
                int tt = t->type->localtype;
 
-               q = newStmt(mb, sqlRef, putName("getVariable"));
+               q = newStmt(mb, sqlRef, getVariableRef);
                q = pushArgument(mb, q, be->mvc_var);
                q = pushStr(mb, q, varname);
                if (q == NULL)
@@ -522,7 +522,7 @@ stmt_tid(backend *be, sql_table *t, int 
                s->nr = l[0];
                return s;
        }
-               q = newStmt(mb, sqlRef, tidRef);
+       q = newStmt(mb, sqlRef, tidRef);
        if (q == NULL)
                return NULL;
        setVarType(mb, getArg(q, 0), newBatType(tt));
@@ -695,7 +695,7 @@ stmt_append_col(backend *be, sql_column 
                int *l = c->t->data;
 
                if (c->colnr == 0) { /* append to tid column */
-                       q = newStmt(mb, sqlRef, "grow");
+                       q = newStmt(mb, sqlRef, growRef);
                        q = pushArgument(mb, q, l[0]);
                        q = pushArgument(mb, q, b->nr);
                } 
@@ -2768,13 +2768,11 @@ stmt_table_clear(backend *be, sql_table 
        InstrPtr q = NULL;
 
        if (!t->s && t->data) { /* declared table */
-               int *l = t->data; 
-               int cnt = list_length(t->columns.set)+1, i;
-
-               for (i = 0; i < cnt; i++) {
-                       q = newStmt(mb, batRef, "clear");
+               int *l = t->data, cnt = list_length(t->columns.set)+1;
+
+               for (int i = 0; i < cnt; i++) {
+                       q = newStmt(mb, sqlRef, clearRef);
                        q = pushArgument(mb, q, l[i]);
-                       l[i] = getDestVar(q);
                }
        } else {
                q = newStmt(mb, sqlRef, clear_tableRef);
@@ -2997,7 +2995,7 @@ stmt_Nop(backend *be, stmt *ops, sql_sub
                q = NULL;
                if (strcmp(fimp, "rotate_xor_hash") == 0 &&
                    strcmp(mod, calcRef) == 0 &&
-                   (q = newStmt(mb, mkeyRef, putName("bulk_rotate_xor_hash"))) 
== NULL)
+                   (q = newStmt(mb, mkeyRef, bulk_rotate_xor_hashRef)) == NULL)
                        return NULL;
                if (!q) {
                        if (f->func->type == F_UNION)
diff --git a/sql/test/miscellaneous/Tests/declared_tables.sql 
b/sql/test/miscellaneous/Tests/declared_tables.sql
--- a/sql/test/miscellaneous/Tests/declared_tables.sql
+++ b/sql/test/miscellaneous/Tests/declared_tables.sql
@@ -16,3 +16,20 @@ plan declare b int;
 explain declare b int;
 select a;
 select b; --error, b was never declared
+
+/* Testing declared tables inside UDFs */
+CREATE OR REPLACE FUNCTION testtruncate() RETURNS INT 
+BEGIN
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to