[ASTERIXDB-2420][COMP] Internal error with limit clause
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- CopyLimitDownRule must not copy limit below clauses
that produce that limit’s variables
Change-Id: I6c77b7e24d6d0a95f3c772301d592c5b5c478119
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2805
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Taewoo Kim <wangsaeu@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.1.ddl.sqlpp
new file mode 100644
index 0000000..4f446c8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.1.ddl.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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 push down limit
+ * Expected Result : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.DBLPType as
+{
+ id : bigint,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+};
+
+create dataset DBLP1(DBLPType) primary key id;
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.2.update.sqlpp
new file mode 100644
index 0000000..867b825
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.2.update.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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;
+
+load dataset DBLP1 using localfs ((`path`=`asterix_nc1://data/dblp-small/dblp-small-id.txt`),(`format`=`delimited-text`),(`delimiter`=`:`));
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.3.query.sqlpp
new file mode 100644
index 0000000..8960f6b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.3.query.sqlpp
@@ -0,0 +1,25 @@
+/* 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 limit pushdown
+ * Expected Result : Success
+ */
+
+use test;
+
+select value t.id
+from DBLP1 t
+order by t.id
+limit {"a":1}.a offset {"a":1}.a
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.1.adm
new file mode 100644
index 0000000..d8263ee
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/query-ASTERIXDB-2420/query-ASTERIXDB-2420.1.adm
@@ -0,0 +1 @@
+2
\ 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 16bf364..49bed4b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -10197,6 +10197,11 @@
<output-dir compare="Text">push-limit-to-primary-lookup-select</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="limit">
+ <compilation-unit name="query-ASTERIXDB-2420">
+ <output-dir compare="Text">query-ASTERIXDB-2420</output-dir>
+ </compilation-unit>
+ </test-case>
</test-group>
&GeoQueries;
</test-suite>
diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
index 1eaf9c7..4a224c8 100644
--- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
+++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
@@ -67,13 +67,17 @@
List<LogicalVariable> candidateProducedVars = new ArrayList<>();
while (true) {
- candidateProducedVars.clear();
ILogicalOperator candidateOp = candidateOpRef.getValue();
LogicalOperatorTag candidateOpTag = candidateOp.getOperatorTag();
if (candidateOp.getInputs().size() > 1 || !candidateOp.isMap()
|| candidateOpTag == LogicalOperatorTag.SELECT || candidateOpTag == LogicalOperatorTag.LIMIT
- || candidateOpTag == LogicalOperatorTag.UNNEST_MAP
- || !OperatorPropertiesUtil.disjoint(limitUsedVars, candidateProducedVars)) {
+ || candidateOpTag == LogicalOperatorTag.UNNEST_MAP) {
+ break;
+ }
+
+ candidateProducedVars.clear();
+ VariableUtilities.getProducedVariables(candidateOp, candidateProducedVars);
+ if (!OperatorPropertiesUtil.disjoint(limitUsedVars, candidateProducedVars)) {
break;
}