This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 041571d17ed71620a42fc8ec688097a99e160088 Author: Peeyush Gupta <[email protected]> AuthorDate: Wed Oct 9 15:00:22 2024 -0700 [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 <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> --- .../optimizerts/queries/query-ASTERIXDB-3512.sqlpp | 44 ++++++++++++++++++++++ .../optimizerts/results/query-ASTERIXDB-3512.plan | 28 ++++++++++++++ .../query-ASTERIXDB-3512.1.ddl.sqlpp | 34 +++++++++++++++++ .../query-ASTERIXDB-3512.2.update.sqlpp | 38 +++++++++++++++++++ .../query-ASTERIXDB-3512.3.query.sqlpp | 38 +++++++++++++++++++ .../query-ASTERIXDB-3512.3.adm | 2 + .../src/test/resources/runtimets/sqlpp_queries.xml | 5 +++ .../rules/RemoveUnusedAssignAndAggregateRule.java | 15 ++++++-- 8 files changed, 200 insertions(+), 4 deletions(-) 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 0000000000..d51df3bc07 --- /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 0000000000..9160a431c1 --- /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 0000000000..980d4d459f --- /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 0000000000..41879a7324 --- /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 0000000000..60f91ada79 --- /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 0000000000..9ea757d3be --- /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 717700f96d..09b9e2360e 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -7310,6 +7310,11 @@ <output-dir compare="Text">query-ASTERIXDB-3316</output-dir> </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> 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 956f0b7b67..84346fdbcd 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.AbstractLogi 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 @@ public class RemoveUnusedAssignAndAggregateRule implements IAlgebraicRewriteRule 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 @@ public class RemoveUnusedAssignAndAggregateRule implements IAlgebraicRewriteRule 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) {
