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

Modified Files:
        algebra.c builtins.c logical.c physical.c 
Log Message:
* Algebra / MIL implementation of XQuery builtin function fn:translate.
* Erase trailing space chars.
* Introduce new algebra types for the document management functions:
   - aat_docmgmt
   - aat_str1
   - aat_str2
* Algebra implementation of the following document management functions:
   - pf:add-doc(str,str)
   - pf:add-doc(str,str, str)
   - pf:add-doc(str,str, int)
   - pf:add-doc(str,str, str, int)
   - pf:del-doc(str)
  mil code generation and runtime DocmgmTape function are still missing.


Index: physical.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/physical.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- physical.c  15 Jan 2008 15:52:57 -0000      1.51
+++ physical.c  18 Jan 2008 16:11:36 -0000      1.52
@@ -1629,6 +1629,7 @@
             res_type = aat_bln;
             break;
 
+        case alg_fun_fn_translate:
         case alg_fun_fn_replace:
             assert (refs.count == 3);
             /* make sure all attributes are of type string */
@@ -1690,6 +1691,70 @@
             res_type = n->schema.items[ix[0]].type;
             break;
 
+        case alg_fun_pf_add_doc:
+            assert(refs.count == 2);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types*/
+            res_type = aat_docmgmt | aat_str | aat_str1;
+
+            break;
+
+        case alg_fun_pf_add_doc_str:
+            assert(refs.count == 3);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+            assert(n->schema.items[ix[2]].type == aat_str);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types*/
+            res_type = aat_docmgmt | aat_str | aat_str1 | aat_str2;
+            break;
+
+        case alg_fun_pf_add_doc_int:
+            assert(refs.count == 3);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+            assert(n->schema.items[ix[2]].type == aat_int);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types */
+            res_type = aat_docmgmt | aat_str | aat_str1 | aat_int;
+            break;
+
+        case alg_fun_pf_add_doc_str_int:
+            assert(refs.count == 4);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+            assert(n->schema.items[ix[2]].type == aat_str);
+            assert(n->schema.items[ix[3]].type == aat_int);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types */
+            res_type = aat_docmgmt | aat_str | aat_str1 | aat_str2 | aat_int;
+            break;
+
+        case alg_fun_pf_del_doc:
+            assert(refs.count == 1);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types */
+            res_type = aat_docmgmt | aat_str1;
+            break;
+
         case alg_fun_upd_delete:
             assert(refs.count == 1);
             /* make sure that the attributes is a node */
@@ -3794,7 +3859,7 @@
     /* by default we don't know anything about the output ordering */
 
     /* XRPC functions return the result in iter|pos order */
-    if (kind == alg_fun_call_xrpc) 
+    if (kind == alg_fun_call_xrpc)
         PFord_set_add (ret->orderings, sortby (schema.items[0].name,
                                                schema.items[1].name));
 
@@ -3862,7 +3927,7 @@
     ret->schema.items = NULL;
 
     ret->sem.col_ref.pos = col_pos;
-    
+
     /* costs */
     ret->cost = argument->cost + param_list->cost;
 

Index: algebra.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/algebra.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- algebra.c   11 Jan 2008 10:46:56 -0000      1.66
+++ algebra.c   18 Jan 2008 16:11:36 -0000      1.67
@@ -698,12 +698,13 @@
         case aat_pfrag:
         case aat_afrag:
         case aat_update:
+        case aat_docmgmt:
         case aat_node1:
         case aat_pnode1:
         case aat_anode1:
-        case aat_pre1:
-        case aat_attr1:
-        case aat_pfrag1:
+        case aat_pre1:    /* or aat_str2, which can be compared but there is */
+        case aat_attr1:   /*          no way to distinguish it from aat_pre1 */
+        case aat_pfrag1:  /* or aat_str1, same as str2. */
         case aat_afrag1:
                         break; /* error */
     }
@@ -740,11 +741,21 @@
         case aat_attr1: return "attrID1";
         case aat_afrag1:return "afrag1";
         case aat_pnode1:return "pnode1";
-        case aat_pre1:  return "pre1";
-        case aat_pfrag1:return "pfrag1";
+        case aat_pre1:
+            if (type & aat_docmgmt)
+                return "aat_str2";
+            else
+                return "pre1";
+        case aat_pfrag1:
+            if (type & aat_docmgmt)
+                return "aat_str1";
+            else
+                return "pfrag1";
         default:
             if (type & aat_update)
                 return "update";
+            else if (type & aat_docmgmt)
+                return "docmgmt";
             else
                 PFoops (OOPS_FATAL, "unknown attribute simple type (%i)", 
type);
     }
