Changeset: c6774f5ec11b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c6774f5ec11b
Modified Files:
        pathfinder/compiler/algebra/algebra.c
        pathfinder/compiler/algebra/builtins.c
        pathfinder/compiler/algebra/logical.c
        pathfinder/compiler/algebra/physical.c
        pathfinder/compiler/algebra/prop/prop_ocol.c
        pathfinder/compiler/include/algebra.h
        pathfinder/compiler/include/builtins.h
        pathfinder/compiler/include/sql.h
        pathfinder/compiler/include/sql_mnemonic.h
        pathfinder/compiler/mil/milgen.brg
        pathfinder/compiler/semantics/xquery_fo.c
        pathfinder/compiler/sql/lalg2sql.brg
        pathfinder/compiler/sql/sql.c
        pathfinder/compiler/sql/sqlprint.c
        pathfinder/compiler/xmlimport/xml2lalg_converters.c
Branch: default
Log Message:

Changed input type of the substring operator and added SQL code generation

-- Changed the input types of the second (and third) argument
   of the substring 1:1 operator from dbl to int.

-- Renamed alg_fun_fn_substring_dbl to alg_fun_fn_substring_len.

-- Extended the SQL code generation to cope with the two variants
   of substring operators.


diffs (truncated from 454 to 300 lines):

diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/algebra/algebra.c
--- a/pathfinder/compiler/algebra/algebra.c     Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/algebra/algebra.c     Sun Aug 01 21:59:04 2010 +0200
@@ -1189,7 +1189,7 @@
         case alg_fun_pf_log:              return "pf:log";
         case alg_fun_fn_concat:           return "fn:concat";
         case alg_fun_fn_substring:        return "fn:substring";
-        case alg_fun_fn_substring_dbl:    return "fn:substring3";
+        case alg_fun_fn_substring_len:    return "fn:substring_len";
         case alg_fun_fn_string_length:    return "fn:string-length";
         case alg_fun_fn_normalize_space:  return "fn:normalize-space";
         case alg_fun_fn_upper_case:       return "fn:upper-case";
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/algebra/builtins.c
--- a/pathfinder/compiler/algebra/builtins.c    Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/algebra/builtins.c    Sun Aug 01 21:59:04 2010 +0200
@@ -1944,12 +1944,21 @@
                                                proj (col_iter, col_iter))),
                                        col_pos, lit_nat (1)),
                                    col_item, lit_str (""))),
-                           project (cast (args[1].rel,
-                                          col_cast,
-                                          col_item,
-                                          aat_dbl),
-                                    proj (col_iter1, col_iter),
-                                    proj (col_item1, col_cast)),
+                           project (
+                               cast (
+                                   fun_1to1 (
+                                       cast (args[1].rel,
+                                             col_cast,
+                                             col_item,
+                                             aat_dbl),
+                                       alg_fun_fn_round,
+                                       col_res,
+                                       collist (col_cast)),
+                                   col_item1,
+                                   col_res,
+                                   aat_int),
+                               proj (col_iter1, col_iter),
+                               proj (col_item1, col_item1)),
                            col_iter,
                            col_iter1),
                        alg_fun_fn_substring,
@@ -1967,7 +1976,7 @@
  * <code>fn:substring(xs:string?, xs:double, xs:double)</code>
  */
 struct PFla_pair_t
-PFbui_fn_substring_dbl (const PFla_op_t *loop,
+PFbui_fn_substring_len (const PFla_op_t *loop,
                         bool ordering,
                         PFla_op_t **side_effects,
                         struct PFla_pair_t *args)
@@ -1990,23 +1999,41 @@
                                                    proj (col_iter, col_iter))),
                                            col_pos, lit_nat (1)),
                                        col_item, lit_str (""))),
-                               project (cast (args[1].rel,
-                                              col_cast,
-                                              col_item,
-                                              aat_dbl),
-                                        proj (col_iter1, col_iter),
-                                        proj (col_item1, col_cast)),
+                               project (
+                                   cast (
+                                       fun_1to1 (
+                                           cast (args[1].rel,
+                                                 col_cast,
+                                                 col_item,
+                                                 aat_dbl),
+                                           alg_fun_fn_round,
+                                           col_res,
+                                           collist (col_cast)),
+                                       col_item1,
+                                       col_res,
+                                       aat_int),
+                                   proj (col_iter1, col_iter),
+                                   proj (col_item1, col_item1)),
                                col_iter,
                                col_iter1),
