You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2013/06/01 01:55:26 UTC

svn commit: r1488435 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateUnnestAggregateSubplanRule.java

Author: prestonc
Date: Fri May 31 23:55:25 2013
New Revision: 1488435

URL: http://svn.apache.org/r1488435
Log:
The rule now moves the sub expressions as part of the elimination. Before the expressions were being ignored since there were none. The change allows for more expression to exist and not erase them.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateUnnestAggregateSubplanRule.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateUnnestAggregateSubplanRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateUnnestAggregateSubplanRule.java?rev=1488435&r1=1488434&r2=1488435&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateUnnestAggregateSubplanRule.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateUnnestAggregateSubplanRule.java Fri May 31 23:55:25 2013
@@ -80,8 +80,18 @@ public class EliminateUnnestAggregateSub
             return false;
         }
 
+        // Use the left over functions from iterator and sequence.
+        Mutable<ILogicalExpression> assignExpression = functionCall2.getArguments().get(0);
+        ILogicalExpression lastUnnestExpression = findLastFunctionExpression(logicalExpression);
+        if (lastUnnestExpression != null) {
+            // Additional functions are included in the iterate function that need to be included.
+            AbstractFunctionCallExpression lastUnnestFunction = (AbstractFunctionCallExpression) lastUnnestExpression;
+            lastUnnestFunction.getArguments().set(0, functionCall2.getArguments().get(0));
+            assignExpression = functionCall.getArguments().get(0);
+        }
+
         // Replace search string with assign.
-        AssignOperator aOp = new AssignOperator(unnest.getVariable(), functionCall2.getArguments().get(0));
+        AssignOperator aOp = new AssignOperator(unnest.getVariable(), assignExpression);
         for (Mutable<ILogicalOperator> input : subplanOp.getInputs()) {
             aOp.getInputs().add(input);
         }
@@ -94,6 +104,18 @@ public class EliminateUnnestAggregateSub
         return true;
     }
 
+    private ILogicalExpression findLastFunctionExpression(ILogicalExpression expression) {
+        if (expression.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+            AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) expression;
+            ILogicalExpression nextExpression = functionCall.getArguments().get(0).getValue();
+            if (nextExpression.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+                return expression;
+            }
+            return findLastFunctionExpression(nextExpression);
+        }
+        return null;
+    }
+
     private AbstractLogicalOperator findLastSubplanOperator(AbstractLogicalOperator op) {
         AbstractLogicalOperator next;
         while (op.getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {