Update of /cvsroot/monetdb/pathfinder/compiler/algebra/prop
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv11514/algebra/prop

Modified Files:
        prop_card.c prop_composite_key.c prop_const.c prop_dom.c 
        prop_fd.c prop_guide.c prop_icol.c prop_key.c prop_level.c 
        prop_lineage.c prop_ocol.c prop_ori_names.c prop_rec_delta.c 
        prop_req_node.c prop_reqval.c prop_set.c prop_trace_names.c 
        prop_unq_names.c 
Log Message:
-- Replaced aggregate operators count, min, max, avg, sum, prod, seqty1,
   and all in the algebra by a single aggregate operator ``aggr'' 
   that can handle multiple aggregates. The aggregate entries 
   are of kind count, min, max, avg, sum, prod, seqty1, all, and dist. 

-- Added new aggregate kind ``dist'' that allows to represent group by
   columns that functionally depend on the partitioning criterion
   in the result of the grouping aggregate.

-- Added rewrite that merges aggregates.                                        
                                             
                                                                                
                                             
-- Added rewrite that removes superfluous aggregates.                           
                                             
                                                                                
                                             
-- Added rewrite that pushes a rank operator through an aggregate.              
                                             
                                                                                
                                             
-- Extended the XML import to cope with the old                                 
                                             
   as well as the new representation of aggregates.                             
                                             


U prop_unq_names.c
Index: prop_unq_names.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_unq_names.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- prop_unq_names.c    7 May 2009 14:26:33 -0000       1.43
+++ prop_unq_names.c    12 Jun 2009 13:06:14 -0000      1.44
@@ -415,15 +415,9 @@
             new_name_pair (np_list, n->sem.unary.res);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
