Changeset: 04718e18ded8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=04718e18ded8
Modified Files:
monetdb5/modules/mal/array.mx
sql/scripts/29_array.sql
sql/server/rel_select.c
sql/test/sciql/Tests/07_tiling_01.sql
sql/test/sciql/Tests/07_tiling_01.stable.err
sql/test/sciql/Tests/07_tiling_01.stable.out
Branch: sciql
Log Message:
The first working SciQL GROUP BY query
array.mx:
yet another controled hack: add the BAT version of the SciQL AGGR functions
rel_select.c:
get/set correct types for the parameters so that sql_bind_func can find the
function.
07_tiling_01.*
the first working tiling query and its stable.{out,err}
diffs (truncated from 370 to 300 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
@@ -88,6 +88,19 @@ pattern avg(values:bat[:oid,:any_1], any
address ARRAYtilesAvg
comment "Construct the average over all tiles";
+module batarray;
+
+# The BAT version of the AGGR functions over array tiles
+pattern sum(values:bat[:oid,:any_1], any...):bat[:oid,:any_1]
+address ARRAYtilesSum
+comment "Construct the sum over all tiles";
+
+pattern avg(values:bat[:oid,:any_1], any...):bat[:oid,:any_1]
+address ARRAYtilesAvg
+comment "Construct the average over all tiles";
+
+module array;
+
# unused functions
pattern map(dims:bat[:oid,:any]...):bat[:oid,:oid]
diff --git a/sql/scripts/29_array.sql b/sql/scripts/29_array.sql
--- a/sql/scripts/29_array.sql
+++ b/sql/scripts/29_array.sql
@@ -50,11 +50,11 @@ create function array_filler(cnt bigint,
create function array_filler(cnt bigint, val blob) returns table (id
bigint, vals blob) external name "array".filler_;
create function array_filler(cnt bigint, val clob) returns table (id
bigint, vals clob) external name "array".filler_;
-create function array_tavg(val int, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (a double) external name
"array".avg;
-create function array_tavg(val real, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (a real) external name
"array".avg;
-create function array_tavg(val double, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (a double) external name
"array".avg;
+create function array_avg(val int, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (a double) external name
"array".avg;
+create function array_avg(val real, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (a real) external name
"array".avg;
+create function array_avg(val double, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (a double) external name
"array".avg;
-create function array_tsum(val int, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (s bigint) external name
"array".sum;
-create function array_tsum(val real, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (s double) external name
"array".sum;
-create function array_tsum(val double, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (s double) external name
"array".sum;
+create function array_sum(val int, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (s bigint) external name
"array".sum;
+create function array_sum(val real, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (s double) external name
"array".sum;
+create function array_sum(val double, dim1 int, offsets1 int, size1 int, dim2
int, offsets2 int, size2 int) returns table (s double) external name
"array".sum;
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -479,7 +479,7 @@ rel_arrayslice(mvc *sql, sql_table *t, c
/* build the slc_val expression, which is going to compute a
list of to be sliced dimensional values. */
idx_term = idx_exp->data.lval->h;
- if(idx_exp->data.lval->cnt == 1) {
+ if (idx_exp->data.lval->cnt == 1) {
slc_val = rel_check_type(sql, &col->type,
rel_value_exp(sql, &rel, idx_term->data.sym, sql_where, ek), type_cast);
} else {
/* If the value of start/step/stop is omitted, we get
its value from the dimension definition.
@@ -493,7 +493,7 @@ rel_arrayslice(mvc *sql, sql_table *t, c
exp_atom(sql->sa, atom_general(sql->sa,
&col->type, col->dim->start)));
- if(idx_exp->data.lval->cnt == 2) {
+ if (idx_exp->data.lval->cnt == 2) {
append(args, exp_atom(sql->sa,
atom_general(sql->sa, &col->type, col->dim->step)));
} else {
idx_term = idx_term->next;
@@ -1897,7 +1897,7 @@ rel_arraytiling(mvc *sql, sql_rel **rel,
/* need the base array for the dimension info. */
if (sname && !(s=mvc_bind_schema(sql,sname)))
return sql_error(sql, 02, "3F000!SELECT: no such schema '%s'",
sname);
- if(!s) s = cur_schema(sql);
+ if (!s) s = cur_schema(sql);
if (!(a = mvc_bind_table(sql, s, aname)))
return sql_error(sql, 02, "42S02!SELECT: no such array
'%s.%s'", s->base.name, aname);
if (a->ndims > 2)
@@ -3889,7 +3889,7 @@ rel_nop(mvc *sql, sql_rel **rel, symbol
* | project (
|
* | | project (
|
* | | | array(sys.a) [ a.x, a.y, a.v, a.%TID% NOT NULL ] COUNT
|
- * | | ) [ a.x, a.y, sys.array_tiling_sum(a.v, a.x, offset_x, size_x, a.y,
offset_y, size_y) as L6 ] |
+ * | | ) [ a.x, a.y, sys.array_sum(a.v, a.x, offset_x, size_x, a.y, offset_y,
size_y) as L6 ] |
* | ) [ L6 ]
|
*
+---------------------------------------------------------------------------------------------------+
*/
@@ -3902,7 +3902,7 @@ _rel_tiling_aggr(mvc *sql, sql_rel **rel
sql_subfunc *sf = NULL;
sql_subtype st_int, st_flt;
list *aggr_args = new_exp_list(sql->sa), *aggr_types =
new_subtype_list(sql->sa);
- char *aggrstr2 = SA_NEW_ARRAY(sql->sa, char, strlen("array_t") +
strlen(aggrstr) + 1);
+ char *aggrstr2 = SA_NEW_ARRAY(sql->sa, char, strlen("array_") +
strlen(aggrstr) + 1);
node *cn = NULL;
sql_table *t = (sql_table*)((sql_rel*)groupby->l)->l;
int i = 0, j = 0, *dsize = NULL;
@@ -3910,7 +3910,7 @@ _rel_tiling_aggr(mvc *sql, sql_rel **rel
(void)distinct;
- strcpy(aggrstr2, "array_t\0");
+ strcpy(aggrstr2, "array_\0");
strcat(aggrstr2, aggrstr);
if (!sym) { /* AGGR(*) case, but only "count" is allowed */
@@ -3921,10 +3921,11 @@ _rel_tiling_aggr(mvc *sql, sql_rel **rel
sql_error(sql, 02, "%s: '%s(*)' not implemented for array
tiles", toUpperCopy(aggrstr2, aggrstr), aggrstr);
return NULL;
} else {
- if(sym->token != SQL_COLUMN) {
+ if (sym->token != SQL_COLUMN) {
return sql_error(sql, 02, "SELECT: expressions other
than <column name> not supported in tiling ranges");
}
exp = rel_column_ref(sql, rel, sym, f);
+ append(groupby->exps, exp);
append(aggr_args, exp);
append(aggr_types, exp_subtype(exp));
}
@@ -3987,36 +3988,43 @@ _rel_tiling_aggr(mvc *sql, sql_rel **rel
*/
nrep = SA_NEW_ARRAY(sql->sa, sql_exp*, t->ndims);
ngrp = SA_NEW_ARRAY(sql->sa, sql_exp*, t->ndims);
- if(!nrep || !ngrp) {
+ if (!nrep || !ngrp) {
return sql_error(sql, 02, "SELECT: failed to allocate space");
}
sql_find_subtype(&st_int, "int", 9, 0);
sql_find_subtype(&st_flt, "double", 23, 0);
- for(i = 0; i < t->ndims; i++) nrep[i] = ngrp[i] = exp_atom_int(sql->sa,
1);
+ for (i = 0; i < t->ndims; i++)
+ nrep[i] = ngrp[i] = exp_atom_int(sql->sa, 1);
for (i = 0; i < t->ndims; i++){
list *ceil_args = new_exp_list(sql->sa);
-
- exp = rel_check_type(sql, &st_flt, os_sto[i], type_cast);
- if(!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_sub", exp_subtype(exp), exp_subtype(exp), F_FUNC)))
+ sql_subtype ost_sta, ost_sto;
+
+ ost_sta = *exp_subtype(os_sta[i]);
+ ost_sto = *exp_subtype(os_sto[i]);
+
+ if (!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_sub", &st_flt, &st_flt, F_FUNC)))
return sql_error(sql, 02, "failed to bind to the SQL
function \"-\"");
- /* FIXME: why do I need this extra rel_check_type? */
- append(ceil_args, exp_binop(sql->sa, exp, rel_check_type(sql,
&st_flt, os_sta[i], type_cast), sf));
-
- if(!(sf = sql_bind_func_(sql->sa, sql->session->schema, "ceil",
exps_subtype(ceil_args), F_FUNC)))
+ append(ceil_args, exp_binop(sql->sa,
+ rel_check_type(sql, &st_flt, os_sto[i],
type_cast),
+ rel_check_type(sql, &st_flt, os_sta[i],
type_cast), sf));
+ os_sta[i] = rel_check_type(sql, &ost_sta, os_sta[i], type_cast);
+ os_sto[i] = rel_check_type(sql, &ost_sto, os_sto[i], type_cast);
+
+ if (!(sf = sql_bind_func_(sql->sa, sql->session->schema,
"ceil", exps_subtype(ceil_args), F_FUNC)))
return sql_error(sql, 02, "failed to bind to the SQL
function \"ceil\"");
exp = rel_check_type(sql, &st_int, exp_op(sql->sa, ceil_args,
sf), type_cast);
- if(!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_div", exp_subtype(exp), exp_subtype(os_ste[i]), F_FUNC)))
+ if (!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_div", exp_subtype(exp), exp_subtype(os_ste[i]), F_FUNC)))
return sql_error(sql, 02, "failed to bind to the SQL
function \"/\"");
exp = exp_binop(sql->sa, exp, os_ste[i], sf);
for (j = 0; j < i; j++) {
- if(!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_mul", exp_subtype(nrep[j]), exp_subtype(exp), F_FUNC)))
+ if (!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_mul", exp_subtype(nrep[j]), exp_subtype(exp), F_FUNC)))
return sql_error(sql, 02, "failed to bind to
the SQL function \"*\"");
nrep[j] = exp_binop(sql->sa, nrep[j], exp, sf);
}
for (j = t->ndims-1; j > i; j--) {
- if(!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_mul", exp_subtype(ngrp[j]), exp_subtype(exp), F_FUNC)))
+ if (!(sf = sql_bind_func(sql->sa, sql->session->schema,
"sql_mul", exp_subtype(ngrp[j]), exp_subtype(exp), F_FUNC)))
return sql_error(sql, 02, "failed to bind to
the SQL function \"*\"");
ngrp[j] = exp_binop(sql->sa, ngrp[j], exp, sf);
}
@@ -4032,7 +4040,7 @@ _rel_tiling_aggr(mvc *sql, sql_rel **rel
append(srs_args, os_sto[i]);
append(srs_args, nrep[i]);
append(srs_args, ngrp[i]);
- if(!(sf = sql_bind_func_(sql->sa, sql->session->schema,
"array_series1", exps_subtype(srs_args), F_FUNC)))
+ if (!(sf = sql_bind_func_(sql->sa, sql->session->schema,
"array_series1", exps_subtype(srs_args), F_FUNC)))
return sql_error(sql, 02, "failed to bind to the SQL
function \"array_series1\"");
append(aggr_args, dim[i]);
@@ -4048,15 +4056,20 @@ _rel_tiling_aggr(mvc *sql, sql_rel **rel
append(aggr_args, exp);
append(aggr_types, exp_subtype(exp));
}
- if(!(sf = sql_bind_func_(sql->sa, sql->session->schema, aggrstr2,
aggr_types, F_FUNC)))
+ if (!(sf = sql_bind_func_(sql->sa, sql->session->schema, aggrstr2,
aggr_types, F_FUNC)))
return sql_error(sql, 02, "failed to bind to the SQL function
\"%s\"", aggrstr2);
exp = exp_op(sql->sa, aggr_args, sf);
+ if (!exp->name) {
+ char name[16], *nme = NULL;
+ nme = number2name(name, 16, ++sql->label);
+ exp_setname(sql->sa, exp, NULL, nme);
+ }
+ append(groupby->exps, exp);
/* HACK: secretly change the groupby into a project, and wipe out all
traces of the AGGR */
groupby->op = op_project;
groupby->r = NULL;
groupby->card = CARD_MULTI;
(*rel)->card = CARD_MULTI;
- rel_project_add_exp(sql, groupby, exp);
return exp;
}
@@ -4493,13 +4506,13 @@ rel_group_by(mvc *sql, sql_rel *rel, sym
list *es = NULL;
if (grp->token == SQL_ARRAY_DIM_SLICE) {
- if(!(es = rel_arraytiling(sql, &rel, grp, f)))
+ if (!(es = rel_arraytiling(sql, &rel, grp, f)))
return NULL;
/* FIXME: shouldn't we do the same error checks as the
case of normal GROUP BY below? */
exps = list_merge(exps, es, (fdup)NULL);
found_sgb += 1;
- if(o->next->type == type_int) {
- if(o->next->data.i_val) {
+ if (o->next->type == type_int) {
+ if (o->next->data.i_val) {
/* TODO: how do we pass this
information? */
return sql_error(sql, 02, "SELECT:
DISTINCT array tiles not supported yet\n");
}
diff --git a/sql/test/sciql/Tests/07_tiling_01.sql
b/sql/test/sciql/Tests/07_tiling_01.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/sciql/Tests/07_tiling_01.sql
@@ -0,0 +1,4 @@
+create array a (x int dimension[4], y int dimension[4], v float default 37);
+select x, y, avg(v) from a group by a[x-1:x+2][y-2:y+1];
+select x, y, sum(v) from a group by a[x-1:x+2][y-2:y+1];
+
diff --git a/sql/test/sciql/Tests/07_tiling_01.stable.err
b/sql/test/sciql/Tests/07_tiling_01.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/sciql/Tests/07_tiling_01.stable.err
@@ -0,0 +1,37 @@
+stderr of test '07_tiling_01` in directory 'test/sciql` itself:
+
+
+# 14:43:17 >
+# 14:43:17 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"gdk_dbfarm=/export/scratch0/zhang/monet-install/sciql/debug/var/MonetDB"
"--set" "mapi_open=true" "--set" "mapi_port=39237" "--set" "monet_prompt="
"--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_test_sciql"
"--set" "mal_listing=0"
+# 14:43:17 >
+
+# builtin opt gdk_dbname = demo
+# builtin opt gdk_dbfarm =
/export/scratch0/zhang/monet-install/sciql/debug/var/monetdb5/dbfarm
+# builtin opt gdk_debug = 0
+# builtin opt gdk_alloc_map = no
+# builtin opt gdk_vmtrim = yes
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt gdk_dbfarm =
/export/scratch0/zhang/monet-install/sciql/debug/var/MonetDB
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 39237
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbname = mTests_test_sciql
+# cmdline opt mal_listing = 0
+
+# 14:43:17 >
+# 14:43:17 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=jarl"
"--port=39237"
+# 14:43:17 >
+
+
+# 14:43:18 >
+# 14:43:18 > "Done."
+# 14:43:18 >
+
diff --git a/sql/test/sciql/Tests/07_tiling_01.stable.out
b/sql/test/sciql/Tests/07_tiling_01.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/sciql/Tests/07_tiling_01.stable.out
@@ -0,0 +1,95 @@
+stdout of test '07_tiling_01` in directory 'test/sciql` itself:
+
+
+# 14:43:17 >
+# 14:43:17 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"gdk_dbfarm=/export/scratch0/zhang/monet-install/sciql/debug/var/MonetDB"
"--set" "mapi_open=true" "--set" "mapi_port=39237" "--set" "monet_prompt="
"--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_test_sciql"
"--set" "mal_listing=0"
+# 14:43:17 >
+
+# MonetDB 5 server v11.8.0
+# This is an unreleased version
+# Serving database 'mTests_test_sciql', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 7.749 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2012 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://jarl.ins.cwi.nl:39237/
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list