You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2019/03/06 19:24:19 UTC

[asterixdb] branch master updated: [ASTERIXDB-2525][COMP] Re-infer types after introducing aggregate combiners

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 c402e5b  [ASTERIXDB-2525][COMP] Re-infer types after introducing aggregate combiners
c402e5b is described below

commit c402e5b23ff702041161f3c8c3ac2a92dac4e3a5
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Tue Mar 5 15:07:37 2019 -0800

    [ASTERIXDB-2525][COMP] Re-infer types after introducing aggregate combiners
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Re-infer all types after introducing aggregate combiners
    - AbstractIntroduceGroupByCombinerRule should keep original
      operators in nested plans if it did not apply
    
    Change-Id: I404b795452660792166d7e41edcd7dbf9d85f9f8
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3248
    Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../asterix/optimizer/base/RuleCollections.java    |  2 ++
 .../rules/SetClosedRecordConstructorsRule.java     |  6 ++---
 .../query-ASTERIXDB-2525.1.query.sqlpp             | 26 ++++++++++++++++++++++
 .../query-ASTERIXDB-2525.1.adm                     |  1 +
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  5 +++++
 .../AbstractIntroduceGroupByCombinerRule.java      | 24 +++++++++++---------
 6 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
index 1dd5e9c..25f49d9 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
@@ -293,6 +293,8 @@ public final class RuleCollections {
         consolidation.add(new InlineAssignIntoAggregateRule());
         consolidation.add(new AsterixIntroduceGroupByCombinerRule());
         consolidation.add(new IntroduceAggregateCombinerRule());
+        // Re-infer all types after introducing aggregate combiners
+        consolidation.add(new ReinferAllTypesRule());
         consolidation.add(new CountVarToCountOneRule());
         consolidation.add(new RemoveUnusedAssignAndAggregateRule());
         consolidation.add(new RemoveRedundantGroupByDecorVarsRule());
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
index 9ca80e5..50da592 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
@@ -18,9 +18,6 @@
  */
 package org.apache.asterix.optimizer.rules;
 
-import static org.apache.asterix.common.config.GlobalConfig.ASTERIX_LOGGER;
-
-import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.lang.common.util.FunctionUtil;
@@ -43,6 +40,7 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceE
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
 import org.apache.hyracks.algebricks.core.algebra.visitors.AbstractConstVarFunVisitor;
 import org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionReferenceTransform;
+import org.apache.hyracks.algebricks.core.config.AlgebricksConfig;
 import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 import org.apache.hyracks.util.LogRedactionUtil;
 
@@ -137,7 +135,7 @@ public class SetClosedRecordConstructorsRule implements IAlgebraicRewriteRule {
                     }
                     if (allClosed) {
                         expr.setFunctionInfo(FunctionUtil.getFunctionInfo(BuiltinFunctions.CLOSED_RECORD_CONSTRUCTOR));
-                        ASTERIX_LOGGER.trace(() -> "Switching to CLOSED record constructor in "
+                        AlgebricksConfig.ALGEBRICKS_LOGGER.trace(() -> "Switching to CLOSED record constructor in "
                                 + LogRedactionUtil.userData(expr.toString()) + ".\n");
                         changed = true;
                     }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/global-aggregate/query-ASTERIXDB-2525/query-ASTERIXDB-2525.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/global-aggregate/query-ASTERIXDB-2525/query-ASTERIXDB-2525.1.query.sqlpp
new file mode 100644
index 0000000..39575b5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/global-aggregate/query-ASTERIXDB-2525/query-ASTERIXDB-2525.1.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.
+ */
+
+select (
+  select value count(d.x)
+  from (
+    from range(1,4) x
+    select x
+  ) d
+)[0] as res
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/global-aggregate/query-ASTERIXDB-2525/query-ASTERIXDB-2525.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/global-aggregate/query-ASTERIXDB-2525/query-ASTERIXDB-2525.1.adm
new file mode 100644
index 0000000..897d4ad
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/global-aggregate/query-ASTERIXDB-2525/query-ASTERIXDB-2525.1.adm
@@ -0,0 +1 @@
+{ "res": 4 }
\ 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 d3c66b6..ea6205f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -3995,6 +3995,11 @@
         <output-dir compare="Text">query-ASTERIXDB-1626-2</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="global-aggregate">
+      <compilation-unit name="query-ASTERIXDB-2525">
+        <output-dir compare="Text">query-ASTERIXDB-2525</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="group-by">
     <test-case FilePath="group-by">
diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java
index 7b9c255..1e6d79a 100644
--- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java
+++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java
@@ -21,7 +21,6 @@ package org.apache.hyracks.algebricks.rewriter.rules;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -144,21 +143,24 @@ public abstract class AbstractIntroduceGroupByCombinerRule extends AbstractIntro
         List<LogicalVariable> gbyVars = gbyOp.getGbyVarList();
 
         // Backup nested plans since tryToPushSubplan(...) may mutate them.
-        List<ILogicalPlan> copiedNestedPlans = new ArrayList<>();
-        for (ILogicalPlan nestedPlan : gbyOp.getNestedPlans()) {
-            ILogicalPlan copiedNestedPlan = OperatorManipulationUtil.deepCopy(nestedPlan, gbyOp);
-            OperatorManipulationUtil.computeTypeEnvironment(copiedNestedPlan, context);
-            copiedNestedPlans.add(copiedNestedPlan);
-        }
+        List<ILogicalPlan> gbyNestedPlans = gbyOp.getNestedPlans();
+        List<ILogicalPlan> backupNestedPlans = new ArrayList<>(gbyNestedPlans);
+
+        for (int i = 0, n = gbyNestedPlans.size(); i < n; i++) {
+            ILogicalPlan nestedPlan = gbyNestedPlans.get(i);
+
+            // Replace nested plan with its copy
+            ILogicalPlan p = OperatorManipulationUtil.deepCopy(nestedPlan, gbyOp);
+            OperatorManipulationUtil.computeTypeEnvironment(p, context);
+            gbyNestedPlans.set(i, p);
 
-        for (ILogicalPlan p : gbyOp.getNestedPlans()) {
             // NOTE: tryToPushSubplan(...) can mutate the nested subplan p.
             Pair<Boolean, ILogicalPlan> bip = tryToPushSubplan(p, gbyOp, newGbyOp, bi, gbyVars, context);
             if (!bip.first) {
                 // For now, if we cannot push everything, give up.
-                // Resets the group-by operator with backup nested plans.
-                gbyOp.getNestedPlans().clear();
-                gbyOp.getNestedPlans().addAll(copiedNestedPlans);
+                // Resets the group-by operator with original nested plans.
+                gbyNestedPlans.clear();
+                gbyNestedPlans.addAll(backupNestedPlans);
                 return null;
             }
             ILogicalPlan pushedSubplan = bip.second;