-            new_name_pair (np_list, n->sem.aggr.res);
+        case la_aggr:
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                new_name_pair (np_list, n->sem.aggr.aggr[i].res);
             if (n->sem.aggr.part)
                 add_name_pair (np_list,
                                n->sem.aggr.part,

U prop_ocol.c
Index: prop_ocol.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_ocol.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- prop_ocol.c 7 May 2009 14:26:03 -0000       1.74
+++ prop_ocol.c 12 Jun 2009 13:06:14 -0000      1.75
@@ -709,52 +709,42 @@
             ocols_count (n)++;
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
+        case la_aggr:
             /* set number of schema items in the result schema:
-             * result column plus partitioning column
+             * result columns plus partitioning column
              * (if available -- constant optimizations may
              *  have removed it).
              */
-            new_ocols (n, n->sem.aggr.part ? 2 : 1);
+            new_ocols (n, n->sem.aggr.count + (n->sem.aggr.part ? 1 : 0));
 
             /* verify that columns 'col' and 'part' are columns of n
              * and include them into the result schema
              */
-            for (unsigned int i = 0; i < ocols_count (L(n)); i++) {
-                if (n->sem.aggr.col == ocol_at (L(n), i).name) {
-                    ocol_at (n, 0) = ocol_at (L(n), i);
-                    ocol_at (n, 0).name = n->sem.aggr.res;
-                }
-                if (n->sem.aggr.part &&
-                    n->sem.aggr.part == ocol_at (L(n), i).name) {
-                    ocol_at (n, 1) = ocol_at (L(n), i);
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++) {
+                PFalg_col_t col = n->sem.aggr.aggr[i].col;
+                if (col) {
+                    if (!PFprop_ocol (L(n), col))
+                        PFoops (OOPS_FATAL,
+                                "column `%s' referenced in aggregate not 
found",
+                                PFcol_str (col));
+                    ocol_at (n, i).type = PFprop_type_of (L(n), col);
                 }
-            }
-            break;
-
-        case la_count:
-            /* set number of schema items in the result schema:
-             * result column plus partitioning column
-             * (if available -- constant optimizations may
-             *  have removed it).
-             */
-            new_ocols (n, n->sem.aggr.part ? 2 : 1);
+                else
+                    ocol_at (n, i).type = aat_int;
 
-            /* insert result column into schema */
-            ocol_at (n, 0).name = n->sem.aggr.res;
-            ocol_at (n, 0).type = aat_int;
+                ocol_at (n, i).name = n->sem.aggr.aggr[i].res;
+            }
+            if (n->sem.aggr.part) {
+                unsigned int i    = n->sem.aggr.count;
+                PFalg_col_t  part = n->sem.aggr.part;
+                if (!PFprop_ocol (L(n), part))
+                    PFoops (OOPS_FATAL,
+                            "column `%s' referenced in aggregate not found",
+                            PFcol_str (part));
 
-            /* copy the partitioning column */
-            if (n->sem.aggr.part)
-                for (unsigned int i = 0; i < ocols_count (L(n)); i++)
-                    if (ocol_at (L(n), i).name == n->sem.aggr.part) {
-                        ocol_at (n, 1) = ocol_at (L(n), i);
-                        break;
-                    }
+                ocol_at (n, i).type = PFprop_type_of (L(n), part);
+                ocol_at (n, i).name = part;
+            }
             break;
 
         case la_rownum:
@@ -803,18 +793,6 @@
             ocols_count (n)++;
             break;
 
-        case la_seqty1:
-        case la_all:
-            new_ocols (n, n->sem.aggr.part ? 2 : 1);
-
-            ocol_at (n, 0).name = n->sem.aggr.res;
-            ocol_at (n, 0).type = aat_bln;
-            if (n->sem.aggr.part) {
-                ocol_at (n, 1).name = n->sem.aggr.part;
-                ocol_at (n, 1).type = PFprop_type_of (L(n), n->sem.aggr.part);
-            }
-            break;
-
         case la_step:
         case la_guide_step:
 #ifndef NDEBUG

U prop_const.c
Index: prop_const.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_const.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- prop_const.c        7 May 2009 14:25:28 -0000       1.52
+++ prop_const.c        12 Jun 2009 13:06:13 -0000      1.53
@@ -538,20 +538,25 @@
                     PFprop_const_val (L(n)->prop, n->sem.binary.col1));
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-            /* if column 'col' is constant the result 'res' will be as well */
-            if (PFprop_const (L(n)->prop, n->sem.aggr.col))
-                PFprop_mark_const (
-                        n->prop,
-                        n->sem.aggr.res,
-                        PFprop_const_val (L(n)->prop, n->sem.aggr.col));
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                if (PFprop_const (L(n)->prop, n->sem.aggr.aggr[i].col))
+                    switch (n->sem.aggr.aggr[i].kind) {
+                        case alg_aggr_dist:
+                        case alg_aggr_min:
+                        case alg_aggr_max:
+                        case alg_aggr_avg:
+                        case alg_aggr_all:
+                            PFprop_mark_const (
+                                    n->prop,
+                                    n->sem.aggr.aggr[i].res,
+                                    PFprop_const_val (L(n)->prop,
+                                                      
n->sem.aggr.aggr[i].col));
+                            break;
+
+                        default:
+                            break;
+                    }
             if (n->sem.aggr.part &&
                 PFprop_const (L(n)->prop, n->sem.aggr.part))
                 PFprop_mark_const (

U prop_reqval.c
Index: prop_reqval.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_reqval.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- prop_reqval.c       7 May 2009 14:26:20 -0000       1.56
+++ prop_reqval.c       12 Jun 2009 13:06:14 -0000      1.57
@@ -510,14 +510,7 @@
     if (MAP_LIST(n) &&
         (MULTIPLE_INPUT_EDGES(n) ||
          n->kind == la_pos_select ||
-         n->kind == la_avg ||
-         n->kind == la_max ||
-         n->kind == la_min ||
-         n->kind == la_sum ||
-         n->kind == la_prod ||
-         n->kind == la_count ||
-         n->kind == la_seqty1 ||
-         n->kind == la_all ||
+         n->kind == la_aggr ||
          n->kind == la_rownum ||
          n->kind == la_rowrank ||
          n->kind == la_twig ||
@@ -855,16 +848,9 @@
                 adjust_value (n->sem.unary.col);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
         {
-            PFarray_t *lmap = PFarray (sizeof (req_val_t), 2);
+            PFarray_t *lmap = PFarray (sizeof (req_val_t), n->schema.count);
             if (n->sem.aggr.part) {
                 /* keep properties */
                 req_val_t *map  = find_map (MAP_LIST(n), n->sem.aggr.part);
@@ -872,10 +858,11 @@
                 /* we only have to provide the same groups */
                 adjust_part_ (lmap, n->sem.aggr.part);
             }
-            if (n->sem.aggr.col)
-                /* to make up for the schema change
-                   we add the input columns by hand */
-                adjust_value_ (lmap, n->sem.aggr.col);
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                if (n->sem.aggr.aggr[i].col)
+                    /* to make up for the schema change
+                       we add the input columns by hand */
+                    adjust_value_ (lmap, n->sem.aggr.aggr[i].col);
 
             prop_infer_reqvals (L(n), lmap);
         }   return; /* only infer once */

U prop_set.c
Index: prop_set.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_set.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- prop_set.c  7 May 2009 14:26:25 -0000       1.31
+++ prop_set.c  12 Jun 2009 13:06:14 -0000      1.32
@@ -99,10 +99,6 @@
             break;
 
         case la_pos_select:
-        case la_avg:
-        case la_sum:
-        case la_prod:
-        case la_count:
         case la_rownum:
         case la_rowid:
         case la_twig:
@@ -155,13 +151,29 @@
             break;
 
         case la_distinct:
-        case la_max:
-        case la_min:
-        case la_seqty1:
-        case la_all:
             l_set = true;
             break;
 
+        case la_aggr:
+            l_set = true;
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                switch (n->sem.aggr.aggr[i].kind) {
+                    case alg_aggr_dist:
+                    case alg_aggr_min:
+                    case alg_aggr_max:
+                    case alg_aggr_all:
+                        break;
+
+                    case alg_aggr_count:
+                    case alg_aggr_avg:
+                    case alg_aggr_sum:
+                    case alg_aggr_seqty1:
+                    case alg_aggr_prod:
+                        l_set = false;
+                        break;
+                }
+            break;
+
         case la_step:
         case la_guide_step:
             l_set = false;
@@ -402,31 +414,48 @@
             break;
 
         case la_distinct:
-        case la_max:
-        case la_min:
-        case la_seqty1:
-        case la_all:
             /* allow duplicates for the argument */
             l_col = col_NULL;
             l_set = true;
             break;
 
-        case la_avg:
-        case la_sum:
-        case la_prod:
-        case la_count:
-            /* Switch the set property from TRUE to MAYBE (TRUE+col)
-               if there is a partition column col and keep the MAYBE
-               information if it stores the same column name. */
-            if (n->prop->set && n->sem.aggr.part) {
-                if ((n->prop->set_col && n->prop->set_col == n->sem.aggr.part) 
||
-                    !n->prop->set_col) {
-                    l_col = n->sem.aggr.part;
-                    l_set = true;
+        case la_aggr:
+            l_col = col_NULL;
+            l_set = true;
+
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++) {
+                switch (n->sem.aggr.aggr[i].kind) {
+                    case alg_aggr_dist:
+                    case alg_aggr_min:
+                    case alg_aggr_max:
+                    case alg_aggr_all:
+                        break;
+
+                    case alg_aggr_count:
+                    case alg_aggr_avg:
+                    case alg_aggr_sum:
+                    case alg_aggr_seqty1:
+                    case alg_aggr_prod:
+                        /* Switch the set property from TRUE to MAYBE 
(TRUE+col)
+                           if there is a partition column col and keep the 
MAYBE
+                           information if it stores the same column name. */
+                        if (n->prop->set &&
+                            n->sem.aggr.part &&
+                            ((n->prop->set_col &&
+                              n->prop->set_col == n->sem.aggr.part) ||
+                             !n->prop->set_col)) {
+                            l_col = n->sem.aggr.part;
+                        }
+                        else {
+                            l_set = false;
+                        }
+                        break;
+                }
+                if (!l_set) {
+                    l_col = col_NULL;
                     break;
                 }
             }
-            l_set = false;
             break;
 
         case la_rowid:

U prop_icol.c
Index: prop_icol.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_icol.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- prop_icol.c 7 May 2009 14:25:45 -0000       1.48
+++ prop_icol.c 12 Jun 2009 13:06:13 -0000      1.49
@@ -449,37 +449,14 @@
             union_ (n->prop->l_icols, n->sem.unary.col);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_seqty1:
-        case la_all:
-            copy (n->prop->l_icols, n->prop->icols);
-
-            /* do not infer input columns if operator is not required */
-            if (!in (n->prop->icols, n->sem.aggr.res))
-                break;
-
-            diff (n->prop->l_icols, n->sem.aggr.res);
-            union_ (n->prop->l_icols, n->sem.aggr.col);
-            /* only infer part if available */
-            if (n->sem.aggr.part != col_NULL)
-                union_ (n->prop->l_icols, n->sem.aggr.part);
-            break;
-
-        case la_count:
-            copy (n->prop->l_icols, n->prop->icols);
-
-            /* do not infer input columns if operator is not required */
-            if (!in (n->prop->icols, n->sem.aggr.res))
-                break;
-
-            diff (n->prop->l_icols, n->sem.aggr.res);
-            /* only infer part if available */
-            if (n->sem.aggr.part != col_NULL)
+        case la_aggr:
+            if (n->sem.aggr.part)
                 union_ (n->prop->l_icols, n->sem.aggr.part);
+            /* only infer the columns that are necessary for the output */
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                if (n->sem.aggr.aggr[i].kind != alg_aggr_count &&
+                    in (n->prop->icols, n->sem.aggr.aggr[i].res))
+                    union_ (n->prop->l_icols, n->sem.aggr.aggr[i].col);
             break;
 
         case la_rownum:

U prop_rec_delta.c
Index: prop_rec_delta.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_rec_delta.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- prop_rec_delta.c    7 May 2009 14:26:12 -0000       1.33
+++ prop_rec_delta.c    12 Jun 2009 13:06:14 -0000      1.34
@@ -226,14 +226,7 @@
             }
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
             /* check for a reference to iter */
             if (n->sem.aggr.part &&
                 ITER(L(n)) & n->sem.aggr.part)

U prop_level.c
Index: prop_level.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_level.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- prop_level.c        7 May 2009 14:25:54 -0000       1.23
+++ prop_level.c        12 Jun 2009 13:06:14 -0000      1.24
@@ -151,14 +151,6 @@
         case la_lit_tbl:
         case la_empty_tbl:
         case la_ref_tbl:
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
         case la_fcns:
         case la_docnode:
         case la_element:
@@ -256,6 +248,17 @@
                     }
             break;
 
+        case la_aggr:
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                if (n->sem.aggr.aggr[i].kind == alg_aggr_dist &&
+                    LEVEL_KNOWN (PFprop_level (L(n)->prop,
+                                               n->sem.aggr.aggr[i].col)))
+                    mark_level (n->prop,
+                                n->sem.aggr.aggr[i].res,
+                                PFprop_level (L(n)->prop,
+                                              n->sem.aggr.aggr[i].col));
+            break;
+
         case la_step_join:
         case la_guide_step_join:
             copy_level_info (n, R(n));

U prop_composite_key.c
Index: prop_composite_key.c
===================================================================
RCS file: 
/cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_composite_key.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- prop_composite_key.c        7 May 2009 14:25:24 -0000       1.32
+++ prop_composite_key.c        12 Jun 2009 13:06:13 -0000      1.33
@@ -626,21 +626,15 @@
             }
         }   break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
             /* either the partition is key or if not
                present the aggregated result as it
                contains only one tuple */
             if (n->sem.aggr.part)
                 union_ (CKEYS, collist (n->sem.aggr.part));
             else
