Update of /cvsroot/monetdb/pathfinder/compiler/xmlimport
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5022/compiler/xmlimport

Modified Files:
      Tag: M5XQ
        xml2lalg.c 
Log Message:
propagated changes of Friday Jun 12 2009 - Monday Jun 15 2009
from the development trunk to the M5XQ branch

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/06/12 - tsheyar: compiler/xmlimport/xml2lalg.c,1.37
-- 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 xml2lalg.c
Index: xml2lalg.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/xmlimport/xml2lalg.c,v
retrieving revision 1.32.2.3
retrieving revision 1.32.2.4
diff -u -d -r1.32.2.3 -r1.32.2.4
--- xml2lalg.c  28 May 2009 15:12:00 -0000      1.32.2.3
+++ xml2lalg.c  15 Jun 2009 12:47:58 -0000      1.32.2.4
@@ -280,6 +280,13 @@
 #define PFLA_PREDICATES(xpath) \
                     getPFLA_Predicates(ctx, nodePtr, xpath)
 
+/**              
+ * Macro return-type:  PFalg_sel_t* 
+ * XPath return-type:  element(comparison)+
+ */
+#define PFLA_AGGREGATES(xpath) \
+                    getPFLA_Aggregates(ctx, nodePtr, xpath)
+
 
 /**              
  * Macro return-type:  int 
@@ -442,6 +449,12 @@
     xmlNodePtr nodePtr, 
     const char* xpathExpression);
 
+PFalg_aggr_t* 
+getPFLA_Aggregates(
+    XML2LALGContext* ctx, 
+    xmlNodePtr nodePtr, 
+    const char* xpathExpression);
+
 PFalg_proj_t* 
 getPFLA_Projection(
     XML2LALGContext* ctx, 
@@ -693,6 +706,65 @@
 
 
 
+/**
+ * Legacy XML code import for old aggregate representations.
+ */
+static PFla_op_t *
+aggregate_legacy_detect (XML2LALGContext* ctx, xmlNodePtr nodePtr)
+{
+    PFalg_aggr_t      aggr;
+    PFalg_aggr_kind_t kind = alg_aggr_count;
+    char             *kind_str;
+   
+    /* fetch the node kind string from xml */
+    kind_str = PFxml2la_xpath_getAttributeValueFromAttributeNode (
+                   PFxml2la_xpath_getNthNode(XPATH("/@kind"), 0));
+
+    /* standard case */
+    if (!strcmp ("aggr", kind_str))
+        return NULL;
+    /* legacy code */
+    else if (!strcmp ("count", kind_str))
+        kind = alg_aggr_count;
+    else if (!strcmp ("sum", kind_str))
+        kind = alg_aggr_sum;
+    else if (!strcmp ("min", kind_str))
+        kind = alg_aggr_min;
+    else if (!strcmp ("max", kind_str))
+        kind = alg_aggr_max;
+    else if (!strcmp ("avg", kind_str))
+        kind = alg_aggr_avg;
+    else if (!strcmp ("prod", kind_str))
+        kind = alg_aggr_prod;
+    else if (!strcmp ("seqty1", kind_str))
+        kind = alg_aggr_seqty1;
+    else if (!strcmp ("all", kind_str))
+        kind = alg_aggr_all;
+    else
+        PFoops (OOPS_FATAL,
+                "could not recognize aggregate kind (%s)",
+                kind_str);
+
+    /*
+    <content>
+       <column name="COLNAME" new="true"/>
+       <column name="COLNAME" new="false" function="item"/>
+      (<column name="COLNAME" function="partition" new="false"/>)?
+    </content>
+    */
+
+    aggr = PFalg_aggr (kind,
+                       PFLA_ATT("/content/colu...@new='true']/@name"), 
+                       PFLA_ATT_O("/content/colu...@function='item']/@name",
+                                  col_NULL));
+
+    return PFla_aggr (CHILDNODE(0),
+                      
PFLA_ATT_O("/content/colu...@function='partition']/@name",
+                                 col_NULL),
+                      1,
+                      &aggr);
+}
+
 /* 
   =============================================================================
   =============================================================================
@@ -1268,54 +1340,33 @@
 
/******************************************************************************/
 
/******************************************************************************/
 
-    case la_avg                  : 
-    case la_max                  :
-    case la_min                  :
-    case la_sum                  :
-    case la_prod                 :
+    case la_aggr                 : 
         {
-            /*
-           <content>
-              <column name="COLNAME" new="true"/>
-              <column name="COLNAME" new="false" function="item"/>
-             (<column name="COLNAME" function="partition" new="false"/>)?
-           </content>
-           */
-
-            newAlgNode = PFla_aggr 
-             (
-             algOpKindID, 
-             CHILDNODE(0), 
-             PFLA_ATT("/content/colu...@new='true']/@name"), 
-             PFLA_ATT("/content/colu...@function='item']/@name"), 
-             PFLA_ATT_O("/content/colu...@function='partition']/@name",
-                        col_NULL)
-             );
-        }  
-        break;                       
-
-/******************************************************************************/
-/******************************************************************************/
-
-    case la_count                : 
+            /* check for legacy aggregate representations */
+            if ((newAlgNode = aggregate_legacy_detect (ctx, nodePtr)))
+                break;
 
