Changeset: 6c9614606946 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6c9614606946
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/rel_bin.h
sql/backends/monet5/sql_gencode.c
sql/server/rel_psm.c
Branch: sciql
Log Message:
Trying to get array-returning UDFs working again...
The main change is moving the code of sql_parse() into _sql_parse, so that
_sql_parse also returns the relational tree.
But more work is needed...
diffs (147 lines):
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -2601,7 +2601,7 @@ rel2bin_sample( mvc *sql, sql_rel *rel,
}
stmt *
-sql_parse(mvc *m, sql_allocator *sa, char *query, char mode)
+_sql_parse(mvc *m, sql_allocator *sa, char *query, char mode, sql_rel **ret)
{
mvc *o = NULL;
stmt *sq = NULL;
@@ -2655,6 +2655,8 @@ sql_parse(mvc *m, sql_allocator *sa, cha
if (r) {
r = rel_optimizer(m, r);
sq = rel_bin(m, r);
+ if (ret != NULL)
+ *ret = r;
}
}
@@ -2695,6 +2697,12 @@ sql_parse(mvc *m, sql_allocator *sa, cha
return sq;
}
+stmt *
+sql_parse(mvc *m, sql_allocator *sa, char *query, char mode)
+{
+ return _sql_parse(m, sa, query, mode, NULL);
+}
+
static stmt *
nth( list *l, int n)
{
diff --git a/sql/backends/monet5/rel_bin.h b/sql/backends/monet5/rel_bin.h
--- a/sql/backends/monet5/rel_bin.h
+++ b/sql/backends/monet5/rel_bin.h
@@ -27,6 +27,7 @@ extern stmt * exp_bin(mvc *sql, sql_exp
extern stmt * rel_bin(mvc *sql, sql_rel *rel);
extern stmt * output_rel_bin(mvc *sql, sql_rel *rel);
+extern stmt *_sql_parse(mvc *m, sql_allocator *sa, char *query, char mode,
sql_rel **ret_rel);
extern stmt * sql_parse(mvc *m, sql_allocator *sa, char *query, char mode);
#endif /*_REL_BIN_H_*/
diff --git a/sql/backends/monet5/sql_gencode.c
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -315,7 +315,8 @@ static int
}
}
- if (backend_dumpstmt(be, curBlk, s, NULL) < 0)
+ /* FIXME: do we really need to pass 'r' here? When is this function
called to handle what? */
+ if (backend_dumpstmt(be, curBlk, s, r) < 0)
return -1;
/* SQL function definitions meant for inlineing should not be optimized
before */
varSetProp(curBlk, getArg(curInstr, 0), sqlfunctionProp, op_eq, NULL);
@@ -2352,6 +2353,13 @@ add_materialise_stmt(MalBlkPtr mb, sql_r
add_materialise_stmt(mb, rel->l, processed);
add_materialise_stmt(mb, rel->r, processed);
break;
+ case op_ddl:
+ if (rel->exps) {
+ node *n = NULL;
+ for (n = rel->exps->h; n; n = n->next) {
+ /* TODO: search for op_ddl for arrays declared
in a UDF */
+ }
+ }
default:
break;
}
@@ -2629,6 +2637,7 @@ backend_create_func(backend *be, sql_fun
stmt *s;
int i, retseen =0, sideeffects =0;
sql_allocator *sa, *osa = m->sa;
+ sql_rel *rel = NULL;
/* nothing to do for internal and ready (not recompiling) functions */
if (!f->sql || f->sql > 1)
@@ -2636,7 +2645,7 @@ backend_create_func(backend *be, sql_fun
f->sql++;
sa = sa_create();
m->session->schema = f->s;
- s = sql_parse(m, sa, f->query, m_instantiate);
+ s = _sql_parse(m, sa, f->query, m_instantiate, &rel);
m->sa = osa;
m->session->schema = schema;
if (s && !f->sql) { /* native function */
@@ -2690,7 +2699,7 @@ backend_create_func(backend *be, sql_fun
if ( m->session->auto_commit)
setCommitProperty(curBlk);
- if (backend_dumpstmt(be, curBlk, s, NULL) < 0)
+ if (backend_dumpstmt(be, curBlk, s, rel) < 0)
return -1;
/* selectively make functions available for inlineing */
/* for the time being we only inline scalar functions */
diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -435,9 +435,14 @@ rel_psm_return( mvc *sql, sql_subtype *r
sql_table *t = rel_ddl_table_get(rel);
node *n, *m;
char *tname = t->base.name;
+ /* in case of an array, the dimension info. is contained from
the
+ * fourth exp in rel->exps, see also rel_table() */
+ node *d = rel->exps->h->next->next->next;
if (cs_size(&t->columns) !=
cs_size(&restype->comp_type->columns))
return sql_error(sql, 02, "RETURN: number of columns do
not match");
+ if (t->valence != restype->comp_type->valence)
+ return sql_error(sql, 02, "RETURN: number of dimensions
do not match (%d != %d)", t->valence, restype->comp_type->valence);
for (n = t->columns.set->h, m =
restype->comp_type->columns.set->h; n && m; n = n->next, m = m->next) {
sql_column *c = n->data;
sql_column *ce = m->data;
@@ -445,15 +450,26 @@ rel_psm_return( mvc *sql, sql_subtype *r
if (c->dim) {
list *rng_exps = new_exp_list(sql->sa), *drngs
= sa_list(sql->sa);
- assert(rng_exps && drngs);
+ if (rng_exps == NULL || drngs == NULL)
+ return sql_error(sql, 02, "RETURN:
failed to allocate space");
- append(rng_exps, rel_check_type(sql, &c->type,
exp_atom_lng(sql->sa, c->dim->strt), type_cast));
- append(rng_exps, rel_check_type(sql, &c->type,
exp_atom_lng(sql->sa, c->dim->step), type_cast));
- append(rng_exps, rel_check_type(sql, &c->type,
exp_atom_lng(sql->sa, c->dim->stop), type_cast));
+ if (d == NULL)
+ return sql_error(sql, 02, "RETURN:
missing info of dimension \"%s.%s\"", tname, c->base.name);
+
+ /* d->data is the exp containing the dim->ord */
+ if (((sql_exp*)d->data)->type != e_atom)
+ return sql_error(sql, 02, "RETURN:
invalid type of the order of dimension \"%s.%s\", %d expected, got %d", tname,
c->base.name, e_atom, ((sql_exp*)d->data)->type);
+
+ append(rng_exps, d->next->data);
+ append(rng_exps, d->next->next->data);
+ append(rng_exps, d->next->next->next->data);
append(drngs, rng_exps);
append(drngs, new_exp_list(sql->sa)); /* empty
lists for slicing and */
append(drngs, new_exp_list(sql->sa)); /* tiling
ranges */
e = exp_alias(sql->sa, tname, c->base.name,
tname, c->base.name, &c->type, CARD_MULTI, c->null, 0, drngs);
+
+ /* info for the next dimension */
+ d = d->next->next->next->next;
} else {
e = exp_alias(sql->sa, tname, c->base.name,
tname, c->base.name, &c->type, CARD_MULTI, c->null, 0, NULL);
}
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list