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

Modified Files:
      Tag: PF_ROX
        algebra_cse.c builtins.c core2alg.brg logical.c physical.c 
        planner.c 
Log Message:
propagated changes of Wednesday Jan 30 2008 - Saturday Feb 09 2008
from the development trunk to the PF_ROX branch


Index: core2alg.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/core2alg.brg,v
retrieving revision 1.60
retrieving revision 1.60.4.1
diff -u -d -r1.60 -r1.60.4.1
--- core2alg.brg        11 Jan 2008 10:46:56 -0000      1.60
+++ core2alg.brg        9 Feb 2008 08:40:11 -0000       1.60.4.1
@@ -43,6 +43,8 @@
 #include "qname.h"
 #include "mem.h"
 #include "alg_dag.h"
+/* recursion-depth option */
+#include "options.h"
 
 /* PFvar_t */
 #include "variable.h"
@@ -308,6 +310,8 @@
 /** Algebra equivalent of a Core tree node */
 #define A(p) ((p)->alg)
[...1364 lines suppressed...]
+            PFoops (OOPS_WARNING,
+                    "Only the last recursion depth option is used.");
 
-    /* label the core tree bottom up */
-    PFcore2alg_label (r);
+        ctx.recursion_depth = atoi (*((char **) PFarray_top (options)));
+    }
+    
+    /* Initialize stack recording the active user-defined functions */
+    ctx.fun_active = PFarray (sizeof (fun_active_t));
 
+    /* initially do not memorize algebra translations */
+    ctx.core2alg_map = NULL;
+    
     /* invoke compilation */
-    reduce (r, 1);
+    reduce (&ctx, r, 1);
 
     return A(r).rel;
 }

Index: physical.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/physical.c,v
retrieving revision 1.53
retrieving revision 1.53.2.1
diff -u -d -r1.53 -r1.53.2.1
--- physical.c  20 Jan 2008 22:35:03 -0000      1.53
+++ physical.c  9 Feb 2008 08:40:14 -0000       1.53.2.1
@@ -2078,6 +2078,65 @@
 }
 
 /**
+ * Constructor for op:to operator
+ */
+PFpa_op_t *
+PFpa_to (const PFpa_op_t *n, PFalg_att_t res,
+         PFalg_att_t att1, PFalg_att_t att2)
+{
+    PFpa_op_t *ret = wire1 (pa_to, n);
+
+    /* allocate memory for the result schema */
+    ret->schema.count = n->schema.count + 1;
+    ret->schema.items
+        = PFmalloc (ret->schema.count * sizeof (*(ret->schema.items)));
+
+    /* copy schema from n */
+    for (unsigned int i = 0; i < n->schema.count; i++)
+        ret->schema.items[i] = n->schema.items[i];
+
+#ifndef NDEBUG
+    /* verify that attributes 'att1' and 'att2' are attributes of n */
+    if (!check_col (n, att1))
+        PFoops (OOPS_FATAL,
+                "attribute `%s' referenced in op:to not found",
+                PFatt_str (att1));
+    if (!check_col (n, att2))
+        PFoops (OOPS_FATAL,
+                "attribute `%s' referenced in op:to not found",
+                PFatt_str (att2));
+#endif
+
+    /* finally add schema item for new attribute */
+    ret->schema.items[n->schema.count].name = res;
+    ret->schema.items[n->schema.count].type = aat_int;
+
+    /* insert semantic value (input attributes and result attribute)
+       into the result */
+    ret->sem.binary.res = res;
+    ret->sem.binary.att1 = att1;
+    ret->sem.binary.att2 = att2;
+
+    /* ---- orderings ---- */
+    for (unsigned int i = 0; i < PFord_set_count (n->orderings); i++) {
+        PFord_set_add (ret->orderings, PFord_set_at (n->orderings, i));
+
+        /* if we have already an ordering we can also add the new
+           generated column at the end. It won't break the ordering. */
+        PFord_set_add (ret->orderings,
+                       PFord_refine (
+                           PFord_set_at (n->orderings, i),
+                           res, DIR_ASC));
+
+    }
+
+    /* ---- costs ---- */
+    ret->cost = DEFAULT_COST + n->cost;
+
+    return ret;
+}
+
+/**
  * HashCount: Hash-based Count operator. Does neither benefit from
  * any existing ordering, nor does it provide/preserve any input
  * ordering.
@@ -2794,60 +2853,36 @@
  * function.  Returns a (frag, result) pair.
  */
 PFpa_op_t *
