Changeset: 0fc93542f3d4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0fc93542f3d4
Modified Files:
        sql/backends/monet5/Tests/cquery09.stable.err
        sql/backends/monet5/sql_cquery.c
        sql/backends/monet5/sql_execute.c
Branch: trails
Log Message:

Adding continuous functions in the Petri-net.


diffs (146 lines):

diff --git a/sql/backends/monet5/Tests/cquery09.stable.err 
b/sql/backends/monet5/Tests/cquery09.stable.err
--- a/sql/backends/monet5/Tests/cquery09.stable.err
+++ b/sql/backends/monet5/Tests/cquery09.stable.err
@@ -31,9 +31,9 @@ MAPI  = (monetdb) /var/tmp/mtest-4922/.s
 QUERY = drop table result9; --error
 ERROR = !DROP TABLE: unable to drop stream table 'result9': there are pending 
continuous queries on it
 CODE  = 42000
-MAPI  = (monetdb) /var/tmp/mtest-19446/.s.monetdb.36302
-QUERY = stop continuous sys.cq_c(2); --error
-ERROR = !The continuous procedure user.cq_c(2:int); has not yet started
+MAPI  = (monetdb) /var/tmp/mtest-14598/.s.monetdb.30177
+QUERY = stop continuous sys.cq_c(1);
+ERROR = !The continuous procedure user.cq_c(X_4); has not yet started
 CODE  = 42000
 
 # 16:43:44 >  
diff --git a/sql/backends/monet5/sql_cquery.c b/sql/backends/monet5/sql_cquery.c
--- a/sql/backends/monet5/sql_cquery.c
+++ b/sql/backends/monet5/sql_cquery.c
@@ -474,14 +474,23 @@ CQregister(Client cntxt, MalBlkPtr mb, M
        MalBlkPtr other;
        Symbol s;
        CQnode *pnew;
-       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
-       char* err_message = (sqlcontext && sqlcontext->continuous & 
mod_continuous_function) ? "function" : "procedure";
-       int i, j, cycles = sqlcontext ? sqlcontext->cycles : 
DEFAULT_CP_CYCLES;/*,
-          is_function = strcmp(err_message, "function") == 0;*/
-       lng heartbeats = sqlcontext ? sqlcontext->heartbeats : 
DEFAULT_CP_HEARTBEAT;
+       backend *be = (backend *) cntxt->sqlcontext;
+       mvc* sqlcontext;
+       char* err_message = "procedure";
+       int i, j, is_function = 0, cycles = DEFAULT_CP_CYCLES;
+       lng heartbeats = DEFAULT_CP_HEARTBEAT;
 
        (void) pci;
 
+       if(be){
+               sqlcontext = be->mvc;
+               if(sqlcontext->continuous & mod_continuous_function)
+                       err_message = "function";
+               cycles = sqlcontext->cycles;
+               heartbeats = sqlcontext->heartbeats;
+               is_function = (sqlcontext->continuous & 
mod_continuous_function);
+       }
+
        if(cycles < 0 && cycles != NO_CYCLES){
                msg = createException(SQL,"cquery.register",SQLSTATE(42000) 
"The cycles value must be non negative\n");
                goto finish;
@@ -491,15 +500,16 @@ CQregister(Client cntxt, MalBlkPtr mb, M
                goto finish;
        }
 
-       /*if(is_function) {
-               q = newStmt(mb, userRef, cq->name);
-               if (!q) {
-                       msg = 
createException(SQL,"cquery.register",SQLSTATE(HY001) MAL_MALLOC_FAIL);
-                       goto finish;
+       if(is_function){ /* for functions we need to remove the sql.mvc 
instruction */
+               for(i = 1; i< mb->stop; i++){
+                       sig= getInstrPtr(mb,i);
+                       if( getFunctionId(sig) == mvcRef){
+                               removeInstruction(mb, sig);
+                       }
                }
-       }*/
+       }
 
