Dmitry Lychagin has uploaded a new change for review.

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

Change subject: [ASTERIXDB-2348][COMP] Incorrect result with distinct aggregate
......................................................................

[ASTERIXDB-2348][COMP] Incorrect result with distinct aggregate

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Account for micro group by/distinct by operators in
  EnforceStructuralPropertiesRule

Change-Id: I0f440046d6cdb2dc0302c5aa4c01ffacb703ee73
---
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.1.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.2.update.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.3.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue2348/issue2348.3.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M 
hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/EnforceStructuralPropertiesRule.java
6 files changed, 99 insertions(+), 6 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/44/2544/1

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.1.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.1.ddl.sqlpp
new file mode 100644
index 0000000..a50d20b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.1.ddl.sqlpp
@@ -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 test if exists;
+create  dataverse test;
+
+use test;
+
+create type test.TestType as
+{
+  c_id: string
+};
+
+create  dataset t1(TestType) primary key c_id;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.2.update.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.2.update.sqlpp
new file mode 100644
index 0000000..ec72ef5
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.2.update.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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 test;
+
+insert into t1 select value t from [
+  {"c_id":"01","c_b":true, "c_d":900,"c_i":999999},
+  {"c_id":"02","c_b":true, "c_d":800,"c_i":888888},
+  {"c_id":"03","c_b":true, "c_d":700,"c_i":777777},
+  {"c_id":"05","c_b":false,"c_d":111,"c_i":111111}
+] t
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.3.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.3.query.sqlpp
new file mode 100644
index 0000000..4fc8b4b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/aggregate-sql/issue2348/issue2348.3.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.
+ */
+
+use test;
+
+select min(distinct c_i) v
+from t1
+where c_b
+group by c_i, c_d, c_b
+order by v
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue2348/issue2348.3.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue2348/issue2348.3.adm
new file mode 100644
index 0000000..cf2ede9
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue2348/issue2348.3.adm
@@ -0,0 +1,3 @@
+{ "v": 777777 }
+{ "v": 888888 }
+{ "v": 999999 }
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 832bb06..dd2b626 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -686,6 +686,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue2348">
+        <output-dir compare="Text">issue2348</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
       <compilation-unit name="avg_double">
         <output-dir compare="Text">avg_double</output-dir>
       </compilation-unit>
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 da0466e..08de5bb 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
@@ -50,14 +50,14 @@
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder.OrderKind;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.FDsAndEquivClassesVisitor;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractPreSortedDistinctByPOperator;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractPreclusteredGroupByPOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractStableSortPOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.BroadcastExchangePOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.ExternalGroupByPOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.HashPartitionExchangePOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.HashPartitionMergeExchangePOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.InMemoryStableSortPOperator;
-import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.PreSortedDistinctByPOperator;
-import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.PreclusteredGroupByPOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.RandomMergeExchangePOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.RandomPartitionExchangePOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.RangePartitionExchangePOperator;
@@ -357,15 +357,17 @@
                 hgbyOp.computeColumnSet(gby.getGroupByList());
                 break;
             }
-            case PRE_CLUSTERED_GROUP_BY: {
+            case PRE_CLUSTERED_GROUP_BY:
+            case MICRO_PRE_CLUSTERED_GROUP_BY: {
                 GroupByOperator gby = (GroupByOperator) op;
-                PreclusteredGroupByPOperator preSortedGby = 
(PreclusteredGroupByPOperator) pOp;
+                AbstractPreclusteredGroupByPOperator preSortedGby = 
(AbstractPreclusteredGroupByPOperator) pOp;
                 preSortedGby.setGbyColumns(gby.getGbyVarList());
                 break;
             }
-            case PRE_SORTED_DISTINCT_BY: {
+            case PRE_SORTED_DISTINCT_BY:
+            case MICRO_PRE_SORTED_DISTINCT_BY: {
                 DistinctOperator d = (DistinctOperator) op;
-                PreSortedDistinctByPOperator preSortedDistinct = 
(PreSortedDistinctByPOperator) pOp;
+                AbstractPreSortedDistinctByPOperator preSortedDistinct = 
(AbstractPreSortedDistinctByPOperator) pOp;
                 
preSortedDistinct.setDistinctByColumns(d.getDistinctByVarList());
                 break;
             }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f440046d6cdb2dc0302c5aa4c01ffacb703ee73
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: release-0.9.4-pre-rc
Gerrit-Owner: Dmitry Lychagin <dmitry.lycha...@couchbase.com>

Reply via email to