-PFpa_doc_tbl (const PFpa_op_t *rel, PFalg_att_t iter, PFalg_att_t item)
+PFpa_doc_tbl (const PFpa_op_t *n, PFalg_att_t res, PFalg_att_t att)
 {
-    PFpa_op_t         *ret;
-
-#ifndef NDEBUG
-    unsigned short found = 0;
-
-    for (unsigned int i = 0; i < rel->schema.count; i++)
-        if (rel->schema.items[i].name == iter
-            || rel->schema.items[i].name == item)
-            found++;
-
-    if (found != 2)
-        PFoops (OOPS_FATAL, "document access requires iter|item schema");
-#endif
+    unsigned int i;
+    PFpa_op_t   *ret;
 
-    ret = wire1 (pa_doc_tbl, rel);
+    ret = wire1 (pa_doc_tbl, n);
 
-    ret->sem.ii.iter = iter;
-    ret->sem.ii.item = item;
+    /* store columns to work on in semantical field */
+    ret->sem.unary.res = res;
+    ret->sem.unary.att = att;
 
-    /* The schema of the result part is iter|item */
-    ret->schema.count = 2;
+    /* allocate memory for the result schema */
+    ret->schema.count = n->schema.count + 1;
     ret->schema.items
-        = PFmalloc (ret->schema.count * sizeof (*ret->schema.items));
-
-    ret->schema.items[0]
-        = (PFalg_schm_item_t) { .name = iter,
-                                .type = aat_nat };
-    ret->schema.items[1]
-        = (PFalg_schm_item_t) { .name = item,
-                                .type = aat_pnode };
-
-    /* ---- doc_tbl: orderings ---- */
+        = PFmalloc (ret->schema.count * sizeof (*(ret->schema.items)));
 
-    /* If the input is sorted by `iter', the output will be as well. */
-    bool sorted_by_iter = false;
+    for (i = 0; i < n->schema.count; i++)
+        ret->schema.items[i] = n->schema.items[i];
 
-    for (unsigned int i = 0; i < PFord_set_count (rel->orderings); i++)
-        if (PFord_implies (PFord_set_at (rel->orderings, i),
-                           sortby (iter))) {
-            sorted_by_iter = true;
-            break;
-        }
+    ret->schema.items[i]
+        = (struct PFalg_schm_item_t) { .name = res,
+                                       .type = aat_pnode };
 
-    if (sorted_by_iter) {
-        if (PFprop_const (rel->prop, item))
-            PFord_set_add (ret->orderings, sortby (iter, item));
-        else
-            PFord_set_add (ret->orderings, sortby (iter));
-    }
+    /* ---- doc_tbl: orderings ---- */
+    /*    ordering stays the same   */
+    for (unsigned int i = 0; i < PFord_set_count (n->orderings); i++)
+        PFord_set_add (ret->orderings, PFord_set_at (n->orderings, i));
 
     /* ---- doc_tbl: costs ---- */
-    ret->cost = DEFAULT_COST + rel->cost;
+    ret->cost = DEFAULT_COST + n->cost;
 
     return ret;
 }
@@ -3316,7 +3351,8 @@
 /**
  * Constructor for error
  */