-        {
             /*
-            <content>
-               <column name="COLNAME" new="true"/>
-              (<column name="COLNAME" function="partition" new="false"/>)?
-            </content>
-            */
-
-            newAlgNode = PFla_count
+              <content>
+               (<column name="COLNAME" function="partition" new="false"/>)?
+               (<aggregate kind="KIND">
+                  <column name="COLNAME" new="true"/>
+                  <column name="COLNAME" new="false"/>
+                </aggregate>)+
+             </content>             
+            */       
+            
+            newAlgNode = PFla_aggr
              (
-             CHILDNODE(0), 
-             PFLA_ATT("/content/colu...@new='true']/@name"), 
+             CHILDNODE(0),
              PFLA_ATT_O("/content/colu...@function='partition']/@name",
-                        col_NULL)
+                        col_NULL),
+             NODECOUNT("/content/aggregate"), 
+             PFLA_AGGREGATES("/content/aggregate")
              );
+
         }  
-        break;
+        break;                       
 
 
/******************************************************************************/
 
/******************************************************************************/
@@ -1483,57 +1534,6 @@
 
/******************************************************************************/
 
/******************************************************************************/
 
-    case la_seqty1               : 
-
-        {
-
-            /*
-            <content>
-               <column name="COLNAME" new="true"/>
-               <column name="COLNAME" new="false" function="item"/>
-              (<column name="COLNAME" function="partition" new="false"/>)?
-            </content>
-            */
-
-            newAlgNode = PFla_seqty1 
-             (
-             CHILDNODE(0), 
-             PFLA_ATT("/content/colu...@new='true']/@name"), 
-             PFLA_ATT("/content/colu...@function='item']/@name"), 
-             PFLA_ATT_O("/content/colu...@function='partition']/@name",
-                        col_NULL)
-             );
-        }  
-        break;
-
-/******************************************************************************/
-/******************************************************************************/
-
-    case la_all                  : 
-
-        {
-            /*
-            <content>
-               <column name="COLNAME" new="true"/>
-               <column name="COLNAME" new="false" function="item"/>
-              (<column name="COLNAME" function="partition" new="false"/>)?
-            </content>
-            */
-
-            newAlgNode = PFla_all 
-             (
-             CHILDNODE(0), 
-             PFLA_ATT("/content/colu...@new='true']/@name"), 
-             PFLA_ATT("/content/colu...@function='item']/@name"), 
-             PFLA_ATT_O("/content/colu...@function='partition']/@name",
-                        col_NULL)
-             );
-        }  
-        break;
-
-/******************************************************************************/
-/******************************************************************************/
-
     case la_step                 : 
 
         {
@@ -2864,6 +2864,65 @@
 
 
 
+PFalg_aggr_t *
+getPFLA_Aggregates(
+    XML2LALGContext* ctx, 
+    xmlNodePtr nodePtr, 
+    const char* xpathExpression)
+{
+    /*
+     <content>
+      (<aggregate kind="KIND">
+         <column name="COLNAME" new="true"/>
+         <column name="COLNAME" new="false"/>
+       </aggregate>)*
+    </content>             
+     */
+
+
+
+    /* fetch the aggregates (and indirectly the predicate count) from xml */
+    xmlXPathObjectPtr aggregates_xml =  XPATH(xpathExpression);
+
+    /* how many aggregates do we have? */
+    int aggregateCount =  PFxml2la_xpath_getNodeCount(aggregates_xml);
+
+    /*
+    ******************************************************************
+    ******************************************************************
+    * construct the Predicate List
+    ******************************************************************
+    ******************************************************************
+    */
+
+    /* allocate the aggregate list*/
+    PFalg_aggr_t* aggregates =  
+        (PFalg_aggr_t*) PFmalloc (aggregateCount * sizeof (PFalg_aggr_t));
+    /* fetch and relate the aggregates from xml to 
+    the corresponding pf aggregates */
+    for (int p = 0; p < aggregateCount; p++)
+    {
+        xmlNodePtr aggregate_xml = 
+            PFxml2la_xpath_getNthNode(aggregates_xml, p);
+
+
+        aggregates[p].kind = PFxml2la_conv_2PFLA_aggregateType(
+            PFxml2la_xpath_getAttributeValueFromElementNode(
+                aggregate_xml, "kind"));
+
+        /* PFLA_ATT & PFLA_ATT_O macros use variable nodePtr
+           as starting point for XPath expression */
+        nodePtr = aggregate_xml;
+        aggregates[p].res = PFLA_ATT ("/colu...@new='true']/@name");
+        aggregates[p].col = PFLA_ATT_O ("/colu...@new='false']/@name", 
col_NULL);
+    }
+
+    if(aggregates_xml)
+        xmlXPathFreeObject(aggregates_xml);
+
+    return aggregates;
+
+}
 
 
 /* todo: check order... */


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