@@ -993,9 +1004,9 @@
 PFalg_type (PFty_t ty)
 {
     PFalg_simple_type_t alg_ty = 0;
-    
+
     ty = PFty_prime (PFty_defn (ty));
-    
+
     if (!PFty_disjoint (ty, PFty_xs_integer ()))
         alg_ty |= aat_int;
     if (!PFty_disjoint (ty, PFty_xs_string ()))
@@ -1025,6 +1036,13 @@
         alg_ty |= aat_uA;
         alg_ty |= aat_qname;
     }
+    if (!PFty_disjoint (ty, PFty_docmgmt ())) {
+        alg_ty |= aat_docmgmt;
+        alg_ty |= aat_str;
+        alg_ty |= aat_str1;
+        alg_ty |= aat_str2;
+        alg_ty |= aat_int;
+    }
     return alg_ty;
 }
 
@@ -1067,6 +1085,7 @@
         case alg_fun_fn_normalize_space:  return "fn:normalize-space";
         case alg_fun_fn_upper_case:       return "fn:upper-case";
         case alg_fun_fn_lower_case:       return "fn:lower-case";
+        case alg_fun_fn_translate:        return "fn:translate";
         case alg_fun_fn_contains:         return "fn:contains";
         case alg_fun_fn_starts_with:      return "fn:starts-with";
         case alg_fun_fn_ends_with:        return "fn:ends-with";
@@ -1083,6 +1102,11 @@
         case alg_fun_fn_qname:            return "fn:QName";
         case alg_fun_pf_fragment:         return "#pf:fragment";
         case alg_fun_pf_supernode:        return "#pf:supernode";
+        case alg_fun_pf_add_doc:          return "pf:add-doc";
+        case alg_fun_pf_add_doc_str:      return "pf:add-doc";
+        case alg_fun_pf_add_doc_int:      return "pf:add-doc";
+        case alg_fun_pf_add_doc_str_int:  return "pf:add-doc";
+        case alg_fun_pf_del_doc:          return "pf:del-doc";
         case alg_fun_upd_rename:          return "upd:rename";
         case alg_fun_upd_delete:          return "upd:delete";
         case alg_fun_upd_insert_into_as_first:  return "upd:insertIntoAsFirst";

Index: logical.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/logical.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- logical.c   15 Jan 2008 15:52:57 -0000      1.76
+++ logical.c   18 Jan 2008 16:11:36 -0000      1.77
@@ -439,12 +439,12 @@
  * external attribute/column names, and a list of the (internal)
  * key attributes.
  *
- * @param name    The name of the referenced table.  
+ * @param name    The name of the referenced table.
  * @param schema  Attribute list ("internal" attribute names)
  *                with annotated types.
  * @param tatts   String list ("external" attribute/column
  *                names).
- * @param keys    Array holding the *positions* (w.r.t. the 
+ * @param keys    Array holding the *positions* (w.r.t. the
  *                schema) of key attributes
  */
 PFla_op_t *
@@ -470,7 +470,7 @@
     /* set its semantical infos */
     /* deep copy the name of the referenced table*/
     ret->sem.ref_tbl.name = PFstrdup(name);
-    
+
     /* deep copy the "original column names" of the referenced table*/
     ret->sem.ref_tbl.tatts = PFarray(sizeof (char*));
     for (unsigned int i = 0; i < PFarray_last (tatts); i++)
@@ -479,7 +479,7 @@
             char* copiedValue = PFstrdup(value);
             *(char**) PFarray_add (ret->sem.ref_tbl.tatts) = copiedValue;
     }
-    
+
     /* (it's save to) shallow copy the list of key-attribute-names */
     ret->sem.ref_tbl.keys  = PFarray_copy(keys);
 
@@ -1377,6 +1377,7 @@
             res_type = aat_bln;
             break;
 
+        case alg_fun_fn_translate:
         case alg_fun_fn_replace:
             assert (refs.count == 3);
             /* make sure all attributes are of type string */
@@ -1438,6 +1439,69 @@
             res_type = n->schema.items[ix[0]].type;
             break;
 
