Changeset: a99513637a13 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a99513637a13
Modified Files:
monetdb5/modules/mal/array.mx
sql/server/rel_schema.c
sql/sql/29_array.sql
Branch: sciql
Log Message:
First real working SciQL query :)
Different fixes to finally get a first SciQL query that really works, i.e.,
without wrong hacks:)
At least, the following queries work on jarl:
create array a1 (dimx int dimension[17:3:27], dimy int dimension [31:2:40],
dimz int dimension[0:5:19], v float default 0.43);
select * from a1;
select count(*) from a1; -- yields 80
diffs (220 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
@@ -41,10 +41,12 @@ address ARRAYseries_@1
comment "Generates a single series BAT based on range condition, repeating
each value N times and repeat the process M times.";
function series (start:@1, step:@1, stop:@1, N:int, M:int) :bat[:str,:bat];
- b1 := bat.new(:str,:bat,1);
- b2 := series_(start, step, stop, N, M);
- b3 := bat.insert(b1, "dim", b2);
- return series := b3;
+ b1 := bat.new(:str,:bat,2);
+ b2 := array.series_(start, step, stop, N, M);
+ b3 := bat.mirror(b2);
+ b4 := bat.insert(b1, "id", b3);
+ b5 := bat.insert(b4, "dimval", b2);
+ return series := b5;
end series;
@mal
@@ -71,10 +73,14 @@ address ARRAYfiller
comment "Create an array value representation of CNT items and fill it with V";
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);
- return filler := b3;
+ b1 := bat.new(:str,:bat,2);
+ b2 := array.filler_(cnt, v);
+ # TODO: why is a markH necessary here, but no in array.series?
+ b3 := algebra.markH(b2, 0@0);
+ b4 := bat.mirror(b3);
+ b5 := bat.insert(b1, "id", b4);
+ b6 := bat.insert(b5, "cellval", b3);
+ return filler := b5;
end filler;
pattern map(dims:bat[:oid,:any]...):bat[:oid,:oid]
@@ -209,10 +215,10 @@ ARRAYseries_@1(int *ret, @1 *start, @1 *
int s,g;
if ( *start < *stop && *step > 0) {
- cnt = (BUN) ((*stop - *start) / *step) * *group * *series ;
+ cnt = (BUN) ceil(((*stop * 1.0 - *start) / *step)) * *group *
*series ;
} else
if ( abs(*start) < abs(*stop) && abs(*step) > 0) {
- cnt = (BUN) ((-*stop + *start) / *step ) * *group * *series ;
+ cnt = (BUN) ceil(((-*stop * 1.0 + *start) / *step)) * *group *
*series ;
} else
throw(MAL, "array.series", "illegal range");
bn = BATnew(TYPE_void, TYPE_@1, cnt);
@@ -387,6 +393,7 @@ ARRAYfiller(Client cntxt, MalBlkPtr mb,
/* TODO: why not TYPE_void? */
if(!(bn = BATnew(TYPE_oid, getArgType(mb,pci,2), cnt)))
throw(MAL, "array.filler", MAL_MALLOC_FAIL);
+ BATseqbase(bn, 0);
bi = bat_iterator(bn);
for (i = 0; i < cnt; i++)
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
@@ -19,6 +19,7 @@
#include "monetdb_config.h"
+#include <math.h>
#include "rel_trans.h"
#include "rel_select.h"
#include "rel_updates.h"
@@ -944,7 +945,8 @@ rel_create_table(mvc *sql, sql_schema *s
sql_table *t = mvc_create_table(sql, s, name, tt, 0,
SQL_DECLARED_TABLE, commit_action, -1);
dnode *n;
dlist *columns = table_elements_or_subquery->data.lval;
- sql_rel *res = NULL;
+ sql_exp *id_l = NULL, *id_r = NULL;
+ sql_rel *res = NULL, *joinl = NULL, *joinr = NULL;
list *rp = new_exp_list(sql->sa);
node *col = NULL;
int i = 0, j = 0, cnt = 0, *N, *M;
@@ -988,17 +990,17 @@ rel_create_table(mvc *sql, sql_schema *s
atom *a_sto = atom_general(sql->sa, &sc->type,
sc->dim->stop);
switch(a_sto->data.vtype){
case TYPE_bte:
- cnt = (*(bte *)VALget(&a_sto->data) -
*(bte *)VALget(&a_sta->data)) / *(bte *)VALget(&a_ste->data); break;
+ cnt = ceil((*(bte
*)VALget(&a_sto->data) * 1.0 - *(bte *)VALget(&a_sta->data)) / *(bte
*)VALget(&a_ste->data)); break;
case TYPE_sht:
- cnt = (*(sht *)VALget(&a_sto->data) -
*(sht *)VALget(&a_sta->data)) / *(sht *)VALget(&a_ste->data); break;
+ cnt = ceil((*(sht
*)VALget(&a_sto->data) * 1.0 - *(sht *)VALget(&a_sta->data)) / *(sht
*)VALget(&a_ste->data)); break;
case TYPE_int:
- cnt = (*(int *)VALget(&a_sto->data) -
*(int *)VALget(&a_sta->data)) / *(int *)VALget(&a_ste->data); break;
+ cnt = ceil((*(int
*)VALget(&a_sto->data) * 1.0 - *(int *)VALget(&a_sta->data)) / *(int
*)VALget(&a_ste->data)); break;
case TYPE_flt:
- cnt = (*(flt *)VALget(&a_sto->data) -
*(flt *)VALget(&a_sta->data)) / *(flt *)VALget(&a_ste->data); break;
+ cnt = ceil((*(flt
*)VALget(&a_sto->data) - *(flt *)VALget(&a_sta->data)) / *(flt
*)VALget(&a_ste->data)); break;
case TYPE_dbl:
- cnt = (*(dbl *)VALget(&a_sto->data) -
*(dbl *)VALget(&a_sta->data)) / *(dbl *)VALget(&a_ste->data); break;
+ cnt = ceil((*(dbl
*)VALget(&a_sto->data) - *(dbl *)VALget(&a_sta->data)) / *(dbl
*)VALget(&a_ste->data)); break;
case TYPE_lng:
- cnt = (*(lng *)VALget(&a_sto->data) -
*(lng *)VALget(&a_sta->data)) / *(lng *)VALget(&a_ste->data); break;
+ cnt = ceil((*(lng
*)VALget(&a_sto->data) * 1.0 - *(lng *)VALget(&a_sta->data)) / *(lng
*)VALget(&a_ste->data)); break;
default: /* should not reach here */
GDKfree(N); GDKfree(M);
return sql_error(sql, 02, "CREATE
ARRAY: unsupported data type \"%s\"", sc->type.type->sqlname);
@@ -1017,8 +1019,9 @@ rel_create_table(mvc *sql, sql_schema *s
/* create and fill all columns */
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);
- sql_exp *e = NULL;
+ list *args = new_exp_list(sql->sa), *col_exps =
new_exp_list(sql->sa);
+ sql_exp *e = NULL, *func_exp = NULL;
+ sql_subtype *oid_tpe = sql_bind_localtype("oid");
if (sc->dim){
/* TODO: can we avoid computing these
'atom_general' twice? */
@@ -1027,7 +1030,17 @@ rel_create_table(mvc *sql, sql_schema *s
append(args, exp_atom(sql->sa,
atom_general(sql->sa, &sc->type, 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))));
+ func_exp = exp_op(sql->sa, args,
sql_bind_func_(sql->sa, sql->session->schema, "array_series",
exps_subtype(args)));
+ /* TODO: what are the correct values for card
and intern? */
+ if (!id_l) {
+ id_l = exp_column(sql->sa,
sc->base.name, "id", oid_tpe, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0);
+ append(col_exps, id_l);
+ } else {
+ id_r = exp_column(sql->sa,
sc->base.name, "id", oid_tpe, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0);
+ append(col_exps, id_r);
+ }
+ append(col_exps, exp_column(sql->sa,
sc->base.name, "dimval", &sc->type, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0));
+ append(rp, exp_column(sql->sa, sc->base.name,
"dimval", &sc->type, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0));
i++;
} else {
if (sc->def) {
@@ -1042,15 +1055,33 @@ rel_create_table(mvc *sql, sql_schema *s
}
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))));
+ func_exp = exp_op(sql->sa, args,
sql_bind_func_(sql->sa, sql->session->schema, "array_filler",
exps_subtype(args)));
+ if (!id_l) {
+ id_l = exp_column(sql->sa,
sc->base.name, "id", oid_tpe, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0);
+ append(col_exps, id_l);
+ } else {
+ id_r = exp_column(sql->sa,
sc->base.name, "id", oid_tpe, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0);
+ append(col_exps, id_r);
+
+ }
+ append(col_exps, exp_column(sql->sa,
sc->base.name, "cellval", &sc->type, CARD_MULTI, (!sc->dim && !sc->def)?1:0,
0));
+ append(rp, exp_column(sql->sa, sc->base.name,
"cellval", &sc->type, CARD_MULTI, (!sc->dim && !sc->def)?1:0, 0));
}
+ if (!joinl) {
+ joinl = rel_table_func(sql->sa, NULL, func_exp,
col_exps);
+ } else {
+ joinr = rel_table_func(sql->sa, NULL, func_exp,
col_exps);
+ joinl = rel_crossproduct(sql->sa, joinl, joinr,
op_join);
+ rel_join_add_exp(sql->sa, joinl,
exp_compare(sql->sa, id_l, id_r, cmp_equal));
+ }
+
}
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);
}
res = rel_table(sql, DDL_CREATE_TABLE, sname, t, temp);
- return rel_insert(sql, res, rel_project(sql->sa, NULL, rp));
+ return rel_insert(sql, res, rel_project(sql->sa, joinl, rp));
} else { /* [col name list] as subquery with or without data */
/* TODO: handle create_array_as_subquery??? */
sql_rel *sq = NULL, *res = NULL;
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
@@ -23,27 +23,28 @@
-- TODO: DATE, TIME, TIMESTAMP, CHAR and VARCHAR not supported yet
-- TODO: should we deal with TINYINT, SMALLINT separately?
-create function array_series("start" integer, step integer, stop integer, N
integer, M integer) returns table (dim integer)
+create function array_series("start" integer, step integer, stop integer, N
integer, M integer) returns table (id int, dimval integer)
external name "array".series;
-create function array_series("start" bigint, step bigint, stop bigint, N
integer, M integer) returns table (dim bigint)
+create function array_series("start" bigint, step bigint, stop bigint, N
integer, M integer) returns table (id bigint, dimval bigint)
external name "array".series;
-create function array_series("start" float, step float, stop float, N integer,
M integer) returns table (dim float)
+create function array_series("start" float, step float, stop float, N integer,
M integer) returns table (id bigint, dimval float)
external name "array".series;
-create function array_filler(cnt bigint, val integer) returns table (vals
integer)
+create function array_filler(cnt bigint, val integer) returns table (id
bigint, cellval integer)
external name "array".filler;
-create function array_filler(cnt bigint, val bigint) returns table (vals
bigint)
+create function array_filler(cnt bigint, val bigint) returns table (id bigint,
cellval bigint)
external name "array".filler;
-create function array_filler(cnt bigint, val float) returns table (vals float)
- external name "array".filler;
-create function array_filler(cnt bigint, val date) returns table (vals date)
- external name "array".filler;
-create function array_filler(cnt bigint, val time) returns table (vals time)
- external name "array".filler;
-create function array_filler(cnt bigint, val timestamp) returns table (vals
timestamp)
- external name "array".filler;
-create function array_filler(cnt bigint, val char(1024)) returns table (vals
char(1024))
- external name "array".filler;
-create function array_filler(cnt bigint, val varchar(1024)) returns table
(vals varchar(1024))
+create function array_filler(cnt bigint, val float) returns table (id bigint,
cellval float)
external name "array".filler;
+--create function array_filler(cnt bigint, val date) returns table (vals date)
+-- external name "array".filler;
+--create function array_filler(cnt bigint, val time) returns table (vals time)
+-- external name "array".filler;
+--create function array_filler(cnt bigint, val timestamp) returns table (vals
timestamp)
+-- external name "array".filler;
+--create function array_filler(cnt bigint, val char(1024)) returns table (vals
char(1024))
+-- external name "array".filler;
+--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