Changeset: cbf368c0a1d8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cbf368c0a1d8
Modified Files:
        sql/backends/monet5/Tests/factory00.stable.err
        sql/backends/monet5/sql_cquery.c
        sql/backends/monet5/sql_execute.c
        sql/server/rel_psm.c
        sql/server/rel_schema.c
        sql/server/rel_semantic.c
        sql/server/sql_mvc.h
        sql/server/sql_parser.h
        sql/server/sql_parser.y
Branch: trails
Log Message:

First steps into continuous functions calls in the Petri-net


diffs (truncated from 597 to 300 lines):

diff --git a/sql/backends/monet5/Tests/factory00.stable.err 
b/sql/backends/monet5/Tests/factory00.stable.err
--- a/sql/backends/monet5/Tests/factory00.stable.err
+++ b/sql/backends/monet5/Tests/factory00.stable.err
@@ -29,23 +29,23 @@ stderr of test 'factory00` in directory 
 
 MAPI  = (monetdb) /var/tmp/mtest-14113/.s.monetdb.37491
 QUERY = SELECT factory1(); --error
-
+ERROR = !The factory has ended
 CODE  = 42000
 MAPI  = (monetdb) /var/tmp/mtest-14113/.s.monetdb.37491
 QUERY = SELECT factory2(); --error
-
+ERROR = !The factory has ended
 CODE  = 42000
 MAPI  = (monetdb) /var/tmp/mtest-14113/.s.monetdb.37491
 QUERY = SELECT factory3(); --error
-
+ERROR = !The factory has ended
 CODE  = 42000
 MAPI  = (monetdb) /var/tmp/mtest-14113/.s.monetdb.37491
 QUERY = SELECT factory4(); --error
-
+ERROR = !The factory has ended
 CODE  = 42000
 MAPI  = (monetdb) /var/tmp/mtest-14113/.s.monetdb.37491
 QUERY = SELECT factory5(); --error
