>From Peeyush Gupta <peeyush.gu...@couchbase.com>: Peeyush Gupta has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18928 )
Change subject: [ASTERIXDB-3512][COMP] Error with query if secondary indexes created ...................................................................... [ASTERIXDB-3512][COMP] Error with query if secondary indexes created - user model changes: no - storage format changes: no - interface changes: no Ext-ref: MB-63696 Change-Id: Ie6b97d5436fe6f76a92548f2aa756ef5d6d20e49 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18928 Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Ali Alsuliman <ali.al.solai...@gmail.com> --- A asterixdb/asterix-app/src/test/resources/optimizerts/queries/query-ASTERIXDB-3512.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.1.ddl.sqlpp M hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.2.update.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.adm M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml A asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.query.sqlpp 8 files changed, 217 insertions(+), 4 deletions(-) Approvals: Ali Alsuliman: Looks good to me, approved Jenkins: Verified Anon. E. Moose #1000171: diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/query-ASTERIXDB-3512.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/query-ASTERIXDB-3512.sqlpp new file mode 100644 index 0000000..d51df3b --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/query-ASTERIXDB-3512.sqlpp @@ -0,0 +1,44 @@ +/* + * 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 dt1 as {id: int}; + +create dataset collection1(dt1) PRIMARY KEY id; +create dataset collection2(dt1) PRIMARY KEY id; + +CREATE INDEX idx1 ON collection2 (date: STRING, oid: STRING, sym: STRING, reg: BIGINT); + +with tmp1 AS ( + SELECT S.sym + FROM collection1 AS S + WHERE S.date < print_date(current_date(), 'YYYY-MM-DD')), + tmp2 AS ( + SELECT O.sym + FROM collection2 AS O + WHERE O.date < print_date(current_date(), 'YYYY-MM-DD')) +SELECT sl1.sym +FROM tmp1 AS sl1 +UNION ALL +SELECT sl2.sym +FROM tmp2 as sl2; diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan new file mode 100644 index 0000000..9160a43 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan @@ -0,0 +1,28 @@ +-- DISTRIBUTE_RESULT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- UNION_ALL |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_SELECT |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN (test.collection1) |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_SELECT |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- BTREE_SEARCH (test.collection2.collection2) |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STABLE_SORT [$$117(ASC)] |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- BTREE_SEARCH (test.collection2.idx1) |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.1.ddl.sqlpp new file mode 100644 index 0000000..980d4d4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.1.ddl.sqlpp @@ -0,0 +1,34 @@ +/* + * 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: This test case is to verify the fix for ASTERIXDB-3512 + */ + +drop dataverse test if exists; +create dataverse test; + +use test; + +create type dt1 as {id: int}; + +create dataset collection1(dt1) PRIMARY KEY id; +create dataset collection2(dt1) PRIMARY KEY id; + +CREATE INDEX idx1 ON collection2 (date: STRING, oid: STRING, sym: STRING, reg: BIGINT); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.2.update.sqlpp new file mode 100644 index 0000000..41879a7 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.2.update.sqlpp @@ -0,0 +1,38 @@ +/* + * 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; + +upsert into collection1 +[ + { + "id":1, + "sym":10, + "date": "2024-01-01" + } +]; + +upsert into collection2 +[ + { + "id":1, + "sym":10, + "date": "2024-01-01" + } +]; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.query.sqlpp new file mode 100644 index 0000000..60f91ad --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.query.sqlpp @@ -0,0 +1,38 @@ +/* + * 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: This test case is to verify the fix for ASTERIXDB-3512 + */ + +use test; + +with tmp1 AS ( + SELECT S.sym + FROM collection1 AS S + WHERE S.date < print_date(current_date(), 'YYYY-MM-DD')), + tmp2 AS ( + SELECT O.sym + FROM collection2 AS O + WHERE O.date < print_date(current_date(), 'YYYY-MM-DD')) +SELECT sl1.sym +FROM tmp1 AS sl1 +UNION ALL +SELECT sl2.sym +FROM tmp2 as sl2; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.adm new file mode 100644 index 0000000..9ea757d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/query-ASTERIXDB-3512/query-ASTERIXDB-3512.3.adm @@ -0,0 +1,2 @@ +{ "sym": 10 } +{ "sym": 10 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml index 717700f..09b9e23 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -7311,6 +7311,11 @@ </compilation-unit> </test-case> <test-case FilePath="misc"> + <compilation-unit name="query-ASTERIXDB-3512"> + <output-dir compare="Text">query-ASTERIXDB-3512</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="misc"> <compilation-unit name="remove_listify"> <output-dir compare="Text">remove_listify</output-dir> </compilation-unit> diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java index 956f0b7..84346fd 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java @@ -42,6 +42,7 @@ import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans; import org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator; +import org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator; @@ -163,9 +164,15 @@ if (!canRemoveOperator(op, opInSubplan, parentOp)) { break; } - op = (AbstractLogicalOperator) op.getInputs().get(0).getValue(); - opRef.setValue(op); - assignVarsSetForThisOp = removeAssignVarFromConsideration(opRef); + if (op.getOperatorTag() == LogicalOperatorTag.AGGREGATE) { + op = new EmptyTupleSourceOperator(); + context.computeAndSetTypeEnvironmentForOperator(op); + opRef.setValue(op); + } else { + op = (AbstractLogicalOperator) op.getInputs().get(0).getValue(); + opRef.setValue(op); + assignVarsSetForThisOp = removeAssignVarFromConsideration(opRef); + } isTransformed = true; } @@ -445,7 +452,7 @@ private static boolean canRemoveOperator(ILogicalOperator op, boolean opInsideSubplan, ILogicalOperator parentOp) { LogicalOperatorTag opTag = op.getOperatorTag(); - if (opTag == LogicalOperatorTag.AGGREGATE || opTag == LogicalOperatorTag.UNIONALL) { + if ((opTag == LogicalOperatorTag.AGGREGATE && opInsideSubplan) || opTag == LogicalOperatorTag.UNIONALL) { return false; } if (!opInsideSubplan) { -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18928 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: neo Gerrit-Change-Id: Ie6b97d5436fe6f76a92548f2aa756ef5d6d20e49 Gerrit-Change-Number: 18928 Gerrit-PatchSet: 7 Gerrit-Owner: Peeyush Gupta <peeyush.gu...@couchbase.com> Gerrit-Reviewer: Ali Alsuliman <ali.al.solai...@gmail.com> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Peeyush Gupta <peeyush.gu...@couchbase.com> Gerrit-MessageType: merged