This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f8235a  [NO ISSUE][COMP] Change plan printing for window operators
9f8235a is described below

commit 9f8235a09e6a8f20936bd6a0d6b59c2d270853b0
Author: Dmitry Lychagin <[email protected]>
AuthorDate: Tue May 14 14:54:14 2019 -0700

    [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
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3397
    Tested-by: Jenkins <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
    Reviewed-by: Ali Alsuliman <[email protected]>
---
 .../window/misc_01/misc_01.9.query.sqlpp           | 29 +++++++++++++
 .../window/win_negative/win_negative.5.query.sqlpp | 26 ++++++++++++
 .../runtimets/results/window/misc_01/misc_01.9.adm |  2 +
 .../window/misc_01/misc_01.9.ast                   | 48 ++++++++++++++++++++++
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  1 +
 .../core/algebra/base/IOptimizationContext.java    |  4 +-
 .../AbstractLogicalOperatorPrettyPrintVisitor.java |  2 +-
 .../LogicalOperatorPrettyPrintVisitor.java         |  2 +-
 .../LogicalOperatorPrettyPrintVisitorJson.java     | 11 ++++-
 .../core/rewriter/base/AbstractRuleController.java |  4 +-
 .../base/AlgebricksOptimizationContext.java        |  9 ++--
 .../core/rewriter/base/HeuristicOptimizer.java     |  4 +-
 12 files changed, 129 insertions(+), 13 deletions(-)

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 ed28b24..c9a5e37 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -10256,6 +10256,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.IExpressionEvalSiz
 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 interface IOptimizationContext extends ITypingContext, 
IVariableContext {
 
     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 abstract class 
AbstractLogicalOperatorPrettyPrintVisitor implements ILogi
 
     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 @@ public class LogicalOperatorPrettyPrintVisitor extends 
AbstractLogicalOperatorPr
 
     @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 @@ import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.WriteResultO
 public class LogicalOperatorPrettyPrintVisitorJson extends 
AbstractLogicalOperatorPrettyPrintVisitor {
     Map<AbstractLogicalOperator, String> operatorIdentity = new HashMap<>();
 
+    public LogicalOperatorPrettyPrintVisitorJson() {
+    }
+
     public LogicalOperatorPrettyPrintVisitorJson(Appendable app) {
         super(app);
     }
@@ -118,6 +121,12 @@ public class LogicalOperatorPrettyPrintVisitorJson extends 
AbstractLogicalOperat
     }
 
     @Override
+    public AlgebricksAppendable reset(AlgebricksAppendable buffer) {
+        operatorIdentity.clear();
+        return super.reset(buffer);
+    }
+
+    @Override
     public void printOperator(AbstractLogicalOperator op, int indent) throws 
AlgebricksException {
         int currentIndent = indent;
         final AlgebricksAppendable out = get();
@@ -662,7 +671,7 @@ public class LogicalOperatorPrettyPrintVisitorJson extends 
AbstractLogicalOperat
     @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.ILogicalPlan;
 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 @@ public abstract class AbstractRuleController {
 
     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.IMissableTypeCompu
 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 @@ public class AlgebricksOptimizationContext implements 
IOptimizationContext {
     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 @@ public class AlgebricksOptimizationContext implements 
IOptimizationContext {
     }
 
     @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.IOptimizationContext;
 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 @@ public class HeuristicOptimizer {
 
     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,

Reply via email to