-                union_ (CKEYS, collist (n->sem.aggr.res));
+                for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                    union_ (CKEYS, collist (n->sem.aggr.aggr[i].res));
             break;
 
         case la_rownum:

U prop_fd.c
Index: prop_fd.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_fd.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- prop_fd.c   14 May 2009 19:19:52 -0000      1.7
+++ prop_fd.c   12 Jun 2009 13:06:13 -0000      1.8
@@ -54,6 +54,8 @@
 {
     if (!fds) return false;
 
+    if (col1 == col2) return true;
+
     for (unsigned int i = 0; i < PFarray_last (fds); i++)
         if (col1 == ((fd_t *) PFarray_at (fds, i))->col1 &&
             col2 == ((fd_t *) PFarray_at (fds, i))->col2)
@@ -136,15 +138,7 @@
         case la_empty_tbl:
         case la_ref_tbl:
         case la_disjunion:
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
         case la_rownum:
-        case la_seqty1:
-        case la_all:
         case la_step:
         case la_guide_step:
         case la_twig:
@@ -259,6 +253,12 @@
             bulk_add_fds (fds, L(n));
             break;
 
+        case la_aggr:
+            if (n->sem.aggr.part)
+                for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                    add_fd (fds, n->sem.aggr.part, n->sem.aggr.aggr[i].col);
+            break;
+
         case la_num_eq:
         case la_num_gt:
         case la_bool_and:

U prop_trace_names.c
Index: prop_trace_names.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_trace_names.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- prop_trace_names.c  7 May 2009 14:26:29 -0000       1.33
+++ prop_trace_names.c  12 Jun 2009 13:06:14 -0000      1.34
@@ -281,15 +281,9 @@
             diff_np (np_list, n->sem.unary.res);
             break;
 
-        case la_count:
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_seqty1:
-        case la_all:
-            diff_np (np_list, n->sem.aggr.res);
+        case la_aggr:
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                diff_np (np_list, n->sem.aggr.aggr[i].res);
             break;
 
         case la_rownum:

U prop_key.c
Index: prop_key.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_key.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- prop_key.c  14 May 2009 19:57:36 -0000      1.64
+++ prop_key.c  12 Jun 2009 13:06:13 -0000      1.65
@@ -553,21 +553,15 @@
                 union_ (n->prop->keys, n->sem.binary.res);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
             /* either the partition is key or if not
                present the aggregated result as it
                contains only one tuple */
             if (n->sem.aggr.part)
                 union_ (n->prop->keys, n->sem.aggr.part);
             else
-                union_ (n->prop->keys, n->sem.aggr.res);
+                for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                    union_ (n->prop->keys, n->sem.aggr.aggr[i].res);
             break;
 
         case la_rownum:

U prop_req_node.c
Index: prop_req_node.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_req_node.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- prop_req_node.c     7 May 2009 14:26:16 -0000       1.18
+++ prop_req_node.c     12 Jun 2009 13:06:14 -0000      1.19
@@ -469,17 +469,30 @@
             assert ((type_of (n, n->sem.unary.col) & aat_node) == 0);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
-            /* the output cannot be of type node */
-            if (!n->sem.aggr.part) {
-                prop_infer_req_node_vals (L(n), NULL);
+        case la_aggr:
+            /* dist aggregates or the partition column can be of type node */
+            if (MAP_LIST(n) != NULL && PFarray_last (MAP_LIST(n)) > 0) {
+                PFarray_t *new_map = PFarray (sizeof (req_node_t),
+                                              PFarray_last (MAP_LIST(n)));
+
+                for (unsigned int i = 0; i < n->sem.aggr.count; i++) {
+                    map = find_map (MAP_LIST(n), n->sem.aggr.aggr[i].res);
+                    if (map) {
+                        req_node_t map_item = *map;
+                        map_item.col = n->sem.aggr.aggr[i].col;
+                        ADD(new_map, map_item);
+                    }
+                }
+                if (n->sem.aggr.part) {
+                    map = find_map (MAP_LIST(n), n->sem.aggr.part);
+                    if (map) {
+                        req_node_t map_item = *map;
+                        map_item.col = n->sem.aggr.part;
+                        ADD(new_map, map_item);
+                    }
+                }
+
+                prop_infer_req_node_vals (L(n), new_map);
                 return; /* only infer once */
             }
             break;

U prop_guide.c
Index: prop_guide.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_guide.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- prop_guide.c        7 May 2009 14:25:40 -0000       1.34
+++ prop_guide.c        12 Jun 2009 13:06:13 -0000      1.35
@@ -415,6 +415,59 @@
 }
 
 /**
+ * @brief Copy the guide mappings with respect
+ *        to the aggregate operator semantics.
+ */
+static void
+copy_aggregate (PFla_op_t *n)
+{
+    PFguide_mapping_t *mapping      = NULL;
+    PFarray_t         *map_list     = MAPPING_LIST(L(n)),
+                      *new_map_list = PFarray (sizeof (PFguide_mapping_t *),
+                                               n->sem.proj.count);
+    PFalg_col_t        new,
+                       old;
+
+    if (map_list == NULL) {
+        MAPPING_LIST(n) = NULL;
+        return;
+    }
+
+    /* iterate over all columns */
+    for (unsigned int i = 0; i < n->sem.aggr.count; i++) {
+        /* only collect the guides for distinct aggregates */
+        if (n->sem.aggr.aggr[i].kind != alg_aggr_dist)
+            continue;
+
+        /* get new and old column name */
+        new = n->sem.aggr.aggr[i].res;
+        old = n->sem.aggr.aggr[i].col;
+
+        /* get guide mapping from list */
+        mapping = get_guide_mapping (map_list, old);
+
+        if (mapping == NULL)
+            continue;
+
+        /* create a copy */
+        mapping = copy_guide_mapping (mapping);
+
+        /* set new column name */
+        mapping->column = new;
+
+        /* assign guide mapping to the list */
+        GUIDE_MAP_ADD(new_map_list) = mapping;
+    }
+
+    /* only keep the guide mapping list
+       if we have a mapping */
+    if (PFarray_last (new_map_list))
+        MAPPING_LIST(n) = new_map_list;
+    else
+        MAPPING_LIST(n) = NULL;
+}
+
+/**
  * @brief Apply kind and name test for path steps.
  *
  * @param return_attr ensures that attribute nodes are allowed/discarded,
@@ -773,14 +826,6 @@
         case la_lit_tbl:
         case la_empty_tbl:
         case la_ref_tbl:
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
         case la_twig:
         case la_fcns:
         case la_element:
@@ -845,6 +890,10 @@
             copy_intersect (n);
             break;
 
+        case la_aggr:
+            copy_aggregate (n);
+            break;
+
         /* step */
         case la_step:
             copy_step (n);

U prop_ori_names.c
Index: prop_ori_names.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_ori_names.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- prop_ori_names.c    7 May 2009 14:26:07 -0000       1.41
+++ prop_ori_names.c    12 Jun 2009 13:06:14 -0000      1.42
@@ -362,30 +362,17 @@
             diff_np (n->prop->l_name_pairs, np_list, n->sem.unary.res);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
-            /* operators introducing a completely new set of names
-               for its operands (aggregates, steps, doc_tbl, element,
-               merge_adjacent, and string_join) store these columns
-               both in the name pair list of the child and in the current
-               name pair list to support correct renaming if the proposed
-               column name was modified. */
-            unq = n->sem.aggr.res;
-            ori = find_ori_name (np_list, unq);
-            /* use the result name also as column name
-               of the input value column */
-            if (n->kind != la_count) {
-                unq = n->sem.aggr.col;
-                add_name_pair (np_list, ori, unq);
-                add_name_pair (n->prop->l_name_pairs, ori, unq);
-            }
-
+        case la_aggr:
+            /* Infer only columns that are used in the aggregates.
+               Renamings do not have to be mapped. Conflicting names
+               are patched by the function patch_ori_names(). */
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                if (n->sem.aggr.aggr[i].kind != alg_aggr_count) {
+                    ori = find_ori_name (np_list, n->sem.aggr.aggr[i].res);
+                    add_name_pair (n->prop->l_name_pairs,
+                                   ori,
+                                   n->sem.aggr.aggr[i].col);
+                }
             if (n->sem.aggr.part) {
                 unq = n->sem.aggr.part;
                 ori = find_ori_name (np_list, unq);

U prop_card.c
Index: prop_card.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_card.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- prop_card.c 7 May 2009 14:25:19 -0000       1.42
+++ prop_card.c 12 Jun 2009 13:06:12 -0000      1.43
@@ -166,14 +166,7 @@
             n->prop->card = 0;
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
             /* if part is not present the
                aggregation yields only one tuple */
             n->prop->card = n->sem.aggr.part ? 0 : 1;

U prop_lineage.c
Index: prop_lineage.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_lineage.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- prop_lineage.c      7 May 2009 14:25:58 -0000       1.7
+++ prop_lineage.c      12 Jun 2009 13:06:14 -0000      1.8
@@ -235,17 +235,17 @@
             add_new_lineage (n->sem.unary.res);
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
+        case la_aggr:
             if (n->sem.aggr.part)
                 map_lineage (n->sem.aggr.part, L(n), n->sem.aggr.part);
-            add_new_lineage (n->sem.aggr.res);
+
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                if (n->sem.aggr.aggr[i].kind == alg_aggr_dist)
+                    map_lineage (n->sem.aggr.aggr[i].res,
+                                 L(n),
+                                 n->sem.aggr.aggr[i].col);
+                else
+                    add_new_lineage (n->sem.aggr.aggr[i].res);
             break;
 
         case la_rownum:

U prop_dom.c
Index: prop_dom.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/prop/prop_dom.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- prop_dom.c  7 May 2009 20:00:14 -0000       1.67
+++ prop_dom.c  12 Jun 2009 13:06:13 -0000      1.68
@@ -936,21 +936,29 @@
             add_new_dom (n->sem.unary.res);
             break;
 
-        case la_avg:
-        case la_sum:
-        case la_prod:
-        case la_count:
-        case la_seqty1:
-        case la_all:
-            add_new_dom (n->sem.aggr.res);
-            if (n->sem.aggr.part)
-                add_dom (n->sem.aggr.part,
-                         PFprop_dom (L(n)->prop, n->sem.aggr.part));
-            break;
-
-        case la_max:
-        case la_min:
-            filter_dom_ (L(n), n->sem.aggr.col, n->sem.aggr.res);
+        case la_aggr:
+            for (unsigned int i = 0; i < n->sem.aggr.count; i++)
+                switch (n->sem.aggr.aggr[i].kind) {
+                    case alg_aggr_dist:
+                        add_dom (n->sem.aggr.aggr[i].res,
+                                 PFprop_dom (L(n)->prop,
+                                             n->sem.aggr.aggr[i].col));
+                        break;
+                    case alg_aggr_min:
+                    case alg_aggr_max:
+                    case alg_aggr_all:
+                        filter_dom_ (L(n),
+                                     n->sem.aggr.aggr[i].col,
+                                     n->sem.aggr.aggr[i].res);
+                        break;
+                    case alg_aggr_count:
+                    case alg_aggr_avg:
+                    case alg_aggr_sum:
+                    case alg_aggr_seqty1:
+                    case alg_aggr_prod:
+                        add_new_dom (n->sem.aggr.aggr[i].res);
+                        break;
+                }
             if (n->sem.aggr.part)
                 add_dom (n->sem.aggr.part,
                          PFprop_dom (L(n)->prop, n->sem.aggr.part));


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to