-       /* extract the actual procedure call and check for duplicate*/
+       /* extract the actual procedure/function call and check for duplicate */
        for(i = 1; i< mb->stop; i++){
                sig= getInstrPtr(mb,i);
                if( getModuleId(sig) == userRef)
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
@@ -341,7 +341,8 @@ SQLrun(Client c, backend *be, mvc *m)
        // This include template constants, BAT sizes.
        if( m->emod & mod_debug)
                mb->keephistory = TRUE;
-       msg = SQLoptimizeQuery(c, mb);
+       if(!m->continuous) /* it's fine to not optimize the MAL block in a 
continuous query, as the plan it's just a user module call */
+               msg = SQLoptimizeQuery(c, mb);
        mb->keephistory = FALSE;
 
        if (mb->errors){
@@ -355,36 +356,32 @@ SQLrun(Client c, backend *be, mvc *m)
                        printFunction(c->fdout, mb, 0, LIST_MAL_NAME | 
LIST_MAL_VALUE  |  LIST_MAL_MAPI);
        } else if( m->emod & mod_debug) {
                msg = runMALDebugger(c, mb);
+       } else if( m->emod & mod_trace){
+               SQLsetTrace(c,mb);
+               msg = runMAL(c, mb, 0, 0);
+               stopTrace(0);
+       } else if(m->continuous & mod_start_continuous) {
+               //mnstr_printf(c->fdout, "#Start continuous query\n");
+               // hand over the wrapper command to the scheduler
+               msg = CQregister(c,mb, 0,0);
+       } else if(m->continuous & mod_stop_continuous) {
+               //mnstr_printf(c->fdout, "#Stop continuous query\n");
+               msg = CQderegister(c,mb, 0,0);
+       } else if(m->continuous & mod_pause_continuous) {
+               //mnstr_printf(c->fdout, "#Stop continuous query\n");
+               msg = CQpause(c,mb, 0,0);
+       } else if(m->continuous & mod_resume_continuous) {
+               //mnstr_printf(c->fdout, "#Resume continuous query with 
changes\n");
+               msg = CQresume(c,mb, 0,0);
+       } else if(m->continuous & mod_resume_continuous_no_alter) {
+               //mnstr_printf(c->fdout, "#Resume continuous query with no 
changes\n");
+               msg = CQresumeNoAlter(c,mb, 0,0);
        } else {
-               if( m->emod & mod_trace){
-                       SQLsetTrace(c,mb);
-                       msg = runMAL(c, mb, 0, 0);
-                       stopTrace(0);
-               } else {
-                       if(m->continuous & mod_start_continuous) {
-                               //mnstr_printf(c->fdout, "#Start continuous 
query\n");
-                               // hand over the wrapper command to the 
scheduler
-                               msg = CQregister(c,mb, 0,0);
-                       } else if(m->continuous & mod_stop_continuous) {
-                               //mnstr_printf(c->fdout, "#Stop continuous 
query\n");
-                               msg = CQderegister(c,mb, 0,0);
-                       } else if(m->continuous & mod_pause_continuous) {
-                               //mnstr_printf(c->fdout, "#Stop continuous 
query\n");
-                               msg = CQpause(c,mb, 0,0);
-                       } else if(m->continuous & mod_resume_continuous) {
-                               //mnstr_printf(c->fdout, "#Resume continuous 
query with changes\n");
-                               msg = CQresume(c,mb, 0,0);
-                       } else if(m->continuous & 
mod_resume_continuous_no_alter) {
-                               //mnstr_printf(c->fdout, "#Resume continuous 
query with no changes\n");
-                               msg = CQresumeNoAlter(c,mb, 0,0);
-                       } else {
-                               msg = runMAL(c, mb, 0, 0);
-                       }
-                       m->continuous = 0;
-                       m->heartbeats = DEFAULT_CP_HEARTBEAT;
-                       m->cycles = DEFAULT_CP_CYCLES;
-               }
+               msg = runMAL(c, mb, 0, 0);
        }
+       m->continuous = 0;
+       m->heartbeats = DEFAULT_CP_HEARTBEAT;
+       m->cycles = DEFAULT_CP_CYCLES;
 
        // release the resources
        freeMalBlk(mb);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to