Changeset: b6e77ef8a714 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b6e77ef8a714
Added Files:
        sql/backends/monet5/Tests/cfunction02.sql
        sql/backends/monet5/Tests/cfunction02.stable.err
        sql/backends/monet5/Tests/cfunction02.stable.out
Removed Files:
        sql/backends/monet5/Tests/cfunction03.sql
Modified Files:
        monetdb5/mal/mal_factory.c
        monetdb5/optimizer/opt_wrapper.c
        sql/backends/monet5/Tests/All
        sql/backends/monet5/sql_gencode.c
Branch: trails
Log Message:

Clean factory parameters after each call, generate proper "fake" returns in the 
last statements in factories created from SQL.


diffs (267 lines):

diff --git a/monetdb5/mal/mal_factory.c b/monetdb5/mal/mal_factory.c
--- a/monetdb5/mal/mal_factory.c
+++ b/monetdb5/mal/mal_factory.c
@@ -143,9 +143,22 @@ runFactory(Client cntxt, MalBlkPtr mb, M
                }
                pl->stk->stkbot= mb->vtop;      /* stack already initialized */
                msg = runMAL(cntxt, mb, 0, pl->stk);
-        } else {
+       } else {
                msg = reenterMAL(cntxt, mb, pl->pc, -1, pl->stk);
        }
+       if(pl->stk) {
+               i = psig->retc;
+               for (k = pci->retc; i < pci->argc; i++, k++) { //for subsequent 
calls, the previous arguments must be freed
+                       lhs = &pl->stk->stk[psig->argv[k]];
+                       /* variable arguments ? */
+                       if (k == psig->argc - 1)
+                               k--;
+                       if (lhs->vtype == TYPE_str) {
+                               GDKfree(lhs->val.sval);
+                               lhs->val.sval = NULL;
+                       }
+               }
+       }
        /* propagate change in debugging status */
        if (cmd && pl->stk && pl->stk->cmd != cmd && cmd != 'x')
                for (; stk; stk = stk->up)
@@ -341,10 +354,6 @@ shutdownFactory(Client cntxt, MalBlkPtr 
                        pl->caller = NULL;
                        pl->pci = NULL;
                        pl->env = NULL;
-                       pl->client = NULL;
-                       pl->caller = NULL;
-                       pl->env= NULL;
-                       pl->pci = NULL;
                }
        return MAL_SUCCEED;
 }
@@ -400,10 +409,6 @@ void mal_factory_reset(void)
                        pl->caller = NULL;
                        pl->pci = NULL;
                        pl->env = NULL;
-                       pl->client = NULL;
-                       pl->caller = NULL;
-                       pl->env= NULL;
-                       pl->pci = NULL;
        }
        plantId = 1;
        lastPlant = 0;
diff --git a/monetdb5/optimizer/opt_wrapper.c b/monetdb5/optimizer/opt_wrapper.c
--- a/monetdb5/optimizer/opt_wrapper.c
+++ b/monetdb5/optimizer/opt_wrapper.c
@@ -26,6 +26,7 @@
 #include "opt_candidates.h"
 #include "opt_constants.h"
 #include "opt_costModel.h"
+#include "opt_cquery.h"
 #include "opt_dataflow.h"
 #include "opt_deadcode.h"
 #include "opt_emptybind.h"
@@ -48,7 +49,6 @@
 #include "opt_remap.h"
 #include "opt_remoteQueries.h"
 #include "opt_reorder.h"
-#include "opt_cquery.h"
 #include "opt_volcano.h"
 #include "opt_wlc.h"
 
