Changeset: bab7ca9d98ed for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bab7ca9d98ed
Modified Files:
        sql/backends/monet5/Tests/rapi00.sql
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_user.c
        sql/include/sql_catalog.h
        sql/server/rel_psm.c
        sql/server/sql_env.c
        sql/server/sql_mvc.c
        sql/server/sql_mvc.h
        sql/server/sql_parser.y
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: RIntegration
Log Message:

changed function storage, sql boolean is now a language integer
(0 mal, 1 sql, 2 R, 3 C, 4 J).

Next to creation, drop R/C/J functions works

During select we get a mal compilation error.


diffs (truncated from 412 to 300 lines):

diff --git a/sql/backends/monet5/Tests/rapi00.sql 
b/sql/backends/monet5/Tests/rapi00.sql
--- a/sql/backends/monet5/Tests/rapi00.sql
+++ b/sql/backends/monet5/Tests/rapi00.sql
@@ -21,6 +21,8 @@ language R {
 };
 
 select * from functions where name = 'rapi00';
-select * from rapi00();
 
+select * from rapi00() as R;
+
+drop function rapi00;
 drop table rapitable;
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
@@ -887,7 +887,7 @@ create_func(mvc *sql, char *sname, sql_f
                return sql_message("3F000!CREATE %s%s: no such schema '%s'", 
KF, F, sname);
        if (!s)
                s = cur_schema(sql);
-       nf = mvc_create_func(sql, NULL, s, f->base.name, f->ops, &f->res, 
f->type, f->mod, f->imp, f->query);
+       nf = mvc_create_func(sql, NULL, s, f->base.name, f->ops, &f->res, 
f->type, f->lang, f->mod, f->imp, f->query);
        if (nf && nf->query) {
                char *buf;
                sql_rel *r = NULL;
diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c
--- a/sql/backends/monet5/sql_user.c
+++ b/sql/backends/monet5/sql_user.c
@@ -216,7 +216,7 @@ monet5_create_privileges(ptr _mvc, sql_s
        l = sa_list(m->sa);
        /* following funcion returns a table (single column) of user names
           with the approriate scenario (sql) */
-       mvc_create_func(m, NULL, s, "db_users", l, &tpe, F_FUNC, "sql", 
"db_users", "CREATE FUNCTION db_users () RETURNS TABLE( name varchar(2048)) 
EXTERNAL NAME sql.db_users;");
+       mvc_create_func(m, NULL, s, "db_users", l, &tpe, F_FUNC, FUNC_LANG_SQL, 
"sql", "db_users", "CREATE FUNCTION db_users () RETURNS TABLE( name 
varchar(2048)) EXTERNAL NAME sql.db_users;");
        if (m->sa == NULL)
                _DELETE(l);
 
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -274,18 +274,18 @@ typedef struct sql_arg {
 #define F_AGGR 3
 #define F_FILT 4
 #define F_UNION 5
-#define F_CBODY 6
-#define F_RBODY 7
-#define F_JBODY 8
 
 #define IS_FUNC(f) (f->type == F_FUNC)
 #define IS_PROC(f) (f->type == F_PROC)
 #define IS_AGGR(f) (f->type == F_AGGR)
 #define IS_FILT(f) (f->type == F_FILT)
 #define IS_UNION(f) (f->type == F_UNION)
-#define IS_CBODY(f) (f->type == F_CBODY)
-#define IS_RBODY(f) (f->type == F_RBODY)
-#define IS_JBODY(f) (f->type == F_JBODY)
+
+#define FUNC_LANG_MAL 0
+#define FUNC_LANG_SQL 1
+#define FUNC_LANG_R   2
+#define FUNC_LANG_C   3
+#define FUNC_LANG_J   4
 
 typedef struct sql_func {
        sql_base base;
@@ -300,6 +300,7 @@ typedef struct sql_func {
                           1 sql 
                           2 sql instantiated proc 
                        */
+       int lang;       
        char *query;    /* sql code */
        int side_effect;
        int fix_scale;
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
@@ -679,7 +679,7 @@ rel_create_function(sql_allocator *sa, c
 }
 
 static sql_rel *
-rel_create_func(mvc *sql, dlist *qname, dlist *params, symbol *res, dlist 
*ext_name, dlist *body, int type)
+rel_create_func(mvc *sql, dlist *qname, dlist *params, symbol *res, dlist 
*ext_name, dlist *body, int type, int lang)
 {
        char *fname = qname_table(qname);
        char *sname = qname_schema(qname);
@@ -754,16 +754,13 @@ rel_create_func(mvc *sql, dlist *qname, 
                                                        "CREATE %s%s: failed to 
get restype", KF, F);
                        }
 
-                       if (body && type == F_RBODY) {
+                       if (body && lang != FUNC_LANG_SQL) {
+                               char *mod = (lang == FUNC_LANG_R)?"rapi":
+                                           (lang == FUNC_LANG_C)?"capi":
+                                           (lang == 
FUNC_LANG_J)?"japi":"unknown";
                                if (create) 
-                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, "rapi", fname, q);
-                       } else if (body && type == F_CBODY) {
-                               if (create) 
-                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, "capi", fname, q);
-                       } else if (body && type == F_JBODY) {
-                               if (create) 
-                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, "japi", fname, q);
-                       } else if (body) {              /* sql func */
+                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, lang,  mod, fname, q);
+                       } else if (body && lang == FUNC_LANG_SQL) {
                                list *b = NULL;
                                sql_schema *old_schema = cur_schema(sql);
        
@@ -789,7 +786,7 @@ rel_create_func(mvc *sql, dlist *qname, 
                                if (instantiate || deps) {
                                        return rel_psm_block(sql->sa, b);
                                } else if (create) {
-                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, "user", q, q);
+                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, lang, "user", q, q);
                                }
                        } else {
                                char *fmod = qname_module(ext_name);
@@ -797,7 +794,7 @@ rel_create_func(mvc *sql, dlist *qname, 
 
                                sql->params = NULL;
                                if (create) {
-                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, fmod, fnme, q);
+                                       f = mvc_create_func(sql, sql->sa, s, 
fname, l, restype, type, lang, fmod, fnme, q);
                                } else if (!sf) {
                                        return sql_error(sql, 01, "CREATE %s%s: 
external name %s.%s not bound (%s,%s)", KF, F, fmod, fnme, s->base.name, fname 
);
                                } else {
@@ -1157,8 +1154,9 @@ rel_psm(mvc *sql, symbol *s)
        {
                dlist *l = s->data.lval;
                int type = l->h->next->next->next->next->next->data.i_val;
+               int lang = l->h->next->next->next->next->next->next->data.i_val;
 
-               ret = rel_create_func(sql, l->h->data.lval, 
l->h->next->data.lval, l->h->next->next->data.sym, 
l->h->next->next->next->data.lval, l->h->next->next->next->next->data.lval, 
type);
+               ret = rel_create_func(sql, l->h->data.lval, 
l->h->next->data.lval, l->h->next->next->data.sym, 
l->h->next->next->next->data.lval, l->h->next->next->next->next->data.lval, 
type, lang);
                sql->type = Q_SCHEMA;
        }       break;
        case SQL_DROP_FUNC:
diff --git a/sql/server/sql_env.c b/sql/server/sql_env.c
--- a/sql/server/sql_env.c
+++ b/sql/server/sql_env.c
@@ -108,7 +108,7 @@ sql_create_env(mvc *m, sql_schema *s)
 
        /* add function */
        l = sa_list(m->sa);
-       mvc_create_func(m, NULL, s, "env", l, &tpe, F_FUNC, "sql", 
"sql_environment", "CREATE FUNCTION env () RETURNS TABLE( name varchar(1024), 
value varchar(2048)) EXTERNAL NAME sql.sql_environment;");
+       mvc_create_func(m, NULL, s, "env", l, &tpe, F_FUNC, FUNC_LANG_SQL, 
"sql", "sql_environment", "CREATE FUNCTION env () RETURNS TABLE( name 
varchar(1024), value varchar(2048)) EXTERNAL NAME sql.sql_environment;");
        if (m->sa == NULL)
                _DELETE(l);
 
@@ -121,7 +121,7 @@ sql_create_env(mvc *m, sql_schema *s)
 
        /* add function */
        l = sa_list(m->sa);
-       mvc_create_func(m, NULL, s, "var", l, &tpe, F_FUNC, "sql", 
"sql_variables", "CREATE FUNCTION var() RETURNS TABLE( name varchar(1024)) 
EXTERNAL NAME sql.sql_variables;");
+       mvc_create_func(m, NULL, s, "var", l, &tpe, F_FUNC, FUNC_LANG_SQL, 
"sql", "sql_variables", "CREATE FUNCTION var() RETURNS TABLE( name 
varchar(1024)) EXTERNAL NAME sql.sql_variables;");
        if (m->sa == NULL)
                _DELETE(l);
        return 0;
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -786,17 +786,17 @@ mvc_create_type(mvc *sql, sql_schema * s
 }
 
 sql_func *
-mvc_create_func(mvc *sql, sql_allocator *sa, sql_schema * s, char *name, list 
*args, sql_subtype *res, int type, char *mod, char *impl, char *query)
+mvc_create_func(mvc *sql, sql_allocator *sa, sql_schema * s, char *name, list 
*args, sql_subtype *res, int type, int lang, char *mod, char *impl, char *query)
 {
        sql_func *f = NULL;
 
        if (mvc_debug)
                fprintf(stderr, "#mvc_create_func %s\n", name);
        if (sa) {
-               f = create_sql_func(sa, name, args, res, type, mod, impl, 
query);
+               f = create_sql_func(sa, name, args, res, type, lang, mod, impl, 
query);
                f->s = s;
        } else 
-               f = sql_trans_create_func(sql->session->tr, s, name, args, res, 
type, mod, impl, query);
+               f = sql_trans_create_func(sql->session->tr, s, name, args, res, 
type, lang, mod, impl, query);
        return f;
 }
 
diff --git a/sql/server/sql_mvc.h b/sql/server/sql_mvc.h
--- a/sql/server/sql_mvc.h
+++ b/sql/server/sql_mvc.h
@@ -168,7 +168,7 @@ extern sql_key *mvc_bind_ukey(sql_table 
 extern sql_trigger *mvc_bind_trigger(mvc *c, sql_schema *s, char *tname);
 
 extern sql_type *mvc_create_type(mvc *sql, sql_schema *s, char *sqlname, int 
digits, int scale, int radix, char *impl);
-extern sql_func *mvc_create_func(mvc *sql, sql_allocator *sa, sql_schema *s, 
char *name, list *args, sql_subtype *res, int type, char *mod, char *impl, char 
*query);
+extern sql_func *mvc_create_func(mvc *sql, sql_allocator *sa, sql_schema *s, 
char *name, list *args, sql_subtype *res, int type, int lang, char *mod, char 
*impl, char *query);
 extern void mvc_drop_func(mvc *c, sql_schema *s, sql_func * func, int 
drop_action);
 extern void mvc_drop_all_func(mvc *c, sql_schema *s, list *list_func, int 
drop_action);
 
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -1780,6 +1780,7 @@ func_def:
                                append_list(f, $11);
                                append_list(f, NULL);
                                append_int(f, F_FUNC);
+                               append_int(f, FUNC_LANG_MAL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
  /* table in / table out functions */
  |  create UNION FUNCTION qname
@@ -1793,6 +1794,7 @@ func_def:
                                append_list(f, $12);
                                append_list(f, NULL);
                                append_int(f, F_UNION);
+                               append_int(f, FUNC_LANG_MAL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
  |  create FUNCTION qname
        '(' opt_paramlist ')'
@@ -1805,21 +1807,22 @@ func_def:
                                append_list(f, NULL);
                                append_list(f, $9);
                                append_int(f, F_FUNC);
+                               append_int(f, FUNC_LANG_SQL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
   | create FUNCTION qname
        '(' opt_paramlist ')'
     RETURNS func_data_type
     LANGUAGE IDENT X_BODY { 
-                       int tpe_func = 0;
+                       int lang = 0;
                        dlist *f = L();
                        char l = *$10;
 
                        if (l == 'R' || l == 'r')
-                               tpe_func = F_RBODY;
+                               lang = FUNC_LANG_R;
                        else if (l == 'C' || l == 'c')
-                               tpe_func = F_CBODY;
+                               lang = FUNC_LANG_C;
                        else if (l == 'J' || l == 'j')
-                               tpe_func = F_JBODY;
+                               lang = FUNC_LANG_J;
                        else
                                yyerror(m, sql_message("Language name R, C, or 
J(avascript):expected, received '%c'", l));
 
@@ -1828,7 +1831,8 @@ func_def:
                        append_symbol(f, $8);
                        append_list(f, NULL); 
                        append_list(f, append_string(L(), $11));
-                       append_int(f, tpe_func);
+                       append_int(f, F_FUNC);
+                       append_int(f, lang);
                        $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
   | create FILTER FUNCTION qname
        '(' opt_paramlist ')'
@@ -1841,6 +1845,7 @@ func_def:
                                append_list(f, $10);
                                append_list(f, NULL);
                                append_int(f, F_FILT);
+                               append_int(f, FUNC_LANG_MAL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
   | create AGGREGATE qname
        '(' opt_paramlist ')'
@@ -1853,6 +1858,7 @@ func_def:
                                append_list(f, $11);
                                append_list(f, NULL);
                                append_int(f, F_AGGR);
+                               append_int(f, FUNC_LANG_MAL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
  | /* proc ie no result */
     create PROCEDURE qname
@@ -1865,6 +1871,7 @@ func_def:
                                append_list(f, $9);
                                append_list(f, NULL);
                                append_int(f, F_PROC);
+                               append_int(f, FUNC_LANG_MAL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
   | create PROCEDURE qname
        '(' opt_paramlist ')'
@@ -1876,6 +1883,7 @@ func_def:
                                append_list(f, NULL); 
                                append_list(f, $7);
                                append_int(f, F_PROC);
+                               append_int(f, FUNC_LANG_SQL);
                          $$ = _symbol_create_list( SQL_CREATE_FUNC, f ); }
  ;
 
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -306,7 +306,7 @@ extern int sql_trans_commit(sql_trans *t
 
 extern sql_type *sql_trans_create_type(sql_trans *tr, sql_schema * s, char 
*sqlname, int digits, int scale, int radix, char *impl);
 
-extern sql_func *sql_trans_create_func(sql_trans *tr, sql_schema * s, char 
*func, list *args, sql_subtype *res, int type, char *mod, char *impl, char 
*query);
+extern sql_func *sql_trans_create_func(sql_trans *tr, sql_schema * s, char 
*func, list *args, sql_subtype *res, int type, int lang, char *mod, char *impl, 
char *query);
 
 extern void sql_trans_drop_func(sql_trans *tr, sql_schema *s, int id, int 
drop_action);
 extern void sql_trans_drop_all_func(sql_trans *tr, sql_schema *s, list 
*list_func, int drop_action);
@@ -379,7 +379,7 @@ extern sql_key * key_create_done(sql_all
 
 extern sql_idx *create_sql_idx(sql_allocator *sa, sql_table *t, char *nme, 
idx_type it);
 extern sql_idx *create_sql_ic(sql_allocator *sa, sql_idx *i, sql_column *c);
-extern sql_func *create_sql_func(sql_allocator *sa, char *func, list *args, 
sql_subtype *res, int type, char *mod, char *impl, char *query);
+extern sql_func *create_sql_func(sql_allocator *sa, char *func, list *args, 
sql_subtype *res, int type, int lang, char *mod, char *impl, char *query);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to