-PFpa_op_t * PFpa_error (const PFpa_op_t *n,  PFalg_att_t att)
+PFpa_op_t * PFpa_error (const PFpa_op_t *n,  PFalg_att_t att,
+                        PFalg_simple_type_t att_ty)
 {
     PFpa_op_t *ret = wire1 (pa_error, n);
 
@@ -3331,16 +3367,16 @@
     for (unsigned int i = 0; i < n->schema.count; i++) {
         ret->schema.items[i] = n->schema.items[i];
         if (att == n->schema.items[i].name)
-            ret->schema.items[i].type = 0;
+            ret->schema.items[i].type = att_ty;
     }
 
     ret->sem.err.att = att;
-    ret->sem.err.str = "I was there, Case; I was there when "
-                       "they invented your kind";
+    ret->sem.err.str = NULL; /* error message is stored in column @a att */
 
     /* ordering stays the same */
     for (unsigned int i = 0; i < PFord_set_count (n->orderings); i++)
         PFord_set_add (ret->orderings, PFord_set_at (n->orderings, i));
+
     /* costs */
     ret->cost = DEFAULT_COST + n->cost;
 

Index: planner.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/planner.c,v
retrieving revision 1.47
retrieving revision 1.47.2.1
diff -u -d -r1.47 -r1.47.2.1
--- planner.c   15 Jan 2008 09:29:20 -0000      1.47
+++ planner.c   9 Feb 2008 08:40:15 -0000       1.47.2.1
@@ -1193,6 +1193,29 @@
 }
 
 /**
+ * Generate physical plan for integer enumeration (op:to).
+ */
+static PFplanlist_t *
+plan_to (const PFla_op_t *n)
+{
+    PFplanlist_t *ret = new_planlist ();
+
+    assert (n);
+    assert (n->kind == la_to);
+    assert (L(n)); assert (L(n)->plans);
+
+    /* consider each plan in n */
+    for (unsigned int i = 0; i < PFarray_last (L(n)->plans); i++)
+        add_plan (ret,
+                  to (*(plan_t **) PFarray_at (L(n)->plans, i),
+                      n->sem.binary.res,
+                      n->sem.binary.att1,
+                      n->sem.binary.att2));
+
+    return ret;
+}
+
+/**
  * Generate physical plan for logical aggregation operators
  * (avg, max, min, sum).
  */
@@ -1557,52 +1580,12 @@
 static PFplanlist_t *
 plan_doc_tbl (const PFla_op_t *n)
 {
-    PFplanlist_t  *ret                = new_planlist ();
-    PFplanlist_t  *ordered            = new_planlist ();
-    plan_t        *cheapest_unordered = NULL;
-    plan_t        *cheapest_ordered   = NULL;
-
-#ifndef NDEBUG
-    /* ensure that input and output columns have the same name */
-    assert (n->sem.doc_tbl.item == n->sem.doc_tbl.item_res);
-#endif
-
-    /* find the cheapest plan for our argument */
-    for (unsigned int i = 0; i < PFarray_last (L(n)->plans); i++)
-        if (!cheapest_unordered
-            || costless (*(plan_t **) PFarray_at (L(n)->plans, i),
-                         cheapest_unordered))
-            cheapest_unordered
-                = *(plan_t **) PFarray_at (L(n)->plans, i);
+    PFplanlist_t *ret = new_planlist ();
 
-    /* an ordering by `iter' is typically helpful -> sort all plans */
     for (unsigned int i = 0; i < PFarray_last (L(n)->plans); i++)
-        add_plans (ordered,
-                   ensure_ordering (
-                       *(plan_t **) PFarray_at (L(n)->plans, i),
-                       sortby (n->sem.doc_tbl.iter)));
-
-    for (unsigned int i = 0; i < PFarray_last (ordered); i++)
-        if (!cheapest_ordered
-            || costless (*(plan_t **) PFarray_at (ordered, i),
-                         cheapest_ordered))
-            cheapest_ordered = *(plan_t **) PFarray_at (ordered, i);
-
-    /*
-     * The plan `cheapest_unordered' is always the cheapest possible
-     * plan.  However, an ordered plan could still be benefitial,
-     * even if it is slightly more expensive on its own.  We assume
-     * that the ordering makes up the cost of an unordered plan, if
-     * its cost is at most 1.5 times the cost of an unordered plan.
-     */
-    if (cheapest_ordered->cost <= cheapest_unordered->cost * 1.5)
-        add_plan (ret, doc_tbl (cheapest_ordered,
-                                n->sem.doc_tbl.iter,
-                                n->sem.doc_tbl.item));
-    else
-        add_plan (ret, doc_tbl (cheapest_unordered,
-                                n->sem.doc_tbl.iter,
-                                n->sem.doc_tbl.item));
+        add_plan (ret,
+                  doc_tbl (*(plan_t **) PFarray_at (L(n)->plans, i),
+                           n->sem.doc_tbl.res, n->sem.doc_tbl.att));
 
     return ret;
 }