@@ -64,6 +64,7 @@ struct{
        {"commonTerms", &OPTcommonTermsImplementation,0,0},
        {"constants", &OPTconstantsImplementation,0,0},
        {"costModel", &OPTcostModelImplementation,0,0},
+       {"cquery", &OPTcqueryImplementation,0,0},
        {"dataflow", &OPTdataflowImplementation,0,0},
        {"deadcode", &OPTdeadcodeImplementation,0,0},
        {"emptybind", &OPTemptybindImplementation,0,0},
@@ -71,7 +72,6 @@ struct{
        {"garbageCollector", &OPTgarbageCollectorImplementation,0,0},
        {"generator", &OPTgeneratorImplementation,0,0},
        {"inline", &OPTinlineImplementation,0,0},
-       {"cquery", &OPTcqueryImplementation,0,0},
        {"jit", &OPTjitImplementation,0,0},
        {"json", &OPTjsonImplementation,0,0},
        {"matpack", &OPTmatpackImplementation,0,0},
diff --git a/sql/backends/monet5/Tests/All b/sql/backends/monet5/Tests/All
--- a/sql/backends/monet5/Tests/All
+++ b/sql/backends/monet5/Tests/All
@@ -114,6 +114,7 @@ cqstream03
 
 cfunction00
 cfunction01
+cfunction02
 
 factory00
 factory01
diff --git a/sql/backends/monet5/Tests/cfunction03.sql 
b/sql/backends/monet5/Tests/cfunction02.sql
rename from sql/backends/monet5/Tests/cfunction03.sql
rename to sql/backends/monet5/Tests/cfunction02.sql
diff --git a/sql/backends/monet5/Tests/cfunction02.stable.err 
b/sql/backends/monet5/Tests/cfunction02.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/cfunction02.stable.err
@@ -0,0 +1,34 @@
+stderr of test 'cfunction02` in directory 'sql/backends/monet5` itself:
+
+
+# 17:04:52 >  
+# 17:04:52 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=39818" "--set" 
"mapi_usock=/var/tmp/mtest-27977/.s.monetdb.39818" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/home/ferreira/MonetDB-trails/BUILD/var/MonetDB/mTests_sql_backends_monet5"
+# 17:04:52 >  
+
+# builtin opt  gdk_dbpath = 
/home/ferreira/MonetDB-trails/BUILD/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# 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 = 39818
+# cmdline opt  mapi_usock = /var/tmp/mtest-27977/.s.monetdb.39818
+# cmdline opt  monet_prompt = 
+# cmdline opt  gdk_dbpath = 
/home/ferreira/MonetDB-trails/BUILD/var/MonetDB/mTests_sql_backends_monet5
+# cmdline opt  gdk_debug = 536870922
+
+# 17:04:52 >  
+# 17:04:52 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-27977" "--port=39818"
+# 17:04:52 >  
+
+
+# 17:04:58 >  
+# 17:04:58 >  "Done."
+# 17:04:58 >  
+
diff --git a/sql/backends/monet5/Tests/cfunction02.stable.out 
b/sql/backends/monet5/Tests/cfunction02.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/cfunction02.stable.out
@@ -0,0 +1,59 @@
+stdout of test 'cfunction02` in directory 'sql/backends/monet5` itself:
+
+
+# 17:04:52 >  
+# 17:04:52 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=39818" "--set" 
"mapi_usock=/var/tmp/mtest-27977/.s.monetdb.39818" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/home/ferreira/MonetDB-trails/BUILD/var/MonetDB/mTests_sql_backends_monet5"
+# 17:04:52 >  
+
+# MonetDB 5 server v11.28.0
+# This is an unreleased version
+# Serving database 'mTests_sql_backends_monet5', using 8 threads
+# Compiled for x86_64-pc-linux-gnu/64bit with 128bit integers
+# Found 15.498 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2017 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://dhcp-120.eduroam.cwi.nl:39818/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-27977/.s.monetdb.39818
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+# MonetDB/Timetrails module loaded
+
+Ready.
+
+# 17:04:52 >  
+# 17:04:52 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-27977" "--port=39818"
+# 17:04:52 >  
+
+#create table results3 (aa int, bb text);
+#create function cfunc3(input text) returns table (aa integer, bb text) begin
+#    declare s int;
+#    set s = 0;
+#    while true do
+#        set s = s + 1;
+#        yield table (select s, input);
+#    end while;
+#end;
+#start continuous function cfunc3('test') with heartbeat 1000 cycles 3;
+#pause continuous cfunc3;
+#create procedure cproc3() begin
+#    insert into results3 (select aa, bb from tmp.cfunc3);
+#end;
+#start continuous procedure cproc3() with cycles 3;
+#stop continuous cfunc3;
+#select aa, bb from results3;
+% sys.results3,        sys.results3 # table_name
+% aa,  bb # name
+% int, clob # type
+% 1,   4 # length
+[ 1,   "test"  ]
+[ 1,   "test"  ]
+[ 1,   "test"  ]
+#drop function cfunc3;
+#drop procedure cproc3;
+#drop table results3;
+
+# 17:04:58 >  
+# 17:04:58 >  "Done."
+# 17:04:58 >  
+
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
@@ -583,7 +583,8 @@ backend_dumpstmt(backend *be, MalBlkPtr 
                        return -1;
        }
        /* generate a dummy return assignment for functions */
-       if (getArgType(mb, getInstrPtr(mb, 0), 0) != TYPE_void && 
getInstrPtr(mb, mb->stop - 1)->barrier != RETURNsymbol) {
+       if (getArgType(mb, getInstrPtr(mb, 0), 0) != TYPE_void && 
getInstrPtr(mb, mb->stop - 1)->barrier != RETURNsymbol &&
+               getInstrPtr(mb, 0)->token != FACTORYsymbol) {
                q = newAssignment(mb);
                if (q == NULL)
                        return -1;
@@ -917,7 +918,7 @@ backend_create_sql_func(backend *be, sql
 {
        mvc *m = be->mvc;
        MalBlkPtr curBlk = NULL;
-       InstrPtr curInstr = NULL;
+       InstrPtr curInstr = NULL, p = NULL, q = NULL/*, o*/;
        Client c = be->client;
        Symbol backup = NULL, curPrg = NULL;
        int i, retseen = 0, sideeffects = 0, vararg = (f->varres || f->vararg), 
no_inline = 0;
@@ -1011,7 +1012,7 @@ backend_create_sql_func(backend *be, sql
        /* check the function for side effects and make that explicit */
        sideeffects = 0;
        for (i = 1; i < curBlk->stop; i++) {
-               InstrPtr p = getInstrPtr(curBlk, i);
+               p = getInstrPtr(curBlk, i);
                if (getFunctionId(p) == bindRef || getFunctionId(p) == 
bindidxRef)
                        continue;
                sideeffects = sideeffects || hasSideEffects(curBlk, p, FALSE); 
@@ -1023,6 +1024,34 @@ backend_create_sql_func(backend *be, sql
                curBlk->inlineProp = 1;
        if (sideeffects)
                curBlk->unsafeProp = 1;
+       p = getInstrPtr(curBlk, 0);
+       if(p->token == FACTORYsymbol) { //for table returning factories we must 
have a "fake" return in the end
+               q = getInstrPtr(curBlk, curBlk->stop - 2);
+               if(q->barrier != RETURNsymbol) {
+                       q = newAssignment(curBlk);
+                       if (q == NULL)
+                               return -1;
+                       q->barrier = RETURNsymbol;
+                       moveInstruction(curBlk, curBlk->stop - 1, curBlk->stop 
- 2);
+               }
+               /*q->gc |= GARBAGECONTROL;
+               o = getInstrPtr(curBlk, curBlk->stop - 3);
+               if(getModuleId(o) == sqlRef && getFunctionId(o) == mvcRef) {
+                       removeInstruction(curBlk, o);
+               }*/
+               if (f->type == F_UNION) {
+                       q->retc = q->argc = 0;
+                       for (i = 0; i < p->retc; i++) {
+                               q = pushArgument(curBlk, q, getArg(p, i));
+                       }
+                       q->retc = q->argc;
+                       for (i = 0; i < p->retc; i++) {
+                               q = pushArgument(curBlk, q, getArg(p, i));
+                       }
+               } else {
+                       setVarType(curBlk, getArg(q, 0), getVarType(curBlk, 
getArg(p, 0)));
+               }
+       }
        /* optimize the code */
        SQLaddQueryToCache(c);
        if( curBlk->inlineProp == 0 && !c->curprg->def->errors) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to