Update of /cvsroot/monetdb/pathfinder/compiler/sql
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26187

Modified Files:
        lalg2sql.brg sql.c 
Log Message:


-- Bugfix regarding the handling of boolean values.
   It was not possible to handle polymorphic sequences consisting of
   boolean expressions.
-- Implementations for boo


Index: sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sql.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- sql.c       11 Jan 2008 10:47:18 -0000      1.45
+++ sql.c       11 Jan 2008 11:04:06 -0000      1.46
@@ -1335,6 +1335,8 @@
         case aat_attr:
         case aat_nat:
         case aat_int:
+        /* we even translate boolean as INTEGER */
+        case aat_bln:
             return "INTEGER";
         case aat_uA:
         case aat_str:

Index: lalg2sql.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/lalg2sql.brg,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- lalg2sql.brg        11 Jan 2008 10:47:17 -0000      1.100
+++ lalg2sql.brg        11 Jan 2008 11:04:06 -0000      1.101
@@ -419,7 +419,7 @@
         case aat_nat:   return lit_int (atom.val.nat_);
         case aat_int:   return lit_int (atom.val.int_);
         case aat_str:   return lit_str (atom.val.str);
-        case aat_bln:   return eq (lit_int (atom.val.bln?1:0), lit_int (1));
+        case aat_bln:   return lit_int (atom.val.bln?1:0);
         case aat_dbl:   return lit_dec (atom.val.dbl);
         case aat_dec:   return lit_dec (atom.val.dec_);
         case aat_qname: return lit_str (PFqname_loc (atom.val.int_));
@@ -681,7 +681,9 @@
 
     /* we have a different strategy when our item is boolean */
     if (col->sem.column.name->ty == aat_bln)
-        n = case_ (when (n, lit_int (1)), else_ (lit_int (0)));
+        n = (n->kind == sql_column_name)?
+            n:
+            case_ (when (n, lit_int (1)), else_ (lit_int (0)));
 
     if (n->kind == sql_column_name || n->kind == sql_ref_column_name)
         return n;
@@ -1861,7 +1863,9 @@
                     colexpr = entry.expression;
                     /* Ensure that boolean columns are replaced. */
                     if (entry.type == aat_bln)
-                        colexpr = case_ (when (colexpr, lit_int (1)),
+                        colexpr = (colexpr->kind == sql_column_name)?
+                                  colexpr:
+                                  case_ (when (colexpr, lit_int (1)),
                                          else_ (lit_int (0)));
                     
                     /* Generate a special column name DIST
@@ -2233,9 +2237,17 @@
         /* Rel:    lit_tbl */
         case 9:
             if (p->sem.lit_tbl.count == 1) {
+                PFsql_t * lit;
                 for (unsigned int col = 0; col < p->schema.count; col++)
                     for (PFalg_simple_type_t t = 1; t; t <<= 1)
                         if (t & TYPE_MASK (p->schema.items[col].type)) {
+                            lit = literal (p->sem.lit_tbl.tuples[0]
+                                                         .atoms[col]);
+                            
+                            /* if we have a boolean, generate
+                             * a boolean expression */
+                            if (t == aat_bln) lit = eq (lit, lit_int (1));
+
                             col_env_add (
                                 COLMAP(p),
                                 p->schema.items[col].name,
@@ -2243,8 +2255,7 @@
                                 (t == p->sem.lit_tbl
                                             .tuples[0]
                                             .atoms[col].type)
-                                ? literal (p->sem.lit_tbl.tuples[0]
-                                                         .atoms[col])
+                                ? lit
                                 : cast (null (), type (t)));
                         }
 
@@ -3047,15 +3058,38 @@
 
         /* Rel:    bool_and (Rel) */
         case 28:
-            /* FIXME: implementation is missing */
-            assert (!"missing");
-            break;
-
         /* Rel:    bool_or (Rel) */
         case 29:
-            /* FIXME: implementation is missing */
-            assert (!"missing");
-            break;
+        {
+            PFsql_t *sqlnode1;
+            PFsql_t *sqlnode2;
+            
+            PFsql_t * (*op) (const PFsql_t *a, const PFsql_t *b);
+
+            /* copy all existing column, from and where lists */
+            copy_cols_from_where (p, L(p));
+
+            sqlnode1 = col_env_lookup (COLMAP(p), p->sem.binary.att1, aat_bln);
+            sqlnode2 = col_env_lookup (COLMAP(p), p->sem.binary.att2, aat_bln);
+
+            if (sqlnode1->kind == sql_column_name)
+                sqlnode1 = eq (sqlnode1, lit_int (1));
+            if (sqlnode2->kind == sql_column_name)
+                sqlnode2 = eq (sqlnode2, lit_int (1));
+
+            switch (p->kind) {
+                case la_bool_and: op = PFsql_and; break;
+                case la_bool_or:  op = PFsql_or;  break;
+                default:
+                    PFoops (OOPS_FATAL,
+                            "la_bool_and or la_bool_or expected!");
+            }
+
+            col_env_add (COLMAP(p),
+                         p->sem.binary.res,
+                         aat_bln,
+                         op (sqlnode1, sqlnode2));
+        }   break;
 
         /* Rel:    bool_not (Rel) */
         case 30:


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to