@@ -2030,7 +2013,8 @@
 
     for (unsigned int i = 0; i < PFarray_last (L(n)->plans); i++)
         add_plan (ret, error(*(plan_t **) PFarray_at (L(n)->plans, i),
-                             n->sem.err.att));
+                             n->sem.err.att,
+                             type_of (n->schema, n->sem.err.att)));
 
     return ret;
 }
@@ -2863,11 +2847,12 @@
 
         case la_bool_not:
                                 plans = plan_unary (n);        break;
+        case la_to:             plans = plan_to (n);           break;
+        case la_count:          plans = plan_count (n);        break;
         case la_avg:            plans = plan_aggr (pa_avg, n); break;
         case la_max:            plans = plan_aggr (pa_max, n); break;
         case la_min:            plans = plan_aggr (pa_min, n); break;
         case la_sum:            plans = plan_aggr (pa_sum, n); break;
-        case la_count:          plans = plan_count (n);        break;
 
         case la_rownum:         plans = plan_rownum (n);       break;
         case la_rowrank:

Index: algebra_cse.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/algebra_cse.c,v
retrieving revision 1.65
retrieving revision 1.65.4.1
diff -u -d -r1.65 -r1.65.4.1
--- algebra_cse.c       11 Jan 2008 10:46:56 -0000      1.65
+++ algebra_cse.c       9 Feb 2008 08:40:09 -0000       1.65.4.1
@@ -275,6 +275,7 @@
         case la_num_gt:
         case la_bool_and:
         case la_bool_or:
+        case la_to:
             return (a->sem.binary.att1 == b->sem.binary.att1
                     && a->sem.binary.att2 == b->sem.binary.att2
                     && a->sem.binary.res == b->sem.binary.res);
@@ -285,13 +286,6 @@
                     && a->sem.unary.res == b->sem.unary.res);
             break;
 
-        case la_to:
-            return (a->sem.to.res == b->sem.to.res
-                    && a->sem.to.att1 == b->sem.to.att1
-                    && a->sem.to.att2 == b->sem.to.att2
-                    && a->sem.to.part == b->sem.to.part);
-            break;
-
         case la_avg:
         case la_max:
         case la_min:
@@ -387,9 +381,8 @@
             break;
 
         case la_doc_tbl:
-            return (a->sem.doc_tbl.iter        == b->sem.doc_tbl.iter
-                    && a->sem.doc_tbl.item     == b->sem.doc_tbl.item
-                    && a->sem.doc_tbl.item_res == b->sem.doc_tbl.item_res);
+            return (a->sem.doc_tbl.att == b->sem.doc_tbl.att &&
+                    a->sem.doc_tbl.res == b->sem.doc_tbl.res);
             break;
 
         case la_merge_adjacent:

