Update of /cvsroot/monetdb/pathfinder/compiler/xmlimport
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv11514/xmlimport
Modified Files:
xml2lalg.c xml2lalg_converters.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 xml2lalg.c
Index: xml2lalg.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/xmlimport/xml2lalg.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- xml2lalg.c 27 May 2009 16:19:10 -0000 1.36
+++ xml2lalg.c 12 Jun 2009 13:06:18 -0000 1.37
@@ -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... */
U xml2lalg_converters.c
Index: xml2lalg_converters.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/xmlimport/xml2lalg_converters.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- xml2lalg_converters.c 9 May 2009 18:13:46 -0000 1.30
+++ xml2lalg_converters.c 12 Jun 2009 13:06:19 -0000 1.31
@@ -83,11 +83,13 @@
mapto (la_bool_or , "or")
mapto (la_bool_not, "not")
mapto (la_to, "op:to")
- mapto (la_avg, "avg")
- mapto (la_max, "max")
- mapto (la_min, "min")
- mapto (la_sum, "sum")
- mapto (la_count, "count")
+ mapto (la_aggr, "aggr")
+ mapto (la_aggr, "avg")
+ mapto (la_aggr, "max")
+ mapto (la_aggr, "min")
+ mapto (la_aggr, "sum")
+ mapto (la_aggr, "count")
+ mapto (la_aggr, "prod")
mapto (la_rownum, "rownum")
mapto (la_rowrank, "rowrank")
mapto (la_rank, "rank")
@@ -95,8 +97,8 @@
mapto (la_type, "type")
mapto (la_type_assert, "type assertion")
mapto (la_cast, "cast")
- mapto (la_seqty1, "seqty1")
- mapto (la_all, "all")
+ mapto (la_aggr, "seqty1")
+ mapto (la_aggr, "all")
mapto (la_step, "XPath step")
mapto (la_step_join, "path step join")
mapto (la_guide_step, "XPath step (with guide information)")
@@ -206,6 +208,8 @@
ori = col_score1;
length = strlen("score");
}
+ else if (!strcmp (s, "(NULL)"))
+ return col_NULL;
else
PFoops (OOPS_FATAL, "don't know what to do with (%s)", s);
@@ -286,6 +290,30 @@
return alg_comp_eq;
}
+PFalg_aggr_kind_t
+PFxml2la_conv_2PFLA_aggregateType (char* s)
+{
+ if (false) return alg_aggr_count; /* discard first case */
+#define mapto_aggr_kind(kind) \
+ else if (strcmp (s, PFalg_aggr_kind_str((kind))) == 0) \
+ return (kind);
+ /* the kind was copied from algebra.c:PFalg_axis_str()
+ (and should stay aligned) */
+ mapto_aggr_kind (alg_aggr_dist)
+ mapto_aggr_kind (alg_aggr_count)
+ mapto_aggr_kind (alg_aggr_min)
+ mapto_aggr_kind (alg_aggr_max)
+ mapto_aggr_kind (alg_aggr_avg)
+ mapto_aggr_kind (alg_aggr_sum)
+ mapto_aggr_kind (alg_aggr_seqty1)
+ mapto_aggr_kind (alg_aggr_all)
+ mapto_aggr_kind (alg_aggr_prod)
+
+ PFoops (OOPS_FATAL, "don't know what to do (%s)", s);
+ /* pacify picky compilers */
+ return alg_aggr_count;
+}
+
PFalg_fun_t
PFxml2la_conv_2PFLA_functionType (char* s)
{
------------------------------------------------------------------------------
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