-                           project (cast (args[2].rel,
-                                          col_cast,
-                                          col_item,
-                                          aat_dbl),
-                                    proj (col_iter2, col_iter),
-                                    proj (col_item2, col_cast)),
+                           project (
+                               cast (
+                                   fun_1to1 (
+                                       cast (args[2].rel,
+                                             col_cast,
+                                             col_item,
+                                             aat_dbl),
+                                       alg_fun_fn_round,
+                                       col_res,
+                                       collist (col_cast)),
+                                   col_item1,
+                                   col_res,
+                                   aat_int),
+                               proj (col_iter2, col_iter),
+                               proj (col_item2, col_item1)),
                            col_iter,
                            col_iter2),
-                       alg_fun_fn_substring_dbl,
+                       alg_fun_fn_substring_len,
                        col_res,
                        collist (col_item, col_item1, col_item2)),
                 proj (col_iter, col_iter),
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/algebra/logical.c
--- a/pathfinder/compiler/algebra/logical.c     Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/algebra/logical.c     Sun Aug 01 21:59:04 2010 +0200
@@ -1428,18 +1428,18 @@
             assert (clsize (refs) == 2);
             /* make sure both columns are of type str & dbl */
             assert (n->schema.items[ix[0]].type == aat_str);
-            assert (n->schema.items[ix[1]].type == aat_dbl);
+            assert (n->schema.items[ix[1]].type == aat_int);
 
             res_type = aat_str;
             break;
 
-        case alg_fun_fn_substring_dbl:
+        case alg_fun_fn_substring_len:
             assert (clsize (refs) == 3);
 
             /* make sure columns are of type str & dbl */
             assert (n->schema.items[ix[0]].type == aat_str);
-            assert (n->schema.items[ix[1]].type == aat_dbl &&
-                    n->schema.items[ix[2]].type == aat_dbl );
+            assert (n->schema.items[ix[1]].type == aat_int &&
+                    n->schema.items[ix[2]].type == aat_int );
 
             res_type = aat_str;
             break;
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/algebra/physical.c
--- a/pathfinder/compiler/algebra/physical.c    Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/algebra/physical.c    Sun Aug 01 21:59:04 2010 +0200
@@ -1635,17 +1635,17 @@
 
             /* make sure both columns are of type str & dbl */
             assert (n->schema.items[ix[0]].type == aat_str);
-            assert (n->schema.items[ix[1]].type == aat_dbl);
+            assert (n->schema.items[ix[1]].type == aat_int);
 
             res_type = aat_str;
             break;
 
-        case alg_fun_fn_substring_dbl:
+        case alg_fun_fn_substring_len:
             assert (clsize (refs) == 3);
             /* make sure columns are of type str & dbl */
             assert (n->schema.items[ix[0]].type == aat_str);
-            assert (n->schema.items[ix[1]].type == aat_dbl &&
-                    n->schema.items[ix[2]].type == aat_dbl);
+            assert (n->schema.items[ix[1]].type == aat_int &&
+                    n->schema.items[ix[2]].type == aat_int);
 
             res_type = aat_str;
             break;
diff -r 76be7701721b -r c6774f5ec11b 
pathfinder/compiler/algebra/prop/prop_ocol.c
--- a/pathfinder/compiler/algebra/prop/prop_ocol.c      Thu Jul 29 13:37:44 
2010 +0200
+++ b/pathfinder/compiler/algebra/prop/prop_ocol.c      Sun Aug 01 21:59:04 
2010 +0200
@@ -346,17 +346,17 @@
 
                     /* make sure both columns are of type str & dbl */
                     assert (ocol_at (L(n), ix[0]).type == aat_str);
-                    assert (ocol_at (L(n), ix[1]).type == aat_dbl);
+                    assert (ocol_at (L(n), ix[1]).type == aat_int);
 
                     res_type = aat_str;
                     break;
 
-                case alg_fun_fn_substring_dbl:
+                case alg_fun_fn_substring_len:
                     assert (clsize (n->sem.fun_1to1.refs) == 3);
                     /* make sure both columns are of type str & dbl */
                     assert (ocol_at (L(n), ix[0]).type == aat_str);
-                    assert (ocol_at (L(n), ix[1]).type == aat_dbl &&
-                            ocol_at (L(n), ix[2]).type == aat_dbl);
+                    assert (ocol_at (L(n), ix[1]).type == aat_int &&
+                            ocol_at (L(n), ix[2]).type == aat_int);
 
                     res_type = aat_str;
                     break;
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/include/algebra.h
--- a/pathfinder/compiler/include/algebra.h     Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/include/algebra.h     Sun Aug 01 21:59:04 2010 +0200
@@ -384,7 +384,7 @@
     , alg_fun_pf_sqrt             /**< pf:sqrt */
     , alg_fun_fn_concat           /**< fn:concat */
     , alg_fun_fn_substring        /**< fn:substring */