-
+ERROR = !The factory has ended
 CODE  = 42000
 
 # 14:39:53 >  
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
@@ -470,12 +470,13 @@ CQanalysis(Client cntxt, MalBlkPtr mb, i
 str
 CQregister(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci )
 {
-       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
        str msg = MAL_SUCCEED;
        InstrPtr sig = getInstrPtr(mb,0),q;
        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;
        lng heartbeats = sqlcontext ? sqlcontext->heartbeats : 
DEFAULT_CP_HEARTBEAT;
 
@@ -497,8 +498,8 @@ CQregister(Client cntxt, MalBlkPtr mb, M
                        break;
        }
        if( i == mb->stop){
-               msg = createException(SQL,"cquery.register",SQLSTATE(3F000) 
"Cannot detect procedure call %s.%s.\n",
-                                                         getModuleId(sig), 
getFunctionId(sig));
+               msg = createException(SQL,"cquery.register",SQLSTATE(3F000) 
"Cannot detect %s call %s.%s.\n",
+                                                         err_message, 
getModuleId(sig), getFunctionId(sig));
                goto finish;
        }
 
@@ -520,8 +521,8 @@ CQregister(Client cntxt, MalBlkPtr mb, M
        // access the actual procedure body
        s = findSymbol(cntxt->usermodule, getModuleId(sig), getFunctionId(sig));
        if ( s == NULL){
-               msg = createException(SQL,"cquery.register",SQLSTATE(3F000) 
"Cannot find procedure %s.%s.\n",
-                                                         getModuleId(sig), 
getFunctionId(sig));
+               msg = createException(SQL,"cquery.register",SQLSTATE(3F000) 
"Cannot find %s %s.%s.\n",
+                                                         err_message, 
getModuleId(sig), getFunctionId(sig));
                goto unlock;
        }
        if((msg = CQanalysis(cntxt, s->def, pnettop)) != MAL_SUCCEED) {
@@ -614,10 +615,11 @@ finish:
 static str
 CQresumeInternal(Client cntxt, MalBlkPtr mb, int with_alter)
 {
-       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
        str msg = MAL_SUCCEED, mb2str = NULL;
        int idx = 0, j, cycles = DEFAULT_CP_CYCLES;
        lng heartbeats = DEFAULT_CP_HEARTBEAT;
+       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
+       char* err_message = (sqlcontext && sqlcontext->continuous & 
mod_continuous_function) ? "function" : "procedure";
 
 #ifdef DEBUG_CQUERY
        fprintf(stderr, "#resume scheduler\n");
@@ -643,12 +645,12 @@ CQresumeInternal(Client cntxt, MalBlkPtr
        }
        if( idx == pnettop) {
                msg = createException(SQL, "cquery.resume",
-                                                         SQLSTATE(42000) "The 
continuous procedure %s has not yet started\n", mb2str);
+                                                         SQLSTATE(42000) "The 
continuous %s %s has not yet started\n", mb2str, err_message);
                goto unlock;
        }
        if( pnet[idx].status != CQPAUSE) {
                msg = createException(SQL, "cquery.resume",
-                                                         SQLSTATE(42000) "The 
continuous procedure %s is already running\n", mb2str);
+                                                         SQLSTATE(42000) "The 
continuous %s %s is already running\n", mb2str, err_message);
                goto unlock;
        }
        if(with_alter && heartbeats != NO_HEARTBEAT) {
@@ -685,6 +687,8 @@ CQresume(Client cntxt, MalBlkPtr mb, Mal
 {
        int i, k =-1;
        InstrPtr q;
+       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
+       char* err_message = (sqlcontext && sqlcontext->continuous & 
mod_continuous_function) ? "function" : "procedure";
        (void) stk;
        (void) pci;
 
@@ -700,8 +704,8 @@ CQresume(Client cntxt, MalBlkPtr mb, Mal
        }
        if( k >= 0 )
                return CQresumeInternal(cntxt, mb, 1);
-       throw(SQL,"cquery.resume",SQLSTATE(3F000) "The continuous procedure 
%s.%s was not found\n",
-                       getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
+       throw(SQL,"cquery.resume",SQLSTATE(3F000) "The continuous %s %s.%s was 
not found\n",
+                       err_message, getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
 }
 
 str
@@ -709,6 +713,8 @@ CQresumeNoAlter(Client cntxt, MalBlkPtr 
 {
        int i, k =-1;
        InstrPtr q;
+       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
+       char* err_message = (sqlcontext && sqlcontext->continuous & 
mod_continuous_function) ? "function" : "procedure";
        (void) stk;
        (void) pci;
 
@@ -724,8 +730,8 @@ CQresumeNoAlter(Client cntxt, MalBlkPtr 
        }
        if( k >= 0 )
                return CQresumeInternal(cntxt, mb, 0);
-       throw(SQL,"cquery.resume",SQLSTATE(3F000) "The continuous procedure 
%s.%s was not found\n",
-                       getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
+       throw(SQL,"cquery.resume",SQLSTATE(3F000) "The continuous %s %s.%s was 
not found\n",
+                       err_message, getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
 }
 
 str
@@ -761,7 +767,7 @@ CQresumeAll(Client cntxt, MalBlkPtr mb, 
 }
 
 static str
-CQpauseInternal(MalBlkPtr mb)
+CQpauseInternal(MalBlkPtr mb, char* err_message)
 {
        int idx = 0;
        str msg = MAL_SUCCEED, mb2str = NULL;
@@ -772,12 +778,12 @@ CQpauseInternal(MalBlkPtr mb)
        }
        if( idx == pnettop) {
                msg = createException(SQL, "cquery.pause",
-                                                         SQLSTATE(42000) "The 
continuous procedure %s has not yet started\n", mb2str);
+                                                         SQLSTATE(42000) "The 
continuous %s %s has not yet started\n", mb2str, err_message);
                goto finish;
        }
        if( pnet[idx].status == CQPAUSE) {
                msg = createException(SQL, "cquery.pause",
-                                                         SQLSTATE(42000) "The 
continuous procedure %s is already paused\n", mb2str);
+                                                         SQLSTATE(42000) "The 
continuous %s %s is already paused\n", mb2str, err_message);
                goto finish;
        }
        // actually wait if the query was running
@@ -802,7 +808,8 @@ CQpause(Client cntxt, MalBlkPtr mb, MalS
 {
        int i,k = -1;
        InstrPtr q;
-       (void) cntxt;
+       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
+       char* err_message = (sqlcontext && sqlcontext->continuous & 
mod_continuous_function) ? "function" : "procedure";
        (void) stk;
        (void) pci;
 
@@ -816,9 +823,9 @@ CQpause(Client cntxt, MalBlkPtr mb, MalS
                }
        }
        if( k >= 0)
-               return CQpauseInternal(mb);
-       throw(SQL,"cquery.pause",SQLSTATE(3F000) "The continuous procedure 
%s.%s was not found\n",
-                       getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
+               return CQpauseInternal(mb, err_message);
+       throw(SQL,"cquery.pause",SQLSTATE(3F000) "The continuous %s %s.%s was 
not found\n",
+                       err_message, getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
 }
 
 str
@@ -963,7 +970,7 @@ CQwait(Client cntxt, MalBlkPtr mb, MalSt
 /*Remove a specific continuous query from the scheduler */
 
 static str
-CQderegisterInternal(MalBlkPtr mb)
+CQderegisterInternal(MalBlkPtr mb, char* err_message)
 {
        int idx = 0;
        str msg = MAL_SUCCEED, mb2str = NULL;
@@ -974,7 +981,7 @@ CQderegisterInternal(MalBlkPtr mb)
        }
        if(idx == pnettop) {
                msg = createException(SQL, "cquery.deregister",
-                                                         SQLSTATE(42000) "The 
continuous procedure %s has not yet started\n", mb2str);
+                                                         SQLSTATE(42000) "The 
continuous %s %s has not yet started\n", mb2str, err_message);
                goto finish;
        }
        pnet[idx].status = CQSTOP;
@@ -1000,7 +1007,8 @@ CQderegister(Client cntxt, MalBlkPtr mb,
 {
        int i, k= -1;
        InstrPtr q;
-       (void) cntxt;
+       mvc* sqlcontext = ((backend *) cntxt->sqlcontext)->mvc;
+       char* err_message = (sqlcontext && sqlcontext->continuous & 
mod_continuous_function) ? "function" : "procedure";
        (void) stk;
        (void) pci;
 
@@ -1014,9 +1022,9 @@ CQderegister(Client cntxt, MalBlkPtr mb,
                }
        }
        if( k>= 0 )
-               return CQderegisterInternal(mb);
-       throw(SQL,"cquery.deregister",SQLSTATE(3F000) "The continuous procedure 
%s.%s was not found\n",
-                       getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
+               return CQderegisterInternal(mb, err_message);
+       throw(SQL,"cquery.deregister",SQLSTATE(3F000) "The continuous %s %s.%s 
was not found\n",
+                       err_message, getModuleId(getInstrPtr(mb,k)), 
getFunctionId(getInstrPtr(mb,k)));
 }
 
 str
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
@@ -361,29 +361,23 @@ SQLrun(Client c, backend *be, mvc *m)
                        msg = runMAL(c, mb, 0, 0);
                        stopTrace(0);
                } else {
-                       switch( m->continuous){
-                       case mod_start_continuous:
+                       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);
-                               break;
-                       case mod_stop_continuous:
+                       } else if(m->continuous & mod_stop_continuous) {
                                //mnstr_printf(c->fdout, "#Stop continuous 
query\n");
                                msg = CQderegister(c,mb, 0,0);
-                               break;
-                       case mod_pause_continuous:
-                               //mnstr_printf(c->fdout, "#Pause continuous 
query\n");
+                       } else if(m->continuous & mod_pause_continuous) {
+                               //mnstr_printf(c->fdout, "#Stop continuous 
query\n");
                                msg = CQpause(c,mb, 0,0);
-                               break;
-                       case mod_resume_continuous:
+                       } else if(m->continuous & mod_resume_continuous) {
                                //mnstr_printf(c->fdout, "#Resume continuous 
query with changes\n");
                                msg = CQresume(c,mb, 0,0);
-                               break;
-                       case mod_resume_continuous_no_alter:
+                       } 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);
-                               break;
-                       default:
+                       } else {
                                msg = runMAL(c, mb, 0, 0);
                        }
                        m->continuous = 0;
diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -149,15 +149,17 @@ psm_set_exp(mvc *sql, dnode *n)
 }
 
 static sql_exp*
-rel_psm_call(mvc * sql, symbol *se)
+rel_psm_call(mvc * sql, symbol *se, int continuous_query)
 {
        sql_subtype *t;
        sql_exp *res = NULL;
-       exp_kind ek = {type_value, card_none, FALSE};
+       int card = (!continuous_query || continuous_query == 
mod_continuous_procedure) ? card_none : card_value;
+       exp_kind ek = {type_value, card, FALSE};
        sql_rel *rel = NULL;
 
        res = rel_value_exp(sql, &rel, se, sql_sel, ek);
-       if (!res || rel || ((t=exp_subtype(res)) && t->type))  /* only 
procedures */
+       /* only procedures or continuous queries */
+       if (!continuous_query && (!res || rel || ((t=exp_subtype(res)) && 
t->type)))
                return sql_error(sql, 01, SQLSTATE(42000) "Function calls are 
ignored");
        return res;
 }
@@ -629,34 +631,18 @@ sequential_block (mvc *sql, sql_subtype 
                        break;
                case SQL_CALL:
                        sql->continuous = 0;
-                       res = rel_psm_call(sql, s->data.sym);
+                       res = rel_psm_call(sql, s->data.sym, 0);
                        break;
-               case SQL_START_CALL: {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to