Changeset: 22d2f8aad186 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=22d2f8aad186
Modified Files:
monetdb5/modules/mal/array.mx
sql/server/rel_schema.c
sql/sql/29_array.sql
Branch: sciql
Log Message:
Get MAL plan generation working for some basic CREATE ARRAY statements.
- rel_schema.c: compute N and M for multi-dimensional arrays as parameter for
array.series; add call to array.filler to fill the non-dimensional attributes
with default values
- array.mx + 29_array.sql: OID is not a valid SQL type, replace it with BIGINT.
diffs (161 lines):
diff --git a/monetdb5/modules/mal/array.mx b/monetdb5/modules/mal/array.mx
--- a/monetdb5/modules/mal/array.mx
+++ b/monetdb5/modules/mal/array.mx
@@ -66,11 +66,11 @@
address ARRAYfiller_bat
comment "Create an array value representation described by a series column and
fill it with V";
-pattern filler_(cnt:oid, v:any_2):bat[:oid,:any_2]
+pattern filler_(cnt:lng, v:any_2):bat[:oid,:any_2]
address ARRAYfiller
comment "Create an array value representation of CNT items and fill it with V";
-function filler(cnt:oid, v:any_2):bat[:str,:bat];
+function filler(cnt:lng, v:any_2):bat[:str,:bat];
b1 := bat.new(:str,:bat,1);
b2 := filler_(cnt, v);
b3 := bat.insert(b1, "vals", b2);
@@ -378,7 +378,7 @@
BAT *bn;
BATiter bi;
int *ret = (int*) getArgReference(stk,pci,0);
- oid i = 0, cnt = *(oid*) getArgReference(stk,pci,1);
+ lng i = 0, cnt = *(lng *) getArgReference(stk,pci,1);
void *val = (void*) getArgReference(stk,pci,2);
(void) cntxt;
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
@@ -884,7 +884,6 @@
((temp == SQL_MERGE_TABLE)?tt_merge_table:
((temp == SQL_ARRAY)? tt_array:tt_table));
char *t_a = (tt == tt_array)?"ARRAY":"TABLE";
- /* TODO: compute 'fixed' somewhere somehow */
(void)create;
if (sname && !(s = mvc_bind_schema(sql, sname)))
@@ -930,7 +929,7 @@
temp = (tt == tt_table || tt == tt_array)?temp:SQL_PERSIST;
/* For unbounded arrays we don't immediately create the columns
*/
if ((tt == tt_table) || (tt == tt_array && !t->fixed)) {
- /* TODO: is DDL_CREATE_TABLE sufficient for arrays? */
+ /* TODO: DDL_CREATE_TABLE looks sufficient for arrays
for now */
return rel_table(sql, DDL_CREATE_TABLE, sname, t, temp);
} else { /* For fixed arrays, we immediately create and fill in
BATs
for dimensions with dimension values,
and for non-dim.
@@ -938,23 +937,77 @@
sql_rel *res = NULL;
list *rp = new_exp_list(sql->sa);
node *col = NULL;
+ int i = 0, j = 0, cnt = 0, *N, *M;
+ lng cntall = 1;
assert(tt == tt_array && t->fixed);
- for (col = t->columns.set->h; col; col = col->next){
+ N = GDKmalloc(sizeof(lng) * t->ndims);
+ M = GDKmalloc(sizeof(lng) * t->ndims);
+ if(!N || !M) {
+ if(N) GDKfree(N);
+ if(M) GDKfree(M);
+ return sql_error(sql, 02, "CREATE ARRAY: failed
to allocate space");
+ }
+ for(i = 0; i < t->ndims; i++) N[i] = M[i] = 1;
+
+ for (col = t->columns.set->h, i = 0; col; col =
col->next){
+ sql_column *sc = (sql_column *) col->data;
+ if (sc->dim){
+ cnt = (*sc->dim->stop -
*sc->dim->start) / *sc->dim->step;
+ for (j = 0; j < i; j++) N[j] = N[j] *
cnt;
+ for (j = t->ndims; j > i; j--) M[j] =
M[j] * cnt;
+ cntall *= cnt;
+ i++;
+ }
+ }
+ if (i != t->ndims) {
+ GDKfree(N); GDKfree(M);
+ return sql_error(sql, 02, "CREATE ARRAY:
expected number of dimension columns (%d) does not match actual numbre of
dimension columns (%d)", t->ndims, i);
+ }
+
+ /* Create columns for the dimentional attributes */
+ for (col = t->columns.set->h, i = 0; col; col =
col->next){
sql_column *sc = (sql_column *) col->data;
list *args = new_exp_list(sql->sa);
if (sc->dim){
append(args, exp_atom_lng(sql->sa,
*sc->dim->start));
append(args, exp_atom_lng(sql->sa,
*sc->dim->step));
append(args, exp_atom_lng(sql->sa,
*sc->dim->stop));
- /* TODO: compute the 'N' and 'M' */
- append(args, exp_atom_int(sql->sa, 1));
- append(args, exp_atom_int(sql->sa,
*sc->dim->stop));
-
+ append(args, exp_atom_int(sql->sa,
N[i]));
+ append(args, exp_atom_int(sql->sa,
M[i]));
append(rp, exp_op(sql->sa, args,
sql_bind_func_(sql->sa, sql->session->schema, "array_series",
exps_subtype(args))));
+ i++;
}
}
+ if (i != t->ndims) {
+ GDKfree(N); GDKfree(M);
+ return sql_error(sql, 02, "CREATE ARRAY:
expected number of dimension columns (%d) does not match actual numbre of
dimension columns (%d)", t->ndims, i);
+ }
+
+ /* Create columns for the non-dimentional attributes */
+ for (col = t->columns.set->h, i = 0; col; col =
col->next){
+ sql_column *sc = (sql_column *) col->data;
+ list *args = new_exp_list(sql->sa);
+ if (!sc->dim){
+ sql_exp *e = NULL;
+
+ if (sc->def) {
+ char *q = sql_message("select
%s;", sc->def);
+ e = rel_parse_val(sql, q,
sql->emode);
+ _DELETE(q);
+ if (!e || (e =
rel_check_type(sql, &sc->type, e, type_equal)) == NULL)
+ return NULL;
+ } else {
+ atom *a = atom_general(sql->sa,
&sc->type, NULL);
+ e = exp_atom(sql->sa, a);
+ }
+ append(args, exp_atom_lng(sql->sa,
cntall));
+ append(args, e);
+ append(rp, exp_op(sql->sa, args,
sql_bind_func_(sql->sa, sql->session->schema, "array_filler",
exps_subtype(args))));
+ }
+ }
+
res = rel_table(sql, DDL_CREATE_TABLE, sname, t, temp);
return rel_insert(sql, res, rel_project(sql->sa, NULL,
rp));
}
diff --git a/sql/sql/29_array.sql b/sql/sql/29_array.sql
--- a/sql/sql/29_array.sql
+++ b/sql/sql/29_array.sql
@@ -30,20 +30,20 @@
create function array_series("start" float, step float, stop float, N integer,
M integer) returns table (dim float)
external name "array".series;
-create function array_filler(cnt oid, val integer) returns table (vals integer)
+create function array_filler(cnt bigint, val integer) returns table (vals
integer)
external name "array".filler;
-create function array_filler(cnt oid, val bigint) returns table (vals bigint)
+create function array_filler(cnt bigint, val bigint) returns table (vals
bigint)
external name "array".filler;
-create function array_filler(cnt oid, val float) returns table (vals float)
+create function array_filler(cnt bigint, val float) returns table (vals float)
external name "array".filler;
-create function array_filler(cnt oid, val date) returns table (vals date)
+create function array_filler(cnt bigint, val date) returns table (vals date)
external name "array".filler;
-create function array_filler(cnt oid, val time) returns table (vals time)
+create function array_filler(cnt bigint, val time) returns table (vals time)
external name "array".filler;
-create function array_filler(cnt oid, val timestamp) returns table (vals
timestamp)
+create function array_filler(cnt bigint, val timestamp) returns table (vals
timestamp)
external name "array".filler;
-create function array_filler(cnt oid, val char(1024)) returns table (vals
char(1024))
+create function array_filler(cnt bigint, val char(1024)) returns table (vals
char(1024))
external name "array".filler;
-create function array_filler(cnt oid, val varchar(1024)) returns table (vals
varchar(1024))
+create function array_filler(cnt bigint, val varchar(1024)) returns table
(vals varchar(1024))
external name "array".filler;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list