Index: logical.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/logical.c,v
retrieving revision 1.78
retrieving revision 1.78.2.1
diff -u -d -r1.78 -r1.78.2.1
--- logical.c   20 Jan 2008 22:35:03 -0000      1.78
+++ logical.c   9 Feb 2008 08:40:13 -0000       1.78.2.1
@@ -986,11 +986,13 @@
 
         /* see if we have duplicate attributes now */
         for (j = 0; j < i; j++)
-            if (ret->sem.proj.items[i].new == ret->sem.proj.items[j].new)
+            if (ret->sem.proj.items[i].new == ret->sem.proj.items[j].new) {
+                fprintf (stderr, "foo\n");
                 PFoops (OOPS_FATAL,
                         "projection results in duplicate attribute `%s' "
                         "(attributes %i and %i)",
                         PFatt_str (ret->sem.proj.items[i].new), i+1, j+1);
+            }
     }
 
     return ret;
@@ -1901,27 +1903,14 @@
 /**
  * Constructor for op:to operator
  */
-PFla_op_t * PFla_to (const PFla_op_t *n,
-                     PFalg_att_t res,
-                     PFalg_att_t att1,
-                     PFalg_att_t att2,
-                     PFalg_att_t part)
+PFla_op_t *
+PFla_to (const PFla_op_t *n, PFalg_att_t res,
+         PFalg_att_t att1, PFalg_att_t att2)
 {
     PFla_op_t    *ret = la_op_wire1 (la_to, n);
 
-    /* set number of schema items in the result schema
-     * (partitioning attribute plus result attribute)
-     */
-    ret->schema.count = part ? 2 : 1;
-
-    ret->schema.items
-        = PFmalloc (ret->schema.count * sizeof (*(ret->schema.items)));
-
-
 #ifndef NDEBUG
-    /* verify that attributes 'att' and 'part' are attributes of n
-     * and include them into the result schema
-     */
+    /* verify that attributes 'att1' and 'att2' are attributes of n */
     if (!PFprop_ocol (n, att1))
         PFoops (OOPS_FATAL,
                 "attribute `%s' referenced in op:to not found",
@@ -1930,26 +1919,29 @@
         PFoops (OOPS_FATAL,
                 "attribute `%s' referenced in op:to not found",
                 PFatt_str (att2));
-    if (part && !PFprop_ocol (n, part))
-        PFoops (OOPS_FATAL,
-                "partitioning attribute `%s' referenced in op:to not found",
-                PFatt_str (part));
 #endif
 
-    ret->schema.items[0].name = res;
-    ret->schema.items[0].type = aat_int;
-    if (part) {
-        ret->schema.items[1].name = part;
-        ret->schema.items[1].type = PFprop_type_of (n, part);
-    }
+    /* allocate memory for the result schema (schema(n) + 'res') */
+    ret->schema.count = n->schema.count + 1;
+    ret->schema.items
+        = PFmalloc (ret->schema.count * sizeof (*(ret->schema.items)));
 
-    /* insert semantic value (input attributes, partitioning
-     * attribute(s), and result attribute) into the result
+    /* copy schema from 'n' argument */
+    for (unsigned int i = 0; i < n->schema.count; i++)
+        ret->schema.items[i] = n->schema.items[i];
+
+    /* add the information on the 'res' attribute; it is of type
+     * integer and named 'res'
      */
-    ret->sem.to.res = res;
-    ret->sem.to.att1 = att1;
-    ret->sem.to.att2 = att2;
-    ret->sem.to.part = part;
+    ret->schema.items[n->schema.count].name = res;
+    ret->schema.items[n->schema.count].type = aat_int;
+
+    /* insert semantic value (operand attributes and result attribute)
+     * into the result
+     */
+    ret->sem.binary.att1 = att1;
+    ret->sem.binary.att2 = att2;
+    ret->sem.binary.res = res;
 
     return ret;
 }
@@ -2946,29 +2938,28 @@
  * function.  Returns a (frag, result) pair.
  */
 PFla_op_t *
-PFla_doc_tbl (const PFla_op_t *rel,
-              PFalg_att_t iter, PFalg_att_t item,
-              PFalg_att_t item_res)
+PFla_doc_tbl (const PFla_op_t *n, PFalg_att_t res, PFalg_att_t att)
 {
-    PFla_op_t         *ret;
+    unsigned int i;
+    PFla_op_t   *ret;
 
-    ret = la_op_wire1 (la_doc_tbl, rel);
+    ret = la_op_wire1 (la_doc_tbl, n);
 
     /* store columns to work on in semantical field */
-    ret->sem.doc_tbl.iter     = iter;
-    ret->sem.doc_tbl.item     = item;
-    ret->sem.doc_tbl.item_res = item_res;
+    ret->sem.doc_tbl.res = res;
+    ret->sem.doc_tbl.att = att;
 
-    /* The schema of the result part is iter|item */
-    ret->schema.count = 2;
+    /* allocate memory for the result schema */
+    ret->schema.count = n->schema.count + 1;
     ret->schema.items
-        = PFmalloc (ret->schema.count * sizeof (*ret->schema.items));
+        = PFmalloc (ret->schema.count * sizeof (*(ret->schema.items)));
 
-    ret->schema.items[0]
-        = (PFalg_schm_item_t) { .name = iter,
-                                .type = PFprop_type_of (rel, iter) };
-    ret->schema.items[1]
-        = (PFalg_schm_item_t) { .name = item_res, .type = aat_pnode };
+    for (i = 0; i < n->schema.count; i++)
+        ret->schema.items[i] = n->schema.items[i];
+
+    ret->schema.items[i]
+        = (struct PFalg_schm_item_t) { .name = res,
+                                       .type = aat_pnode };
 
     return ret;
 }
@@ -3489,13 +3480,15 @@
 
 
 /**
- * Construct for an error message.
+ * Constructor for a runtime error message.
  *
+ * This operator generates a runtime error (using the string in column
+ * @a att) if a tuple flows through it.
  */
 PFla_op_t *
-PFla_error (const PFla_op_t *n, PFalg_att_t att)
+PFla_error_ (const PFla_op_t *n, PFalg_att_t att, PFalg_simple_type_t att_ty)
 {
-    PFla_op_t    *ret;
+    PFla_op_t   *ret;
     unsigned int i;
 
     assert(n);
@@ -3511,16 +3504,26 @@
     for (i = 0; i < n->schema.count; i++) {
         ret->schema.items[i] = n->schema.items[i];
         if (att == n->schema.items[i].name)
-            ret->schema.items[i].type = 0;
+            ret->schema.items[i].type = att_ty;
     }
 
     ret->sem.err.att = att;
-    ret->sem.err.str =  "Flying is learning how to throw yourself "
-                        "at the ground and miss.";
+    ret->sem.err.str = NULL; /* error message is stored in column @a att */
 
     return ret;
 }
 
+/**
+ * Constructor for a runtime error message.
+ *
+ * This operator generates a runtime error (using the string in column
+ * @a att) if a tuple flows through it.
+ */
+PFla_op_t *
+PFla_error (const PFla_op_t *n, PFalg_att_t att)
+{
+    return PFla_error_ (n, att, 0);
+}
 
 /**
  * Constructor for a conditional error message.
@@ -4225,10 +4228,9 @@
 
         case la_to:
             return PFla_to (left,
-                            n->sem.to.res,
-                            n->sem.to.att1,
-                            n->sem.to.att2,
-                            n->sem.to.part);
+                            n->sem.binary.res,
+                            n->sem.binary.att1,
+                            n->sem.binary.att2);
 
         case la_avg:
         case la_max:
@@ -4341,9 +4343,8 @@
 
         case la_doc_tbl:
             return PFla_doc_tbl (left,
-                                 n->sem.doc_tbl.iter,
-                                 n->sem.doc_tbl.item,
-                                 n->sem.doc_tbl.item_res);
+                                 n->sem.doc_tbl.res,
+                                 n->sem.doc_tbl.att);
 
         case la_doc_access:
             return PFla_doc_access (left, right,
@@ -4422,7 +4423,8 @@
             return PFla_empty_frag ();
 
         case la_error:
-            return PFla_error (left, n->sem.err.att);
+            return PFla_error_ (left, n->sem.err.att,
+                                PFprop_type_of (n, n->sem.err.att));
 
         case la_cond_err:
             return PFla_cond_err (left, right,

Index: builtins.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/builtins.c,v
retrieving revision 1.75
retrieving revision 1.75.2.1
diff -u -d -r1.75 -r1.75.2.1
--- builtins.c  23 Jan 2008 14:30:03 -0000      1.75
+++ builtins.c  9 Feb 2008 08:40:10 -0000       1.75.2.1
@@ -638,7 +638,12 @@
     (void) loop; (void) ordering; (void) args;
 
     return (struct PFla_pair_t) {
-        .rel  = NULL,
+        .rel  = error (
+                    attach (
+                        attach (loop, att_pos, lit_nat (1)),
+                        att_item,
+                        lit_str 
("http://www.w3.org/2005/xqt-errors#FOER0000";)),
+                    att_item),
         .frag = PFla_empty_set ()};
 }
 
@@ -2384,6 +2389,7 @@
                                                args[0].rel,
                                                proj (att_iter, att_iter))),
                                        att_pos, lit_nat (1)),
+                                   /* use '|' as invalid uri */
                                    att_item, lit_str ("|"))),
                            project (args[1].rel,
                                     proj (att_iter1, att_iter),
@@ -3148,12 +3154,12 @@
 PFbui_fn_zero_or_one (const PFla_op_t *loop, bool ordering,
                       struct PFla_pair_t *args)
 {
-    PFla_op_t *count = eq (attach (
+    PFla_op_t *count = gt (attach (
                                count (
                                    project (args[0].rel,
                                             proj (att_iter, att_iter)),
                                    att_item, att_iter),
-                               att_item1, lit_int (1)),
+                               att_item1, lit_int (2)),
                            att_res, att_item1, att_item);
 
     char *err_string = "err:FORG0003, fn:zero-or-one called with "
@@ -3632,8 +3638,8 @@
     (void) loop;
     (void) ordering;
 
-    PFla_op_t *to = to (project (
-                            eqjoin (
+    PFla_op_t *to = project (
+                        to (eqjoin (
                                 project (
                                     args[0].rel,
                                     proj (att_iter, att_iter),
@@ -3644,13 +3650,11 @@
                                     proj (att_item1, att_item)),
                                 att_iter,
                                 att_iter1),
-                            proj (att_iter, att_iter),
-                            proj (att_item, att_item),
-                            proj (att_item1, att_item1)),
-                        att_item,
-                        att_item,
-                        att_item1,
-                        att_iter);
+                            att_res,
+                            att_item,
+                            att_item1),
+                        proj (att_iter, att_iter),
+                        proj (att_item, att_res));
 
     return (struct PFla_pair_t) {
         .rel = rank (
@@ -3742,13 +3746,13 @@
 {
     (void) loop; (void) ordering;
 
-    PFla_op_t *doc = doc_tbl (project (args[0].rel,
-                                       proj (att_iter, att_iter),
-                                       proj (att_item, att_item)),
-                              att_iter, att_item, att_item);
+    PFla_op_t *doc = doc_tbl (args[0].rel, att_res, att_item);
 
     return (struct PFla_pair_t) {
-        .rel  = attach (roots (doc), att_pos, lit_nat (1)),
+        .rel  = project (roots (doc),
+                         proj (att_iter, att_iter),
+                         proj (att_pos, att_pos),
+                         proj (att_item, att_res)),
         .frag = PFla_set (fragment (doc)) };
 }
 


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