Dmitry Lychagin has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/3397
Change subject: [NO ISSUE][COMP] Change plan printing for window operators ...................................................................... [NO ISSUE][COMP] Change plan printing for window operators - user model changes: no - storage format changes: no - interface changes: no Details: - Print window operators as 'window-aggregate' in the query plan - Add testcase for a window function call used in WHERE clause, and a negative testcase - Implement reset() for LogicalOperatorPrettyPrintVisitorJson - Make IOptimizationContext.getPrettyPrintVisitor() return AbstractLogicalOperatorPrettyPrintVisitor Change-Id: I1446238a7c550abf618a72650c2a811fbc4dd710 --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/misc_01/misc_01.9.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.5.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.9.adm A asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/window/misc_01/misc_01.9.ast M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java 12 files changed, 129 insertions(+), 13 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/97/3397/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/misc_01/misc_01.9.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/misc_01/misc_01.9.query.sqlpp new file mode 100644 index 0000000..b8db547 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/misc_01/misc_01.9.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ +/* + * Description : Window function call in a complex WHERE clause + * Expected Res : SUCCESS + */ + +from range(1, 10) x +where to_bigint(to_double(x)) > 1 + and sum(x) over () = 55 + and x < 4 + and count(x) over () = 10 +select value x; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.5.query.sqlpp new file mode 100644 index 0000000..be98876 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.5.query.sqlpp @@ -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. + */ +/* + * Description : Test unsupported Group All case + * Expected Res : FAILURE + */ + + from range(1, 4) x + let y = sum(count(x)) over () + select value x \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.9.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.9.adm new file mode 100644 index 0000000..1234e84 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.9.adm @@ -0,0 +1,2 @@ +2 +3 \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/window/misc_01/misc_01.9.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/window/misc_01/misc_01.9.ast new file mode 100644 index 0000000..ebedcaa --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/window/misc_01/misc_01.9.ast @@ -0,0 +1,48 @@ +Query: +SELECT ELEMENT [ +Variable [ Name=$x ] +] +FROM [ FunctionCall null.range@2[ + LiteralExpr [LONG] [1] + LiteralExpr [LONG] [10] + ] + AS Variable [ Name=$x ] +] +Where + OperatorExpr [ + OperatorExpr [ + FunctionCall null.to-bigint@1[ + FunctionCall null.to-double@1[ + Variable [ Name=$x ] + ] + ] + > + LiteralExpr [LONG] [1] + ] + and + OperatorExpr [ + WINDOW null.sum@1[ + Variable [ Name=$x ] + ] + OVER ( + ) + = + LiteralExpr [LONG] [55] + ] + and + OperatorExpr [ + Variable [ Name=$x ] + < + LiteralExpr [LONG] [4] + ] + and + OperatorExpr [ + WINDOW null.count@1[ + Variable [ Name=$x ] + ] + OVER ( + ) + = + LiteralExpr [LONG] [10] + ] + ] \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 8e96fc5..33bf2d8 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -10167,6 +10167,7 @@ <expected-error>ASX1101: Unexpected ORDER BY clause in window expression</expected-error> <expected-error>ASX1037: Invalid query parameter compiler.windowmemory</expected-error> <expected-error>ASX1102: Expected window or aggregate function, got: unknown_func</expected-error> + <expected-error>ASX1079: Compilation error: count is a SQL-92 aggregate function</expected-error> <source-location>false</source-location> </compilation-unit> </test-case> diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java index a5b2284..ea486f1 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java @@ -25,7 +25,7 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.IMergeAggregationExpressionFactory; import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment; import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider; -import org.apache.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor; +import org.apache.hyracks.algebricks.core.algebra.prettyprint.AbstractLogicalOperatorPrettyPrintVisitor; import org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency; import org.apache.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector; import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain; @@ -81,7 +81,7 @@ public void updatePrimaryKeys(Map<LogicalVariable, LogicalVariable> mappedVars); - public LogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor(); + public AbstractLogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor(); public INodeDomain getComputationNodeDomain(); } diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java index 460f4d0..5319e6a 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java @@ -46,7 +46,7 @@ public AbstractLogicalOperatorPrettyPrintVisitor(AlgebricksAppendable buffer, ILogicalExpressionVisitor<String, Integer> exprVisitor) { - reset(buffer); + this.buffer = buffer; this.exprVisitor = exprVisitor; } diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java index 4128c8b..16afd50 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java @@ -485,7 +485,7 @@ @Override public Void visitWindowOperator(WindowOperator op, Integer indent) throws AlgebricksException { - addIndent(indent).append("window ").append(str(op.getVariables())).append(" <- "); + addIndent(indent).append("window-aggregate ").append(str(op.getVariables())).append(" <- "); pprintExprList(op.getExpressions(), indent); if (!op.getPartitionExpressions().isEmpty()) { buffer.append(" partition "); diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java index f4e8003..7e8a289 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java @@ -77,6 +77,9 @@ public class LogicalOperatorPrettyPrintVisitorJson extends AbstractLogicalOperatorPrettyPrintVisitor { Map<AbstractLogicalOperator, String> operatorIdentity = new HashMap<>(); + public LogicalOperatorPrettyPrintVisitorJson() { + } + public LogicalOperatorPrettyPrintVisitorJson(Appendable app) { super(app); } @@ -115,6 +118,12 @@ } return operatorIdentity.get(op); } + } + + @Override + public AlgebricksAppendable reset(AlgebricksAppendable buffer) { + operatorIdentity.clear(); + return super.reset(buffer); } @Override @@ -662,7 +671,7 @@ @Override public Void visitWindowOperator(WindowOperator op, Integer indent) throws AlgebricksException { Integer fldIndent = indent + 2; - addIndent(indent).append("\"operator\": \"window\""); + addIndent(indent).append("\"operator\": \"window-aggregate\""); variablePrintHelper(op.getVariables(), indent); List<Mutable<ILogicalExpression>> expressions = op.getExpressions(); if (!expressions.isEmpty()) { diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java index 08fe460..6ed4c9e 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java @@ -27,8 +27,8 @@ import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext; 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.prettyprint.AbstractLogicalOperatorPrettyPrintVisitor; import org.apache.hyracks.algebricks.core.algebra.prettyprint.AlgebricksAppendable; -import org.apache.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor; import org.apache.hyracks.algebricks.core.algebra.prettyprint.PlanPrettyPrinter; import org.apache.hyracks.algebricks.core.config.AlgebricksConfig; import org.apache.hyracks.util.LogRedactionUtil; @@ -67,7 +67,7 @@ private String getPlanString(Mutable<ILogicalOperator> opRef) throws AlgebricksException { if (AlgebricksConfig.ALGEBRICKS_LOGGER.isTraceEnabled() && context != null) { - LogicalOperatorPrettyPrintVisitor pvisitor = context.getPrettyPrintVisitor(); + AbstractLogicalOperatorPrettyPrintVisitor pvisitor = context.getPrettyPrintVisitor(); pvisitor.reset(new AlgebricksAppendable()); PlanPrettyPrinter.printOperator((AbstractLogicalOperator) opRef.getValue(), pvisitor, 0); return pvisitor.get().toString(); diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java index 25a4c7a..8c994e7 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java @@ -38,7 +38,7 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment; import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment; import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider; -import org.apache.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor; +import org.apache.hyracks.algebricks.core.algebra.prettyprint.AbstractLogicalOperatorPrettyPrintVisitor; import org.apache.hyracks.algebricks.core.algebra.properties.DefaultNodeGroupDomain; import org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency; import org.apache.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector; @@ -85,14 +85,15 @@ private final IExpressionTypeComputer expressionTypeComputer; private final IMissableTypeComputer nullableTypeComputer; private final INodeDomain defaultNodeDomain; - private final LogicalOperatorPrettyPrintVisitor prettyPrintVisitor; + private final AbstractLogicalOperatorPrettyPrintVisitor prettyPrintVisitor; private final IConflictingTypeResolver conflictingTypeResovler; public AlgebricksOptimizationContext(int varCounter, IExpressionEvalSizeComputer expressionEvalSizeComputer, IMergeAggregationExpressionFactory mergeAggregationExpressionFactory, IExpressionTypeComputer expressionTypeComputer, IMissableTypeComputer nullableTypeComputer, IConflictingTypeResolver conflictingTypeResovler, PhysicalOptimizationConfig physicalOptimizationConfig, - AlgebricksPartitionConstraint clusterLocations, LogicalOperatorPrettyPrintVisitor prettyPrintVisitor) { + AlgebricksPartitionConstraint clusterLocations, + AbstractLogicalOperatorPrettyPrintVisitor prettyPrintVisitor) { this.varCounter = varCounter; this.expressionEvalSizeComputer = expressionEvalSizeComputer; this.mergeAggregationExpressionFactory = mergeAggregationExpressionFactory; @@ -320,7 +321,7 @@ } @Override - public LogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor() { + public AbstractLogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor() { return prettyPrintVisitor; } diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java index 61a843c..64b3f00 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java @@ -29,8 +29,8 @@ import org.apache.hyracks.algebricks.core.algebra.base.PhysicalOperatorTag; 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.prettyprint.AbstractLogicalOperatorPrettyPrintVisitor; import org.apache.hyracks.algebricks.core.algebra.prettyprint.AlgebricksAppendable; -import org.apache.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor; import org.apache.hyracks.algebricks.core.algebra.prettyprint.PlanPrettyPrinter; import org.apache.hyracks.algebricks.core.config.AlgebricksConfig; import org.apache.hyracks.util.LogRedactionUtil; @@ -85,7 +85,7 @@ private void logPlanAt(String name, Level lvl) throws AlgebricksException { if (AlgebricksConfig.ALGEBRICKS_LOGGER.isEnabled(lvl)) { - final LogicalOperatorPrettyPrintVisitor pvisitor = context.getPrettyPrintVisitor(); + final AbstractLogicalOperatorPrettyPrintVisitor pvisitor = context.getPrettyPrintVisitor(); pvisitor.reset(new AlgebricksAppendable()); PlanPrettyPrinter.printPlan(plan, pvisitor, 0); AlgebricksConfig.ALGEBRICKS_LOGGER.log(lvl, -- To view, visit https://asterix-gerrit.ics.uci.edu/3397 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: I1446238a7c550abf618a72650c2a811fbc4dd710 Gerrit-Change-Number: 3397 Gerrit-PatchSet: 1 Gerrit-Owner: Dmitry Lychagin <[email protected]>
