[ASTERIXDB-2536][COMP] Do not push Select through RunningAggregate
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Make OperatorPropertiesUtil.isMovable() return false
for RunningAggregate operators, so Select operators
are not pushed through them
Change-Id: Iae9e69d2a15664360ae8f05fd09eba1a38e346c7
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3305
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/flwr/at07.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/flwr/at07.sqlpp
new file mode 100644
index 0000000..e9e87ca
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/flwr/at07.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.EmploymentType as
+{
+ `organization-name` : string,
+ `start-date` : date,
+ `end-date` : date?
+};
+
+create type test.FacebookUserType as
+ closed {
+ id : bigint,
+ alias : string,
+ name : string,
+ `user-since` : datetime,
+ `friend-ids` : {{bigint}},
+ employment : [EmploymentType]
+};
+
+create dataset FacebookUsers(FacebookUserType) primary key id;
+
+select v.*, i/cnt * 100 as percentile, i, cnt
+from
+ (select name, alias from FacebookUsers order by name) v at i,
+ (select value count(*) from FacebookUsers) cnt
+where v.name = "NicholasStroh"
+order by percentile;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan
new file mode 100644
index 0000000..b91aa81
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan
@@ -0,0 +1,41 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- SORT_MERGE_EXCHANGE [$#2(ASC) ] |PARTITIONED|
+ -- STABLE_SORT [$#2(ASC)] |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- NESTED_LOOP |PARTITIONED|
+ -- RANDOM_PARTITION_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- RUNNING_AGGREGATE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- SORT_MERGE_EXCHANGE [$$84(ASC) ] |PARTITIONED|
+ -- STABLE_SORT [$$84(ASC)] |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- REPLICATE |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
+ -- BROADCAST_EXCHANGE |PARTITIONED|
+ -- AGGREGATE |UNPARTITIONED|
+ -- RANDOM_MERGE_EXCHANGE |PARTITIONED|
+ -- AGGREGATE |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- REPLICATE |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.1.ddl.sqlpp
new file mode 100644
index 0000000..32a29c1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.1.ddl.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Cannot push SELECT through RUNNINGAGGREGATE operator
+ * Expected Result : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.EmploymentType as
+{
+ `organization-name` : string,
+ `start-date` : date,
+ `end-date` : date?
+};
+
+create type test.FacebookUserType as
+ closed {
+ id : bigint,
+ alias : string,
+ name : string,
+ `user-since` : datetime,
+ `friend-ids` : {{bigint}},
+ employment : [EmploymentType]
+};
+
+create dataset FacebookUsers(FacebookUserType) primary key id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.2.update.sqlpp
new file mode 100644
index 0000000..06f12e5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.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.
+ */
+/*
+ * Description : Cannot push SELECT through RUNNINGAGGREGATE operator
+ * Expected Result : Success
+ */
+
+use test;
+
+load dataset FacebookUsers using localfs ((`path`=`asterix_nc1://data/tinysocial/fbu.adm`),(`format`=`adm`));
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.3.query.sqlpp
new file mode 100644
index 0000000..6ce99ab
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at07/at07.3.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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 : Cannot push SELECT through RUNNINGAGGREGATE operator
+ * Expected Result : Success
+ */
+
+use test;
+
+select v.*, i/cnt * 100 as percentile, i, cnt
+from
+ (select name, alias from FacebookUsers order by name) v at i,
+ (select value count(*) from FacebookUsers) cnt
+where v.name = "NicholasStroh"
+order by percentile;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/flwor/at07/at07.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/flwor/at07/at07.3.adm
new file mode 100644
index 0000000..0c8f982
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/flwor/at07/at07.3.adm
@@ -0,0 +1 @@
+{ "percentile": 50.0, "i": 5, "cnt": 10, "name": "NicholasStroh", "alias": "Nicholas" }
\ 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 3ab1ff9..0031b9f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -60,6 +60,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="flwor">
+ <compilation-unit name="at07">
+ <output-dir compare="Text">at07</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="flwor">
<compilation-unit name="order-by-13">
<output-dir compare="Text">order-by-13</output-dir>
</compilation-unit>
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 a5cd5fa..3361bb5 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
@@ -300,24 +300,26 @@
* @param op
* the operator to consider.
* @return true if the operator can be moved, false if the operator cannot be moved.
- * @throws AlgebricksException
*/
public static boolean isMovable(ILogicalOperator op) {
Object annotation = op.getAnnotations().get(MOVABLE);
- if (annotation == null) {
- // Can't move nonPures!
- if (op.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
+ if (annotation != null) {
+ return (Boolean) annotation;
+ }
+ switch (op.getOperatorTag()) {
+ case ASSIGN:
+ // Can't move nonPures!
AssignOperator assign = (AssignOperator) op;
for (Mutable<ILogicalExpression> expr : assign.getExpressions()) {
if (containsNonpureCall(expr.getValue())) {
return false;
}
}
- }
- return true;
+ break;
+ case RUNNINGAGGREGATE:
+ return false;
}
- Boolean movable = (Boolean) annotation;
- return movable;
+ return true;
}
private static boolean containsNonpureCall(ILogicalExpression expr) {