+        case alg_fun_pf_add_doc:
+            assert(refs.count == 2);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types*/
+            res_type = aat_docmgmt | aat_str | aat_str1;
+            break;
+
+        case alg_fun_pf_add_doc_str:
+            assert(refs.count == 3);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+            assert(n->schema.items[ix[2]].type == aat_str);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types*/
+            res_type = aat_docmgmt | aat_str | aat_str1 | aat_str2;
+            break;
+
+        case alg_fun_pf_add_doc_int:
+            assert(refs.count == 3);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+            assert(n->schema.items[ix[2]].type == aat_int);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types */
+            res_type = aat_docmgmt | aat_str | aat_str1 | aat_int;
+            break;
+
+        case alg_fun_pf_add_doc_str_int:
+            assert(refs.count == 4);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+            assert(n->schema.items[ix[1]].type == aat_str);
+            assert(n->schema.items[ix[2]].type == aat_str);
+            assert(n->schema.items[ix[3]].type == aat_int);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types */
+            res_type = aat_docmgmt | aat_str | aat_str1 | aat_str2 | aat_int;
+            break;
+
+        case alg_fun_pf_del_doc:
+            assert(refs.count == 1);
+
+            /* make sure atts are of the correct type */
+            assert(n->schema.items[ix[0]].type == aat_str);
+
+            /* the returning type of doc management functions
+             * is aat_docmgmt bitwise OR the attribute types */
+            res_type = aat_docmgmt | aat_str1;
+            break;
+
         case alg_fun_upd_delete:
             assert(refs.count == 1);
 
@@ -2037,7 +2101,7 @@
  * Worker for PFla_rownum, PFla_rowrank, and PFla_rank.
  */
 static PFla_op_t *
