Yingyi Bu has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/702

Change subject: ASTERIXDB-865: fix for if-else expression.
......................................................................

ASTERIXDB-865: fix for if-else expression.

Change-Id: I17978d2f694e2a5082903002b8388c5bd42811a5
---
M 
algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java
M 
algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
2 files changed, 25 insertions(+), 5 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/hyracks refs/changes/02/702/1

diff --git 
a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java
 
b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java
index dfc12bf..1c5a933 100644
--- 
a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java
+++ 
b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java
@@ -34,6 +34,7 @@
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
 import 
org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 import 
org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import 
org.apache.hyracks.algebricks.core.algebra.expressions.StatefulFunctionCallExpression;
 import 
org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
@@ -265,4 +266,15 @@
         CardinalityInferenceVisitor visitor = new 
CardinalityInferenceVisitor();
         return operator.accept(visitor, null) == 1L;
     }
+
+    public static boolean canFieldAccessBePushedThroughSelect(ILogicalOperator 
op) {
+        if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
+            return true;
+        }
+        SelectOperator selectOp = (SelectOperator) op;
+        if (selectOp.getCondition().getValue() instanceof 
StatefulFunctionCallExpression) {
+            return false;
+        }
+        return true;
+    }
 }
diff --git 
a/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
 
b/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
index f2645f5..e7cf912 100644
--- 
a/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
+++ 
b/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
@@ -29,6 +29,7 @@
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
 import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
@@ -41,7 +42,6 @@
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import org.apache.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl;
 import 
org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionReferenceTransform;
 import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 
@@ -168,10 +168,18 @@
 
         // Descend into subplan
         if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
-            ALogicalPlanImpl subPlan = (ALogicalPlanImpl) ((SubplanOperator) 
op).getNestedPlans().get(0);
-            Mutable<ILogicalOperator> subPlanRootOpRef = 
subPlan.getRoots().get(0);
-            if (inlineVariables(subPlanRootOpRef, context)) {
-                modified = true;
+            SubplanOperator subplanOp = (SubplanOperator) op;
+            for (ILogicalPlan nestedPlan : subplanOp.getNestedPlans()) {
+                for (Mutable<ILogicalOperator> root : nestedPlan.getRoots()) {
+                    if (inlineVariables(root, context)) {
+                        modified = true;
+                    }
+                    // Variables produced by a nested subplan cannot be inlined
+                    // in operators above the subplan.
+                    Set<LogicalVariable> producedVars = new 
HashSet<LogicalVariable>();
+                    VariableUtilities.getProducedVariables(root.getValue(), 
producedVars);
+                    varAssignRhs.keySet().removeAll(producedVars);
+                }
             }
         }
 

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/702
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I17978d2f694e2a5082903002b8388c5bd42811a5
Gerrit-PatchSet: 1
Gerrit-Project: hyracks
Gerrit-Branch: master
Gerrit-Owner: Yingyi Bu <[email protected]>

Reply via email to