Update of /cvsroot/monetdb/pathfinder/compiler/sql
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12892/compiler/sql
Modified Files:
Tag: PF_ROX
lalg2sql.brg sql.c sqlprint.c
Log Message:
propagated changes of Thursday Mar 06 2008 - Monday Mar 17 2008
from the development trunk to the PF_ROX branch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2008/03/10 - mayrm: compiler/sql/lalg2sql.brg,1.123
Bugfix: Since SQL lacks support for boolean types we have to bind the input
operators
of joins trying to join over boolean values.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2008/03/11 - mayrm: tests/BugsViaSourgeforce/Tests/All,1.37
Add test for Bug 1908622 from Sourceforge.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2008/03/14 - mayrm: compiler/include/sql.h,1.47
compiler/include/sql_mnemonic.h,1.38 compiler/sql/lalg2sql.brg,1.124
compiler/sql/sql.c,1.56 compiler/sql/sqlprint.c,1.48
Use the DB2 specific `raise_error' function to throw errors durings runtime.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2008/03/17 - sjoerd: runtime/pathfinder.mx,1.406
propagated changes of Friday Mar 07 2008 - Monday Mar 17 2008
from the XQuery_0-22 branch to the development trunk
===================================================================
2008/03/14 - nielsnes: runtime/pathfinder.mx,1.399.2.6
sum now returns NULL for empty bats
so, introduced an old_sum which has the old semantics
===================================================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sql.c,v
retrieving revision 1.48.2.6
retrieving revision 1.48.2.7
diff -u -d -r1.48.2.6 -r1.48.2.7
--- sql.c 26 Feb 2008 01:26:18 -0000 1.48.2.6
+++ sql.c 17 Mar 2008 16:49:16 -0000 1.48.2.7
@@ -1179,6 +1179,18 @@
}
/**
+ * Create a DB2 runtime error
+ */
+PFsql_t * PFsql_raise_error (PFsql_t *state, PFsql_t *message)
+{
+ assert (state->kind == sql_lit_str &&
+ message->kind == sql_lit_str);
+
+ return wire2 (sql_db2_raise_error, state, message);
+}
+
+
+/**
* Duplicate a given SQL tree.
*/
PFsql_t *
@@ -1363,6 +1375,7 @@
case sql_col_pos: return "pos";
case sql_col_guide: return "guide";
case sql_col_max: return "max";
+ case sql_col_err: return "err";
case sql_col_dist:
assert (name->ty < 100);
res = (char *) PFmalloc (7);
Index: lalg2sql.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/lalg2sql.brg,v
retrieving revision 1.108.2.6
retrieving revision 1.108.2.7
diff -u -d -r1.108.2.6 -r1.108.2.7
--- lalg2sql.brg 6 Mar 2008 16:35:57 -0000 1.108.2.6
+++ lalg2sql.brg 17 Mar 2008 16:49:14 -0000 1.108.2.7
@@ -471,6 +471,7 @@
#define POS_ column_name (special_col (sql_col_pos))
#define MAX_ column_name (special_col (sql_col_max))
#define DIST_ column_name (special_col (sql_col_dist))
+#define ERR_ column_name (special_col (sql_col_err))
#define PRE(n) ext_column_name (n, special_col (sql_col_pre))
#define SIZE(n) ext_column_name (n, special_col (sql_col_size))
@@ -2536,15 +2537,74 @@
{
assert (kids[0] && nts[0]);
assert (kids[1] && nts[1]);
+
/* reduce the first child */
reduce (kids[0], nts[0]);
+ if (p->kind == la_eqjoin) {
+ PFalg_simple_type_t l_ty;
+
+ l_ty = type_of (p, p->sem.eqjoin.att1);
+
+ assert (monomorphic (l_ty));
+
+ /* if the the eqjoin joins over boolean values
+ * we have to bind the underlying node */
+ if (l_ty == aat_bln && !BOUND(L(p)))
+ bind_operator (L(p), false);
+ }
+ else if (p->kind == la_thetajoin) {
+ PFalg_simple_type_t l_ty;
+
+ /* iterate over all predicates and add them to the wherelist */
+ for (unsigned int i = 0; i < p->sem.thetajoin.count; i++) {
+
+ l_ty = type_of (p, p->sem.thetajoin.pred[i].left);
+
+ assert (monomorphic (l_ty));
+
+ /* if the thetajoin joins over boolean values
+ * we have to bind the underlying node */
+ if (l_ty == aat_bln && !BOUND (L(p)))
+ bind_operator (L(p), false);
+ }
+ }
+
/* copy all existing column, from, and where lists
of the left child */
copy_cols_from_where (p, L(p));
reduce (kids[1], nts[1]);
+ if (p->kind == la_eqjoin) {
+ PFalg_simple_type_t r_ty;
+
+ r_ty = type_of (p, p->sem.eqjoin.att2);
+
+ assert (monomorphic (r_ty));
+
+ /* if the the eqjoin joins over boolean values
+ * we have to bind the underlying node */
+ if (r_ty == aat_bln && !BOUND(R(p)))
+ bind_operator (R(p), false);
+ }
+ else if (p->kind == la_thetajoin) {
+ PFalg_simple_type_t r_ty;
+
+ /* iterate over all predicates and add them to the wherelist */
+ for (unsigned int i = 0; i < p->sem.thetajoin.count; i++) {
+
+ r_ty = type_of (p, p->sem.thetajoin.pred[i].right);
+
+ assert (monomorphic (r_ty));
+
+ /* if the thetajoin joins over boolean values
+ * we have to bind the underlying node */
+ if (r_ty == aat_bln && !BOUND (R(p)))
+ bind_operator (R(p), false);
+ }
+ }
+
/* copy all existing expression from right child */
for (unsigned int i = 0; i < PFarray_last (COLMAP(R(p))); i++) {
sql_column_env_t entry = col_env_at (COLMAP(R(p)), i);
@@ -4522,12 +4582,73 @@
break;
/* Rel: cond_err (Rel, Rel) */
- case 99:
+
+ /********************************************************/
+ /* cond_err */
+ /* / \ */
+ /* / \ */
+ /* /\ /\ */
+ /* /q1\ /q2\ */
+ /* ------ ------ */
+ /* We will translate this plan into the following */
+ /* SQL query. */
+ /* */
+ /* SELECT q.* */
+ /* FROM q1 AS q, (SELECT CASE */
+ /* WHEN MIN(CASE */
+ /* WHEN att THEN 1 */
+ /* ELSE 0 */
+ /* END) < 1 */
+ /* THEN raise_error */
+ /* ELSE 1 END */
+ /* FROM q2 AS err) AS foo; */
+ /********************************************************/
+ case 99: {
+#define ERR_SQLSTATE "70001"
+ assert (kids[0] && nts[0]);
+ assert (kids[1] && nts[1]);
+
+ PFsql_t *expr = NULL,
+ *n = NULL;
+ PFalg_simple_type_t ty;
+ char *msg = p->sem.err.str;
+
reduce (kids[0], nts[0]);
/* copy all existing column, from, and where lists */
copy_cols_from_where (p, L(p));
- break;
+
+ reduce (kids[1], nts[1]);
+
+ ty = type_of (R(p), p->sem.err.att);
+ assert (monomorphic (ty) && ty == aat_bln);
+ expr = col_env_lookup (COLMAP(R(p)),
+ p->sem.err.att,
+ ty);
+
+ n = expr;
+
+ /* if the underlying relation containing is bound,
+ * we can directly using the column */
+ n = (n->kind == sql_column_name ||
+ n->kind == sql_lit_int)
+ ? n
+ : case_ (when (n, TRUE_INT), else_ (FALSE_INT));
+
+ n = case_ (when (gt (TRUE_INT, min_ (n)),
+ raise_error (lit_str (ERR_SQLSTATE),
+ lit_str (msg))),
+ else_ (TRUE_INT));
+
+ PFsql_aident_t nalias = new_alias ();
+
+ from_list_add (FROMLIST (p),
+ select (
+ column_assign (n, ERR_),
+ transform_frommap (R(p)),
+ transform_wheremap (R(p))
+ ), alias (nalias));
+ } break;
/* Rel: trace (Rel, Msg) */
case 100:
Index: sqlprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sqlprint.c,v
retrieving revision 1.44.4.3
retrieving revision 1.44.4.4
diff -u -d -r1.44.4.3 -r1.44.4.4
--- sqlprint.c 26 Feb 2008 01:26:19 -0000 1.44.4.3
+++ sqlprint.c 17 Mar 2008 16:49:16 -0000 1.44.4.4
@@ -550,6 +550,20 @@
}
static void
+print_raise_error (PFsql_t *n)
+{
+ assert (n);
+ assert (L(n) && R(n));
+ assert (n->kind == sql_db2_raise_error);
+
+ PFprettyprintf ("raise_error (");
+ print_literal (L(n));
+ PFprettyprintf (",");
+ print_literal (R(n));
+ PFprettyprintf (")");
+}
+
+static void
print_case (PFsql_t *n)
{
assert (n);
@@ -564,12 +578,18 @@
PFprettyprintf ("WHEN ");
print_condition (L(n));
PFprettyprintf (" THEN ");
- print_statement (R(n));
+ if (R(n)->kind != sql_db2_raise_error)
+ print_statement (R(n));
+ else
+ print_raise_error (R(n));
break;
case sql_else:
PFprettyprintf (" ELSE ");
- print_statement (L(n));
+ if (L(n)->kind != sql_db2_raise_error)
+ print_statement (L(n));
+ else
+ print_raise_error (L(n));
break;
case sql_nil:
@@ -868,7 +888,7 @@
case sql_tbl_name:
print_tablereference (f, n, i);
break;
-
+
case sql_on:
print_join (f, n, i);
break;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins