Repository: asterixdb Updated Branches: refs/heads/master 2da225b70 -> 6b8a42f3d
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.1.ddl.aql ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.1.ddl.aql new file mode 100644 index 0000000..99ad6a1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.1.ddl.aql @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +drop dataverse channels if exists; +create dataverse channels; +use dataverse channels; + +create type userLocation as { + userId: int, + stamp: datetime +} + +create dataset Users(userLocation) +primary key stamp; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.2.update.aql ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.2.update.aql new file mode 100644 index 0000000..6c18409 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.2.update.aql @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use dataverse channels; + +insert into dataset Users( +[{"userId":1,"stamp":current-datetime() - day-time-duration("PT10M")}, +{"userId":2,"stamp":current-datetime() - day-time-duration("PT8M")}, +{"userId":3,"stamp":current-datetime() + day-time-duration("PT10M")}] +); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.3.query.aql ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.3.query.aql new file mode 100644 index 0000000..3885444 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/global-datetime-use-index/global-datetime-use-index.3.query.aql @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use dataverse channels; + +let $time := current-datetime() +for $result in dataset Users +where $result.stamp < $time +order by $result.userId +return $result.userId; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.ddl.aql ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.ddl.aql new file mode 100644 index 0000000..99ad6a1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.ddl.aql @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +drop dataverse channels if exists; +create dataverse channels; +use dataverse channels; + +create type userLocation as { + userId: int, + stamp: datetime +} + +create dataset Users(userLocation) +primary key stamp; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.2.update.aql ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.2.update.aql new file mode 100644 index 0000000..541a203 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.2.update.aql @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use dataverse channels; + +insert into dataset Users( +[{"userId":1,"stamp":current-datetime() - day-time-duration("PT10M")}, +{"userId":2,"stamp":current-datetime() + day-time-duration("PT8M")}, +{"userId":3,"stamp":current-datetime() + day-time-duration("PT10M")}] +); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.3.query.aql ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.3.query.aql new file mode 100644 index 0000000..ab2ac11 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.3.query.aql @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use dataverse channels; + +for $result in dataset Users +let $time := current-datetime() +where $result.stamp > $time +order by $result.userId +return $result.userId; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/global-datetime-use-index/global-datetime-use-index.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/global-datetime-use-index/global-datetime-use-index.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/global-datetime-use-index/global-datetime-use-index.1.adm new file mode 100644 index 0000000..7a754f4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/global-datetime-use-index/global-datetime-use-index.1.adm @@ -0,0 +1,2 @@ +1 +2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.adm new file mode 100644 index 0000000..1234e84 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/nonpure/local-datetime-ignore-index/local-datetime-ignore-index.1.adm @@ -0,0 +1,2 @@ +2 +3 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml index 5664c72..cbf715d 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml @@ -4139,8 +4139,20 @@ </compilation-unit> </test-case> <test-case FilePath="nestrecords"> - <compilation-unit name="query-ASTERIXDB-1025"> - <output-dir compare="Text">query-ASTERIXDB-1025</output-dir> + <compilation-unit name="global-datetime-use-index"> + <output-dir compare="Text">global-datetime-use-index</output-dir> + </compilation-unit> + </test-case> + </test-group> + <test-group name="nonpure"> + <test-case FilePath="nonpure"> + <compilation-unit name="local-datetime-ignore-index"> + <output-dir compare="Text">local-datetime-ignore-index</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="nonpure"> + <compilation-unit name="global-datetime-use-index"> + <output-dir compare="Text">global-datetime-use-index</output-dir> </compilation-unit> </test-case> </test-group> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java index 1d20e08..4ceeb5c 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java @@ -27,7 +27,7 @@ public enum PhysicalOperatorTag { DATASOURCE_SCAN, DISTRIBUTE_RESULT, EMPTY_TUPLE_SOURCE, - EXTENSION_OPERATOR, + DELEGATE_OPERATOR, EXTERNAL_GROUP_BY, EXTERNAL_LOOKUP, HASH_GROUP_BY, http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java index e2643dd..8117921 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/util/OperatorPropertiesUtil.java @@ -37,6 +37,7 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression 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; +import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.CardinalityInferenceVisitor; import org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities; @@ -287,13 +288,37 @@ public class OperatorPropertiesUtil { public static boolean isMovable(ILogicalOperator op) { Object annotation = op.getAnnotations().get(MOVABLE); if (annotation == null) { - // By default, it is movable. + // Can't move nonPures! + if (op.getOperatorTag() == LogicalOperatorTag.ASSIGN) { + AssignOperator assign = (AssignOperator) op; + for (Mutable<ILogicalExpression> expr : assign.getExpressions()) { + if (containsNonpureCall(expr.getValue())) { + return false; + } + } + } return true; } Boolean movable = (Boolean) annotation; return movable; } + private static boolean containsNonpureCall(ILogicalExpression expr) { + if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { + AbstractFunctionCallExpression fExpr = (AbstractFunctionCallExpression) expr; + if (!fExpr.getFunctionInfo().isFunctional()) { + return true; + } + for (Mutable<ILogicalExpression> subExpr : fExpr.getArguments()) { + if (containsNonpureCall(subExpr.getValue())) { + return true; + } + } + + } + return false; + } + /** * Mark an operator to be either movable or not. * http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java index 8f6e9a1..bbb6cbd 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.List; import org.apache.commons.lang3.mutable.Mutable; - import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator; import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext; @@ -31,6 +30,7 @@ import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable; import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities; +import org.apache.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil; import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule; public class ConsolidateAssignsRule implements IAlgebraicRewriteRule { @@ -53,6 +53,11 @@ public class ConsolidateAssignsRule implements IAlgebraicRewriteRule { if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } + + if (!OperatorPropertiesUtil.isMovable(op) || !OperatorPropertiesUtil.isMovable(op2)) { + return false; + } + AssignOperator assign2 = (AssignOperator) op2; HashSet<LogicalVariable> used1 = new HashSet<LogicalVariable>(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/EnforceStructuralPropertiesRule.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/EnforceStructuralPropertiesRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/EnforceStructuralPropertiesRule.java index 0b3a57e..a1730ac 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/EnforceStructuralPropertiesRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/EnforceStructuralPropertiesRule.java @@ -68,8 +68,10 @@ import org.apache.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPre import org.apache.hyracks.algebricks.core.algebra.prettyprint.PlanPrettyPrinter; import org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency; import org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty; +import org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty.PropertyType; import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain; import org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty; +import org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty.PartitioningType; import org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningRequirementsCoordinator; import org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector; import org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty; @@ -81,8 +83,6 @@ import org.apache.hyracks.algebricks.core.algebra.properties.PropertiesUtil; import org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty; import org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector; import org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty; -import org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty.PropertyType; -import org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty.PartitioningType; import org.apache.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil; import org.apache.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil; import org.apache.hyracks.algebricks.core.config.AlgebricksConfig; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ExtractCommonExpressionsRule.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ExtractCommonExpressionsRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ExtractCommonExpressionsRule.java index 11ff4be..60275dd 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ExtractCommonExpressionsRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/ExtractCommonExpressionsRule.java @@ -241,19 +241,22 @@ public class ExtractCommonExpressionsRule implements IAlgebraicRewriteRule { if (exprEqClass != null) { // Replace common subexpression with existing variable. if (exprEqClass.variableIsSet()) { - Set<LogicalVariable> liveVars = new HashSet<LogicalVariable>(); - List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>(); - VariableUtilities.getLiveVariables(op, liveVars); - VariableUtilities.getUsedVariables(op, usedVars); - // Check if the replacing variable is live at this op. - // However, if the op is already using variables that are not live, then a replacement may enable fixing the plan. - // This behavior is necessary to, e.g., properly deal with distinct by. - // Also just replace the expr if we are replacing common exprs from within the same operator. - if (liveVars.contains(exprEqClass.getVariable()) || !liveVars.containsAll(usedVars) - || op == exprEqClass.getFirstOperator()) { - exprRef.setValue(new VariableReferenceExpression(exprEqClass.getVariable())); - // Do not descend into children since this expr has been completely replaced. - return true; + if (expr.isFunctional()) { + Set<LogicalVariable> liveVars = new HashSet<>(); + List<LogicalVariable> usedVars = new ArrayList<>(); + VariableUtilities.getLiveVariables(op, liveVars); + VariableUtilities.getUsedVariables(op, usedVars); + // Check if the replacing variable is live at this op. + // However, if the op is already using variables that are not live, + // then a replacement may enable fixing the plan. + // This behavior is necessary to, e.g., properly deal with distinct by. + // Also just replace the expr if we are replacing common exprs from within the same operator. + if (liveVars.contains(exprEqClass.getVariable()) || !liveVars.containsAll(usedVars) + || op == exprEqClass.getFirstOperator()) { + exprRef.setValue(new VariableReferenceExpression(exprEqClass.getVariable())); + // Do not descend into children since this expr has been completely replaced. + return true; + } } } else { if (expr.isFunctional() && assignCommonExpression(exprEqClass, expr)) { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java index b4ade4c..cd42407 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java @@ -118,25 +118,6 @@ public class InlineVariablesRule implements IAlgebraicRewriteRule { return false; } - /** - * An expression will be constant at runtime if it has: - * 1. A type - * 2. No free variables - * - * @param op - * @param funcExpr - * @param context - * @return whether a function is constant - * @throws AlgebricksException - */ - public static boolean functionIsConstantAtRuntime(AbstractFunctionCallExpression funcExpr) - throws AlgebricksException { - //make sure that there are no variables in the expression - Set<LogicalVariable> usedVariables = new HashSet<>(); - funcExpr.getUsedVariables(usedVariables); - return usedVariables.isEmpty(); - } - protected boolean inlineVariables(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); @@ -151,8 +132,7 @@ public class InlineVariablesRule implements IAlgebraicRewriteRule { // Ignore functions that are either in the doNotInline set or are non-functional if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; - if (doNotInlineFuncs.contains(funcExpr.getFunctionIdentifier()) || (!funcExpr.isFunctional() - && !InlineVariablesRule.functionIsConstantAtRuntime(funcExpr))) { + if (doNotInlineFuncs.contains(funcExpr.getFunctionIdentifier()) || !funcExpr.isFunctional()) { continue; } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PushMapOperatorDownThroughProductRule.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PushMapOperatorDownThroughProductRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PushMapOperatorDownThroughProductRule.java index f956d73..f71af5a 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PushMapOperatorDownThroughProductRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PushMapOperatorDownThroughProductRule.java @@ -50,6 +50,11 @@ public class PushMapOperatorDownThroughProductRule implements IAlgebraicRewriteR if (!op1.isMap() || op1.getOperatorTag() == LogicalOperatorTag.LIMIT) { return false; } + + if (!OperatorPropertiesUtil.isMovable(op1)) { + return false; + }; + Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b8a42f3/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/SetExecutionModeRule.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/SetExecutionModeRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/SetExecutionModeRule.java index ed85001..32a3bac 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/SetExecutionModeRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/SetExecutionModeRule.java @@ -19,8 +19,7 @@ package org.apache.hyracks.algebricks.rewriter.rules; import org.apache.commons.lang3.mutable.Mutable; - -import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator; import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext; import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator; @@ -38,7 +37,8 @@ import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule; public class SetExecutionModeRule implements IAlgebraicRewriteRule { @Override - public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) { + public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) + throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); return OperatorManipulationUtil.setOperatorMode(op); }
