Changeset: 1c9e61f1cde6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c9e61f1cde6
Modified Files:
        sql/server/rel_select.c
Branch: sciql
Log Message:

Some progress in Part 2 of SciQL group by.

- adapted the code to build parameter expressions for the SQL 'array_t'AGGR 
functions.
- extended rel_arraytiling to also handle the case <index term>:<index 
term>:<index term>

Code only compiles, to be tested...


diffs (truncated from 461 to 300 lines):

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
@@ -20,6 +20,7 @@
 
 #include "monetdb_config.h"
 #include "rel_select.h"
+#include <math.h> /* for ceil() */
 #include "sql_semantic.h"      /* TODO this dependency should be removed, move
                                   the dependent code into sql_mvc */
 #include "sql_privileges.h"
@@ -1866,11 +1867,11 @@ check_tiling_dimension(mvc *sql, char *d
 static list *
 rel_arraytiling(mvc *sql, sql_rel **rel, symbol *tile_def, int f)
 {
-       list *exps = new_exp_list(sql->sa);
+       list *exps = new_exp_list(sql->sa), *offsets = NULL;
        dlist *qname = NULL, *idx_exps = NULL;
        char *sname = NULL, *aname = NULL, *opnm = NULL;
        dnode *n =  NULL;
-       symbol *tstt = NULL, *tstp =  NULL, *opl = NULL, *opr = NULL;
+       symbol *sym_tsta = NULL, *sym_tsto =  NULL, *opl = NULL, *opr = NULL;
        sql_schema *s = NULL;
        sql_table *a = NULL;
 
@@ -1904,42 +1905,40 @@ rel_arraytiling(mvc *sql, sql_rel **rel,
 
        idx_exps = tile_def->data.lval->h->next->data.lval;
        if (dlist_length(idx_exps) > a->ndims)
-               /* FIXME: why a->ndims == 0 ???!!! */
-               /* return sql_error(sql, 02, "SELECT: #dimensions (%d) in array 
tiling larger than #dimensions (%d) in the array", dlist_length(idx_exps), 
a->ndims); */
+               return sql_error(sql, 02, "SELECT: #dimensions (%d) in array 
tiling larger than #dimensions (%d) in the array", dlist_length(idx_exps), 
a->ndims);
        if (dlist_length(idx_exps) > 2)
                return sql_error(sql, 02, "SELECT: TODO: array tiling over >2 
dimensions");
        for (n = idx_exps->h; n; n = n->next) {
-               sql_exp *exp = NULL, *offset_stt = NULL, *offset_stp = NULL;
+               sql_exp *exp = NULL, *exp_os_sta = NULL, *exp_os_ste = NULL, 
*exp_os_sto = NULL;
                sql_column *dim = NULL;
                exp_kind ek = {type_value, card_value, FALSE};
-               list *offsets = new_exp_list(sql->sa);
+               offsets = new_exp_list(sql->sa);
 
                assert(n->type == type_list);
-               tstt = n->data.lval->h->data.sym;
-
-               switch (dlist_length(n->data.lval)) {
-               case 1:  /* <index_term> */
-                       switch (tstt->token) {
+               /* The first is always the start of the range, to handle the 
first 'index_term':
+                * 1) extract and bind the dimension, which also checks if the
+                *    dimension exists in the array 'aname';
+                * 2) extract the start-offset expression from the 'index_term',
+                *    create an exp_atom with "0" if not specified (case
+                *    SQL_COLUMN), and append it to 'exp->f'.
+                */
+               sym_tsta = n->data.lval->h->data.sym;
+               switch (sym_tsta->token) {
                        case SQL_COLUMN: /* '<column>' */
-                               if (!(exp = get_tiling_dimension(sql, *rel, 
aname, tstt, f)))
+                               if (!(exp = get_tiling_dimension(sql, *rel, 
aname, sym_tsta, f)))
                                        return NULL;
                                if (!(dim = get_dimension(sql, a, exp->name)))
                                        return NULL;
-                               /* array tiling range start */
-                               append(offsets, exp_atom(sql->sa, 
atom_general(sql->sa, &dim->type, "0")));
-                               /* array tiling range stop, which, in case of a 
single <index_term>, is just '1' to make the range only include '0' */
-                               append(offsets, exp_atom(sql->sa, 
atom_general(sql->sa, &dim->type, "1")));
-                               /* use the free 'f' in e_column to pass the 
tiling ranges */
-                               exp->f = offsets;
+                               exp_os_sta = exp_atom(sql->sa, 
atom_general(sql->sa, &dim->type, "0"));
                                break;
                        case SQL_BINOP: /* '<column> <BINOP> <exp>' or '<exp> 
<BINOP> <column>' */
-                               /* tstt->data.lval->h: a list of a single 
string, operator name
-                                * tstt->data.lval->h->next: the symbol of the 
left operand
-                                * tstt->data.lval->h->next->next: the symbol 
of the right operand
+                               /* sym_tsta->data.lval->h: a list of a single 
string, operator name
+                                * sym_tsta->data.lval->h->next: the symbol of 
the left operand
+                                * sym_tsta->data.lval->h->next->next: the 
symbol of the right operand
                                 */
-                               opnm = 
tstt->data.lval->h->data.lval->h->data.sval;
-                               opl = tstt->data.lval->h->next->data.sym;
-                               opr = tstt->data.lval->h->next->next->data.sym;
+                               opnm = 
sym_tsta->data.lval->h->data.lval->h->data.sval;
+                               opl = sym_tsta->data.lval->h->next->data.sym;
+                               opr = 
sym_tsta->data.lval->h->next->next->data.sym;
                                /* the <exp> could also be a SQL_COLUMN, but 
then opl->data.sym->data.lval->h->type == type_int */
                                if (opl->token == SQL_COLUMN && 
opl->data.lval->h->type == type_string) { /* '<column> +/- <exp>' */
                                        if (!(exp = get_tiling_dimension(sql, 
*rel, aname, opl, f)))
@@ -1947,64 +1946,65 @@ rel_arraytiling(mvc *sql, sql_rel **rel,
                                        if (!(dim = get_dimension(sql, a, 
exp->name)))
                                                return NULL;
                                        if (is_addition(opnm)) {
-                                               offset_stt = 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast);
+                                               exp_os_sta = 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast);
                                        } else if (is_substraction(opnm)){
-                                               offset_stt = exp_unop(sql->sa, 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast), sql_bind_func(sql->sa, sql->session->schema, "sql_neg", &dim->type, 
NULL, F_FUNC));
+                                               exp_os_sta = exp_unop(sql->sa, 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast), sql_bind_func(sql->sa, sql->session->schema, "sql_neg", &dim->type, 
NULL, F_FUNC));
                                        } else {
                                                return sql_error(sql, 02, 
"SELECT: binary expressions other than '+' and '-' in array tiling offset not 
supported yet");
                                        }
-                                       /* In case of a single <index_term> the 
offset_stp is just offset_stt + 1 to make the range only include offset_stt */
-                                       offset_stp = exp_binop(sql->sa, 
offset_stt, exp_atom(sql->sa, atom_general(sql->sa, &dim->type, "1")), 
sql_bind_func(sql->sa, sql->session->schema, "sql_add", &dim->type, &dim->type, 
F_FUNC));
-                                       append(offsets, offset_stt);
-                                       append(offsets, offset_stp);
-                                       /* use the free 'f' in e_column to pass 
the tiling ranges */
-                                       exp->f = offsets;
                                } else if (opr->token == SQL_COLUMN && 
opr->data.lval->h->type == type_string) { /* '<exp> +/- <column>' */
                                        return sql_error(sql, 02, "SELECT: 
TODO: implement the '<exp> +/- <column>' case in array tiling!");
                                } else {
                                        return sql_error(sql, 02, "SELECT: 
absolute array tiling offset not supported yet");
                                }
-
                                break;
                        default: /* '<exp> '*/
                                return sql_error(sql, 02, "SELECT: absolute 
array tiling offset not supported yet");
-                       }
-                       break;
-               case 2: /* <index_term> : <index_term> */
-                       switch (tstt->token) {
-                       /* To handle the first 'index_term':
-                        * 1) extract and bind the dimension, which also checks 
if the
-                        *    dimension exists in the array 'aname';
-                        * 2) extract the start-offset expression from the 
'index_term',
-                        *    create an exp_atom with "0" if not specified (case
-                        *    SQL_COLUMN), and append it to 'exp->f'.
-                        */
+               }
+
+               /* If a step is specified, we don't care what it exactly is, 
just treat
+                * it as an expression; otherwise get the value from dimension
+                * specification. */
+               exp_os_ste = (dlist_length(n->data.lval) == 3) ?
+                       rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, 
n->data.lval->h->next->data.sym, sql_where, ek), type_cast):
+                       exp_atom(sql->sa, atom_general(sql->sa, &dim->type, 
dim->dim->step));
+
+               /* array tiling range stop, which, in case of a single 
<index_term>, is
+                * just 'start+step' to make the range only include '0'.
+                * Otherwise, it is given by the second or third 'index_term', 
which is
+                * handled by
+                * 1) extract and _check_ if the dimension name matches the 
dimension
+                *    name in the first 'index_term'.
+                * 2) extract the stop-offset expression from the 'index_term', 
create
+                *    an exp_atom with "0" if not specified (case SQL_COLUMN), 
and
+                *    append it to 'exp->f'.
+                */
+               if (dlist_length(n->data.lval) == 1) {
+                       exp_os_sto = exp_binop(sql->sa, exp_os_sta,
+                                       exp_atom(sql->sa, atom_general(sql->sa, 
&dim->type, dim->dim->step)),
+                                       sql_bind_func(sql->sa, 
sql->session->schema, "sql_add", &dim->type, &dim->type, F_FUNC));
+               } else {
+                       sym_tsto = (dlist_length(n->data.lval) == 2) ? 
n->data.lval->h->next->data.sym : n->data.lval->h->next->next->data.sym;
+                       switch (sym_tsto->token) {
                        case SQL_COLUMN: /* '<column>' */
-                               if (!(exp = get_tiling_dimension(sql, *rel, 
aname, tstt, f)))
+                               if (!check_tiling_dimension(sql, exp->name, 
sym_tsto))
                                        return NULL;
-                               if (!(dim = get_dimension(sql, a, exp->name)))
-                                       return NULL;
-                               /* array tiling range start */
-                               append(offsets, exp_atom(sql->sa, 
atom_general(sql->sa, &dim->type, "0")));
+                               exp_os_sto = exp_atom(sql->sa, 
atom_general(sql->sa, &dim->type, "0"));
                                break;
                        case SQL_BINOP: /* '<column> <BINOP> <exp>' or '<exp> 
<BINOP> <column>' */
-                               opnm = 
tstt->data.lval->h->data.lval->h->data.sval;
-                               opl = tstt->data.lval->h->next->data.sym;
-                               opr = tstt->data.lval->h->next->next->data.sym;
+                               opnm = 
sym_tsto->data.lval->h->data.lval->h->data.sval;
+                               opl = sym_tsto->data.lval->h->next->data.sym;
+                               opr = 
sym_tsto->data.lval->h->next->next->data.sym;
                                if (opl->token == SQL_COLUMN && 
opl->data.lval->h->type == type_string) { /* '<column> +/- <exp>' */
-                                       if (!(exp = get_tiling_dimension(sql, 
*rel, aname, opl, f)))
-                                               return NULL;
-                                       if (!(dim = get_dimension(sql, a, 
exp->name)))
+                                       if (!check_tiling_dimension(sql, 
exp->name, opl))
                                                return NULL;
                                        if (is_addition(opnm)) {
-                                               offset_stt = 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast);
-                                               /* in case of a single 
<index_term> the stop-offset is just start-offset + 1 to ensure start-offset 
will be selected */
+                                               exp_os_sto = 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast);
                                        } else if (is_substraction(opnm)){
-                                               offset_stt = exp_unop(sql->sa, 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast), sql_bind_func(sql->sa, sql->session->schema, "sql_neg", &dim->type, 
NULL, F_FUNC));
+                                               exp_os_sto = exp_unop(sql->sa, 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast), sql_bind_func(sql->sa, sql->session->schema, "sql_neg", &dim->type, 
NULL, F_FUNC));
                                        } else {
                                                return sql_error(sql, 02, 
"SELECT: binary expressions other than '+' and '-' in array tiling offset not 
supported yet");
                                        }
-                                       append(offsets, offset_stt);
                                } else if (opr->token == SQL_COLUMN && 
opr->data.lval->h->type == type_string) { /* '<exp> +/- <column>' */
                                        return sql_error(sql, 02, "SELECT: 
TODO: implement the '<exp> +/- <column>' case!");
                                } else {
@@ -2014,55 +2014,10 @@ rel_arraytiling(mvc *sql, sql_rel **rel,
                        default: /* '<exp>' */
                                return sql_error(sql, 02, "SELECT: absolute 
array tiling offset not supported yet");
                        }
-
-                       tstp = n->data.lval->h->next->data.sym;
-                       switch (tstp->token) {
-                       /* To handle the second 'index_term':
-                        * 1) extract and _check_ if the dimension name matches 
the
-                        *    dimension name in the first 'index_term'.
-                        * 2) extract the stop-offset expression from the 
'index_term',
-                        *    create an exp_atom with "0" if not specified (case
-                        *    SQL_COLUMN), and append it to 'exp->f'.
-                        */
-                       case SQL_COLUMN:
-                               if (!check_tiling_dimension(sql, exp->name, 
tstp))
-                                       return NULL;
-                               /* array tiling range stop */
-                               append(offsets, exp_atom(sql->sa, 
atom_general(sql->sa, &dim->type, "0")));
-                               /* use the free 'f' in e_column to pass the 
tiling ranges */
-                               exp->f = offsets;
-                               break;
-                       case SQL_BINOP:
-                               opnm = 
tstp->data.lval->h->data.lval->h->data.sval;
-                               opl = tstp->data.lval->h->next->data.sym;
-                               opr = tstp->data.lval->h->next->next->data.sym;
-                               if (opl->token == SQL_COLUMN && 
opl->data.lval->h->type == type_string) { /* '<column> +/- <exp>' */
-                                       if (!check_tiling_dimension(sql, 
exp->name, opl))
-                                               return NULL;
-                                       if (is_addition(opnm)) {
-                                               offset_stp = 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast);
-                                       } else if (is_substraction(opnm)){
-                                               offset_stp = exp_unop(sql->sa, 
rel_check_type(sql, &dim->type, rel_value_exp(sql, rel, opr, sql_where, ek), 
type_cast), sql_bind_func(sql->sa, sql->session->schema, "sql_neg", &dim->type, 
NULL, F_FUNC));
-                                       } else {
-                                               return sql_error(sql, 02, 
"SELECT: binary expressions other than '+' and '-' in array tiling offset not 
supported yet");
-                                       }
-                                       append(offsets, offset_stp);
-                                       /* use the free 'f' in e_column to pass 
the tiling ranges */
-                                       exp->f = offsets;
-                               } else if (opr->token == SQL_COLUMN && 
opr->data.lval->h->type == type_string) { /* '<exp> +/- <column>' */
-                                       return sql_error(sql, 02, "SELECT: 
TODO: implement the '<exp> +/- <column>' case!");
-                               } else {
-                                       return sql_error(sql, 02, "SELECT: 
absolute array tiling offset not supported yet");
-                               }
-                               break;
-                       default: /* '<exp>' */
-                               return sql_error(sql, 02, "SELECT: absolute 
array tiling offset not supported yet");
-                       }
-                       break;
-               default: /* <index_term> : <index_term> : <index_term> */
-                       assert(dlist_length(n->data.lval) == 3);
-                       return sql_error(sql, 02, "SELECT: step size in array 
tiling not supported yet");
                }
+               append(append(append(offsets, exp_os_sta), exp_os_ste), 
exp_os_sto);
+               /* use the free 'f' in e_column to pass the tiling ranges */
+               exp->f = offsets;
                append(exps, exp);
        }
        return exps;
@@ -3913,6 +3868,9 @@ rel_nop(mvc *sql, sql_rel **rel, symbol 
        return sql_error(sql, 02, "SELECT: no such operator '%s'", fname);
 }
 
+#define GET_DIM_SZ(tpe,sta,ste,sto) \
+       ceil((*(tpe *)VALget(&sto->data) * 1.0 - *(tpe *)VALget(&sta->data)) / \
+                       *(tpe *)VALget(&ste->data));
 
 /* E.g.:
  * sql> plan select sum(v) from a group by a[x-1:x+2][y-1:y+2];
@@ -3929,68 +3887,163 @@ rel_nop(mvc *sql, sql_rel **rel, symbol 
  * +-------------------------------------------------------------+
  *
  * TO
- * 
+-----------------------------------------------------------------------------+
- * | rel                                                                       
  |
- * 
+=============================================================================+
- * | 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, -1, 2, a.y, -1, 2) as L6 ] 
  |
- * | ) [ L6 ]                                                                  
  |
- * 
+-----------------------------------------------------------------------------+
+ * 
+---------------------------------------------------------------------------------------------------+
+ * | rel                                                                       
                        |
+ * 
+===================================================================================================+
+ * | 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 ]   |
+ * | ) [ L6 ]                                                                  
                        |
+ * 
+---------------------------------------------------------------------------------------------------+
  */
 static sql_exp *
 _rel_tiling_aggr(mvc *sql, sql_rel **rel, sql_rel *groupby, int distinct, char 
*aggrstr, symbol *sym, int f)
 {
-       sql_exp *exp = NULL, *dim1 = NULL, *tstt1 = NULL, *tstp1 = NULL,
-                       *dim2 = NULL, *tstt2 = NULL, *tstp2 = NULL;
+       sql_exp *exp = NULL, **dim = NULL, **oss = NULL;
+       atom **os_sta = NULL, **os_ste = NULL, **os_sto = NULL;
        sql_subfunc *sf = NULL;
-       list *args = new_exp_list(sql->sa);
-       char *aggrstr2 = malloc(strlen("array_tiling_") + strlen(aggrstr) + 1);
+       list *arrg_args = new_exp_list(sql->sa);
+       char *aggrstr2 = SA_NEW_ARRAY(sql->sa, char, strlen("array_t") + 
strlen(aggrstr) + 1);
+       node *cn = NULL;
+       sql_table *t = (sql_table*)((sql_rel*)groupby->l)->l;
+       int i = 0, j = 0;
+       lng cnt = 0, *dsize = NULL, *nrep = NULL, *ngrp = NULL;
+       sql_column *sc = NULL;
 
        (void)distinct;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to