Changeset: 639dc6332862 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=639dc6332862
Modified Files:
        sql/include/sql_catalog.h
        sql/server/rel_schema.c
        sql/server/rel_schema.h
        sql/server/rel_semantic.c
        sql/server/sql_mvc.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: arrays
Log Message:

create array a (x integer dimension[4], y integer dimension[1:1:3], v float) 
succeeds
but the array cannot be queried and does not show in the catalog


diffs (250 lines):

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
@@ -122,6 +122,7 @@ typedef enum temp_t {
        SQL_LOCAL_TEMP,
        SQL_GLOBAL_TEMP,
        SQL_DECLARED_TABLE,     /* variable inside a stored procedure */
+       SQL_DECLARED_ARRAY,     /* variable inside a stored procedure */
        SQL_MERGE_TABLE,
        SQL_STREAM,
        SQL_REMOTE,
@@ -457,7 +458,8 @@ typedef enum table_types {
        tt_merge_table = 3,     /* multiple tables form one table */
        tt_stream = 4,          /* stream */
        tt_remote = 5,          /* stored on a remote server */
-       tt_replica_table = 6    /* multiple replica of the same table */
+       tt_replica_table = 6,   /* multiple replica of the same table */
+       tt_array = 7    /* array */
 } table_types;
 
 #define isTable(x)       (x->type==tt_table)
@@ -467,6 +469,7 @@ typedef enum table_types {
 #define isRemote(x)      (x->type==tt_remote)
 #define isReplicaTable(x) (x->type==tt_replica_table)
 #define isKindOfTable(x)  (isTable(x) || isMergeTable(x) || isRemote(x) || 
isReplicaTable(x))
+#define isArray(x)     (x->type==tt_array)
 
 #define TABLE_WRITABLE 0
 #define TABLE_READONLY 1
@@ -474,7 +477,7 @@ typedef enum table_types {
 
 typedef struct sql_table {
        sql_base base;
-       sht type;               /* table, view, etc */
+       sht type;               /* table, view, array, etc */
        sht access;             /* writable, readonly, appendonly */
        bit system;             /* system or user table */
        temp_t persistence;     /* persistent, global or local temporary */
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -648,6 +648,9 @@ table_element(mvc *sql, symbol *s, sql_s
        }
 
        switch (s->token) {
+       case SQL_DIMENSION:
+               fprintf(stderr, "table_element: Do something for dimensions\n");
+               break;
        case SQL_COLUMN:
                res = create_column(sql, s, ss, t, alter);
                break;
@@ -805,6 +808,90 @@ table_element(mvc *sql, symbol *s, sql_s
        return res;
 }
 
+sql_rel* rel_create_array(mvc *sql, sql_schema *ss, int temp, char *sname, 
char *name, symbol *array_elements, int commit_action) {
+       sql_schema *s = NULL;
+//     int instantiate = (sql->emode == m_instantiate);
+//     int deps = (sql->emode == m_deps);
+//     int create = (!instantiate && !deps);
+       int tt = tt_array;
+
+fprintf(stderr, "In rel_create_array\n");
+//     (void)create;
+       if (sname && !(s = mvc_bind_schema(sql, sname)))
+               return sql_error(sql, 02, "3F000!CREATE ARRAY: no such schema 
'%s'", sname);
+
+       if (temp != SQL_PERSIST && tt == tt_array && commit_action == CA_COMMIT)
+               commit_action = CA_DELETE;
+       
+       if (temp != SQL_DECLARED_ARRAY) {
+               if (temp != SQL_PERSIST && tt == tt_array) {
+                       s = mvc_bind_schema(sql, "tmp");
+                       if (temp == SQL_LOCAL_TEMP && sname && strcmp(sname, 
s->base.name) != 0)
+                               return sql_error(sql, 02, "3F000!CREATE ARRAY: 
local tempory arrays should be stored in the '%s' schema", s->base.name);
+               } else if (s == NULL) {
+                       s = ss;
+               }
+       }
+
+       if (temp != SQL_DECLARED_ARRAY && s)
+               sname = s->base.name;
+
+       if (mvc_bind_table(sql, s, name)) {
+               char *cd = (temp == SQL_DECLARED_ARRAY)?"DECLARE":"CREATE";
+               return sql_error(sql, 02, "42S01!%s ARRAY: name '%s' already in 
use", cd, name);
+       } else if (temp != SQL_DECLARED_ARRAY && (!schema_privs(sql->role_id, 
s) && !(isTempSchema(s) && temp == SQL_LOCAL_TEMP))){
+               return sql_error(sql, 02, "42000!CREATE ARRAY: insufficient 
privileges for user '%s' in schema '%s'", stack_get_string(sql, 
"current_user"), s->base.name);
+       } else if (array_elements->token == SQL_CREATE_ARRAY) { 
+               sql_table *t = mvc_create_table(sql, s, name, tt, 0, 
SQL_DECLARED_ARRAY, commit_action, -1);
+
+               dlist *columns = array_elements->data.lval;
+               dnode *n;
+
+               for (n = columns->h; n; n = n->next) {
+                       symbol *sym = n->data.sym;
+                       int res = table_element(sql, sym, s, t, 0);
+
+                       if (res == SQL_ERR) 
+                               return NULL;
+               }
+               temp = (tt == tt_array)?temp:SQL_PERSIST;
+               return rel_table(sql, DDL_CREATE_TABLE, sname, t, temp); //the 
array does not differ from a table at least until this point
+       } 
+#if 0
+       else { /* [col name list] as subquery with or without data */
+               sql_rel *sq = NULL, *res = NULL;
+               dlist *as_sq = table_elements_or_subquery->data.lval;
+               dlist *column_spec = as_sq->h->data.lval;
+               symbol *subquery = as_sq->h->next->data.sym;
+               int with_data = as_sq->h->next->next->data.i_val;
+               sql_table *t = NULL; 
+
+               assert(as_sq->h->next->next->type == type_int);
+               sq = rel_selects(sql, subquery);
+               if (!sq)
+                       return NULL;
+
+               /* create table */
+               if ((t = mvc_create_table_as_subquery( sql, sq, s, name, 
column_spec, temp, commit_action)) == NULL) { 
+                       rel_destroy(sq);
+                       return NULL;
+               }
+
+               /* insert query result into this table */
+               temp = (tt == tt_table)?temp:SQL_PERSIST;
+               res = rel_table(sql, DDL_CREATE_TABLE, sname, t, temp);
+               if (with_data) {
+                       res = rel_insert(sql, res, sq);
+               } else {
+                       rel_destroy(sq);
+               }
+               return res;
+       }
+#endif
+       /*return NULL;*/ /* never reached as all branches of the above if() end 
with return ... */
+return NULL;
+}
+
 sql_rel *
 rel_create_table(mvc *sql, sql_schema *ss, int temp, char *sname, char *name, 
symbol *table_elements_or_subquery, int commit_action, char *loc)
 {
@@ -1676,6 +1763,19 @@ rel_schemas(mvc *sql, symbol *s)
                           NULL,
                           l->h->next->data.i_val);     /* drop_action */
        }       break;
+       case SQL_CREATE_ARRAY:
+       {
+               dlist *l = s->data.lval;
+               dlist *qname = l->h->next->data.lval;
+               char *sname = qname_schema(qname); //the name of the schema
+               char *name = qname_table(qname); //the name of the array
+               int temp = l->h->data.i_val; //the type of the array. For now 
there is only tt_array
+
+               //if any of the following is not true there is an error in the 
parse tree
+               assert(l->h->type == type_int); 
+               assert(l->h->next->next->next->type == type_int);
+               ret = rel_create_array(sql, cur_schema(sql), temp, sname, name, 
l->h->next->next->data.sym, l->h->next->next->next->data.i_val);
+       }       break;
        case SQL_CREATE_TABLE:
        {
                dlist *l = s->data.lval;
diff --git a/sql/server/rel_schema.h b/sql/server/rel_schema.h
--- a/sql/server/rel_schema.h
+++ b/sql/server/rel_schema.h
@@ -31,4 +31,6 @@ extern sql_rel *rel_create_table(mvc *sq
 extern sql_rel *rel_list(sql_allocator *sa, sql_rel *l, sql_rel *r);
 extern sql_table * mvc_create_table_as_subquery( mvc *sql, sql_rel *sq, 
sql_schema *s, char *tname, dlist *column_spec, int temp, int commit_action );
 
+extern sql_rel *rel_create_array(mvc *sql, sql_schema *ss, int temp, char 
*sname, char *name, symbol *table_elements_or_subquery, int commit_action);
+
 #endif /*_REL_SCHEMA_H_*/
diff --git a/sql/server/rel_semantic.c b/sql/server/rel_semantic.c
--- a/sql/server/rel_semantic.c
+++ b/sql/server/rel_semantic.c
@@ -173,6 +173,7 @@ rel_semantic(mvc *sql, symbol *s)
        case SQL_DROP_SCHEMA:
 
        case SQL_CREATE_TABLE:
+       /*SciQL*/case SQL_CREATE_ARRAY:
        case SQL_CREATE_VIEW:
        case SQL_DROP_TABLE:
        case SQL_DROP_VIEW:
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
@@ -962,7 +962,6 @@ mvc_drop_trigger(mvc *m, sql_schema *s, 
        sql_trans_drop_trigger(m->session->tr, s, tri->base.id, DROP_RESTRICT);
 }
 
-
 sql_table *
 mvc_create_table(mvc *m, sql_schema *s, const char *name, int tt, bit system, 
int persistence, int commit_action, int sz)
 {
@@ -971,7 +970,7 @@ mvc_create_table(mvc *m, sql_schema *s, 
        if (mvc_debug)
                fprintf(stderr, "#mvc_create_table %s %s %d %d %d %d\n", 
s->base.name, name, tt, system, persistence, commit_action);
 
-       if (persistence == SQL_DECLARED_TABLE && (!s || strcmp(s->base.name, 
dt_schema))) {
+       if ((persistence == SQL_DECLARED_TABLE || persistence == 
SQL_DECLARED_ARRAY) && (!s || strcmp(s->base.name, dt_schema))) {
                t = create_sql_table(m->sa, name, tt, system, persistence, 
commit_action);
                t->s = s;
        } else {
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
@@ -33,6 +33,7 @@
 #define isTempSchema(x)  (strcmp((x)->base.name, "tmp") == 0 || \
                          strcmp((x)->base.name, dt_schema) == 0)
 #define isDeclaredTable(x)  ((x)->persistence==SQL_DECLARED_TABLE)
+#define isDeclaredArray(x)  ((x)->persistence==SQL_DECLARED_ARRAY)
 
 extern int catalog_version;
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -1157,7 +1157,7 @@ create_sql_table(sql_allocator *sa, cons
 
        assert(sa);
        assert((persistence==SQL_PERSIST ||
-               persistence==SQL_DECLARED_TABLE || 
+               persistence==SQL_DECLARED_TABLE || 
persistence==SQL_DECLARED_ARRAY || 
                commit_action) && commit_action>=0);
        base_init(sa, &t->base, next_oid(), TR_NEW, name);
        t->type = type;
@@ -2032,10 +2032,10 @@ sql_trans_copy_column( sql_trans *tr, sq
 
        cs_add(&t->columns, col, TR_NEW);
 
-       if (isDeclaredTable(c->t)) 
-       if (isTable(t))
-               if (store_funcs.create_col(tr, col) == LOG_ERR)
-                       return NULL;
+       if (isDeclaredTable(c->t) || isDeclaredArray(c->t)) 
+               if (isTable(t) || isArray(t))
+                       if (store_funcs.create_col(tr, col) == LOG_ERR)
+                               return NULL;
        if (!isDeclaredTable(t))
                table_funcs.table_insert(tr, syscolumn, &col->base.id, 
col->base.name, col->type.type->sqlname, &col->type.digits, &col->type.scale, 
&t->base.id, (col->def) ? col->def : ATOMnilptr(TYPE_str), &col->null, 
&col->colnr, (col->storage_type) ? col->storage_type : ATOMnilptr(TYPE_str));
        col->base.wtime = t->base.wtime = t->s->base.wtime = tr->wtime = 
tr->wstime;
@@ -2582,7 +2582,7 @@ rollforward_create_seq(sql_trans *tr, sq
 static sql_column *
 rollforward_create_column(sql_trans *tr, sql_column *c, int mode)
 {
-       if (isTable(c->t)) {
+       if (isTable(c->t) || isArray(c->t)) {
                int p = (tr->parent == gtrans && !isTempTable(c->t));
 
                if ((p && mode == R_SNAPSHOT && 
store_funcs.snapshot_create_col(tr, c) != LOG_OK) ||
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to