-    , alg_fun_fn_substring_dbl    /**< fn:substring with length specified*/
+    , alg_fun_fn_substring_len    /**< fn:substring with length specified */
     , alg_fun_fn_string_length    /**< fn:string-length */
     , alg_fun_fn_normalize_space  /**< fn:normalize-space */
     , alg_fun_fn_upper_case       /**< fn:upper-case */
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/include/builtins.h
--- a/pathfinder/compiler/include/builtins.h    Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/include/builtins.h    Sun Aug 01 21:59:04 2010 +0200
@@ -406,7 +406,7 @@
                                        bool ordering,
                                        PFla_op_t **side_effects,
                                        struct PFla_pair_t *args);
-struct PFla_pair_t PFbui_fn_substring_dbl (const PFla_op_t *loop,
+struct PFla_pair_t PFbui_fn_substring_len (const PFla_op_t *loop,
                                            bool ordering,
                                            PFla_op_t **side_effects,
                                            struct PFla_pair_t *args);
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/include/sql.h
--- a/pathfinder/compiler/include/sql.h Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/include/sql.h Sun Aug 01 21:59:04 2010 +0200
@@ -166,6 +166,8 @@
     , sql_abs               /* abs expression */
 
     , sql_concat            /* string concatenation */
+    , sql_substring         /* substring search */
+    , sql_substring_length  /* substring search with length */
 
     , sql_is                /* IS predicate */
     , sql_is_not            /* IS NOT predicate */
@@ -737,6 +739,20 @@
  */
 PFsql_t * PFsql_concat (const PFsql_t *a, const PFsql_t *b);
 
+/**
+ * Create a SQL tree node representing the SQL
+ * substring operator.
+ */
+PFsql_t * PFsql_substring (const PFsql_t *a, const PFsql_t *b);
+
+/**
+ * Create a SQL tree node representing the SQL
+ * substring operator with length.
+ */
+PFsql_t * PFsql_substring_length (const PFsql_t *a,
+                                  const PFsql_t *b,
+                                  const PFsql_t *c);
+
 /* .......... Table Functions ........... */
 PFsql_t *PFsql_values (const PFsql_t *a);
 PFsql_t *PFsql_list_list_ (unsigned int count, const PFsql_t **list);
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/include/sql_mnemonic.h
--- a/pathfinder/compiler/include/sql_mnemonic.h        Thu Jul 29 13:37:44 
2010 +0200
+++ b/pathfinder/compiler/include/sql_mnemonic.h        Sun Aug 01 21:59:04 
2010 +0200
@@ -104,6 +104,8 @@
 
 /* .......... String Functions ........... */
 #define concat(a,b)                  PFsql_concat(a,b)
+#define substring(a,b)               PFsql_substring(a,b)
+#define substring_len(a,b,c)         PFsql_substring_length(a,b,c)
 
 /* .......... Table Functions ............ */
 #define values(a)                    PFsql_values(a)
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/mil/milgen.brg
--- a/pathfinder/compiler/mil/milgen.brg        Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/mil/milgen.brg        Sun Aug 01 21:59:04 2010 +0200
@@ -5432,13 +5432,13 @@
                                mstring (
                                    VAR (L(p)->env, col1, aat_str),
                                    mmax( msub( mcast (type (mty_int),
-                                                      mround_up( VAR 
(L(p)->env,
-                                                                 col2,
-                                                                 aat_dbl))),
+                                                      VAR (L(p)->env,
+                                                           col2,
+                                                           aat_int)),
                                               lit_int(1)),
                                          lit_int(0)))));
                 }   break; /* fold) */
-                case alg_fun_fn_substring_dbl: /* fold( */
+                case alg_fun_fn_substring_len: /* fold( */
                 {
                     PFalg_col_t col1, col2, col3;
 
@@ -5452,15 +5452,15 @@
                                mstring2 (
                                    VAR (L(p)->env, col1, aat_str),
                                    mmax( msub( mcast (type (mty_int),
-                                                      mround_up( VAR 
(L(p)->env,
-                                                                 col2,
-                                                                 aat_dbl))),
+                                                      VAR (L(p)->env,
+                                                           col2,
+                                                           aat_int)),
                                               lit_int(1)),
                                          lit_int(0)),
                                    mcast (type (mty_int),
-                                          mround_up( VAR (L(p)->env,
-                                                     col3,
-                                                     aat_dbl))))));
+                                          VAR (L(p)->env,
+                                               col3,
+                                               aat_int)))));
                 }   break; /* fold) */
 
                 case alg_fun_fn_string_length: /* fold( */
diff -r 76be7701721b -r c6774f5ec11b pathfinder/compiler/semantics/xquery_fo.c
--- a/pathfinder/compiler/semantics/xquery_fo.c Thu Jul 29 13:37:44 2010 +0200
+++ b/pathfinder/compiler/semantics/xquery_fo.c Sun Aug 01 21:59:04 2010 +0200
@@ -1048,7 +1048,7 @@
                                 PFty_xs_double (),
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to