-sort_col (const PFla_op_t *n, PFla_op_kind_t kind, char *name, 
+sort_col (const PFla_op_t *n, PFla_op_kind_t kind, char *name,
           PFalg_att_t a, PFord_ordering_t s, PFalg_att_t p)
 {
     PFla_op_t    *ret = la_op_wire1 (kind, n);
@@ -3933,7 +3997,7 @@
     ret->schema.items = NULL;
 
     ret->sem.col_ref.pos = col_pos;
-    
+
     return ret;
 }
 
@@ -4421,11 +4485,11 @@
         case la_fun_param:
             return PFla_fun_param (left, right,
                                    n->schema);
-                                   
+
         case la_fun_frag_param:
             return PFla_fun_frag_param (left, right,
                                         n->sem.col_ref.pos);
-                                   
+
         case la_string_join:
             return PFla_fn_string_join (
                        left, right,

Index: builtins.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/builtins.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- builtins.c  11 Jan 2008 10:46:56 -0000      1.71
+++ builtins.c  18 Jan 2008 16:11:36 -0000      1.72
@@ -665,7 +665,7 @@
     (void) loop; (void) ordering;
 
     return (struct PFla_pair_t) {
-        .rel = error( 
+        .rel = error(
                    project (
                        fun_1to1 (
                            eqjoin (
@@ -1690,6 +1690,53 @@
         .frag = PFla_empty_set () };
 }
 
+/**
+ * Algebra implementation for
+ * <code>fn:translate(xs:string?, xs:string, xs:string)</code>
+ */
+struct PFla_pair_t
+PFbui_fn_translate (const PFla_op_t *loop, bool ordering,
+                    struct PFla_pair_t *args)
+{
+    (void) ordering;
+
+    return (struct PFla_pair_t) {
+        .rel = project (
+                   fun_1to1 (
+                       eqjoin (
+                           eqjoin (
+                               disjunion (
+                                   args[0].rel,
+                                   attach (
+                                       attach (
+                                           difference (
+                                               loop,
+                                               project (
+                                                   args[0].rel,
+                                                   proj (att_iter, att_iter))),
+                                           att_pos, lit_nat (1)),
+                                       att_item, lit_str (""))),
+                               project (args[1].rel,
+                                        proj (att_iter1, att_iter),
+                                        proj (att_item1, att_item)),
+                               att_iter,
+                               att_iter1),
+                           project (args[2].rel,
+                                    proj (att_iter2, att_iter),
+                                    proj (att_item2, att_item)),
+                           att_iter,
+                           att_iter2),
+                       alg_fun_fn_translate,
+                       att_res,
+                       attlist (att_item, att_item1, att_item2)),
+                proj (att_iter, att_iter),
+                proj (att_pos, att_pos),
+                proj (att_item, att_res)),
+
+
+        .frag = PFla_empty_set () };
+}
+
 /* ------------------------------------------ */
 /* 7.5. Functions Based on Substring Matching */
 /* ------------------------------------------ */
@@ -4519,6 +4566,161 @@
         .frag = args[0].frag };
 }
 
+/**
+ * Built-in function pf:add-doc(string, string)
+ */
+struct PFla_pair_t
+PFbui_pf_add_doc (const PFla_op_t *loop, bool ordering,
+                  struct PFla_pair_t *args)
+{
+    (void) loop; (void) ordering;
+
+    return (struct PFla_pair_t) {
+        .rel = project (fun_1to1 (
+                            eqjoin (args[0].rel,
+                               project (args[1].rel,
+                                        proj (att_iter1, att_iter),
+                                        proj (att_item1, att_item)),
+                               att_iter,
+                               att_iter1),
+                            alg_fun_pf_add_doc,
+                            att_res,
+                            attlist (att_item, att_item1)),
+                        proj (att_iter, att_iter),
+                        proj (att_pos, att_pos),
+                        proj (att_item, att_res)),
+        .frag = args[0].frag };
+}
+
+/**
+ * Built-in function pf:add-doc(string, string, string)
+ */
+struct PFla_pair_t
+PFbui_pf_add_doc_str (const PFla_op_t *loop, bool ordering,
+                      struct PFla_pair_t *args)
+{
+    (void) loop; (void) ordering;
+
+    return (struct PFla_pair_t) {
+        .rel = project (fun_1to1 (
+                           eqjoin (
+                               eqjoin (
+                                   args[0].rel,
+                                   project (args[1].rel,
+                                            proj (att_iter1, att_iter),
+                                            proj (att_item1, att_item)),
+                                   att_iter,
+                                   att_iter1),
+                               project (args[2].rel,
+                                        proj (att_iter2, att_iter),
+                                        proj (att_item2, att_item)),
+                               att_iter,
+                               att_iter2),
+                            alg_fun_pf_add_doc_str,
+                            att_res,
+                            attlist (att_item, att_item1, att_item2)),
+                        proj (att_iter, att_iter),
+                        proj (att_pos, att_pos),
+                        proj (att_item, att_res)),
+
+        .frag = args[0].frag };
+}
+
+/**
+ * Built-in function pf:add-doc(string, string, int)
+ */
+struct PFla_pair_t
+PFbui_pf_add_doc_int (const PFla_op_t *loop, bool ordering,
+                      struct PFla_pair_t *args)
+{
+    (void) loop; (void) ordering;
+
+    return (struct PFla_pair_t) {
+        .rel = project (fun_1to1 (
+                           eqjoin (
+                               eqjoin (
+                                   args[0].rel,
+                                   project (args[1].rel,
+                                            proj (att_iter1, att_iter),
+                                            proj (att_item1, att_item)),
+                                   att_iter,
+                                   att_iter1),
+                               project (args[2].rel,
+                                        proj (att_iter2, att_iter),
+                                        proj (att_item2, att_item)),
+                               att_iter,
+                               att_iter2),
+                            alg_fun_pf_add_doc_int,
+                            att_res,
+                            attlist (att_item, att_item1, att_item2)),
+                        proj (att_iter, att_iter),
+                        proj (att_pos, att_pos),
+                        proj (att_item, att_res)),
+
+        .frag = args[0].frag };
+}
+
+/**
+ * Built-in function pf:add-doc(string, string, string, int)
+ */
+struct PFla_pair_t
+PFbui_pf_add_doc_str_int (const PFla_op_t *loop, bool ordering,
+                          struct PFla_pair_t *args)
+{
+    (void) loop; (void) ordering;
+
+    return (struct PFla_pair_t) {
+        .rel = project (fun_1to1 (
+                       eqjoin (
+                           eqjoin (
+                               eqjoin (
+                                   args[0].rel,
+                                   project (args[1].rel,
+                                            proj (att_iter1, att_iter),
+                                            proj (att_item1, att_item)),
+                                   att_iter,
+                                   att_iter1),
+                               project (args[2].rel,
+                                        proj (att_iter2, att_iter),
+                                        proj (att_item2, att_item)),
+                               att_iter,
+                               att_iter2),
+                            project (args[3].rel,
+                                        proj (att_iter3, att_iter),
+                                        proj (att_item3, att_item)),
+                            att_iter,
+                            att_iter3),
+                            alg_fun_pf_add_doc_str_int,
+                            att_res,
+                            attlist (att_item,
+                                     att_item1,
+                                     att_item2,
+                                     att_item3))),
+        .frag = args[0].frag };
+}
+
+/**
+ * Built-in function pf:del-doc(string)
+ */
+struct PFla_pair_t
+PFbui_pf_del_doc (const PFla_op_t *loop, bool ordering,
+                  struct PFla_pair_t *args)
+{
+    (void) loop; (void) ordering;
+
+    return (struct PFla_pair_t) {
+        .rel = project (fun_1to1 (
+                            args[0].rel,
+                            alg_fun_pf_del_doc,
+                            att_res,
+                            attlist (att_item)),
+                        proj (att_iter, att_iter),
+                        proj (att_pos, att_pos),
+                        proj (att_item, att_res)),
+
+        .frag = args[0].frag };
+}
+
 /* -------------------- */
 /* #3. UPDATE FUNCTIONS */
 /* -------------------- */


-------------------------------------------------------------------------
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

Reply via email to