You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "kasakrisz (via GitHub)" <gi...@apache.org> on 2026/03/13 13:48:47 UTC
[PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
kasakrisz opened a new pull request, #6360:
URL: https://github.com/apache/hive/pull/6360
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
```
mvn test -Dtest.output.overwrite -Dtest=TestMiniLlapLocalCliDriver -Dqfile=empty_result_correlate2.q -pl itests/qtest -Pitests
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz merged PR #6360:
URL: https://github.com/apache/hive/pull/6360
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2960012253
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java:
##########
@@ -461,16 +458,6 @@ public Frame decorrelateRel(Sort rel) {
frame.corDefOutputs);
}
- /**
- * Rewrites a {@link Values}.
- *
- * @param rel Values to be rewritten
- */
- public Frame decorrelateRel(Values rel) {
- // There are no inputs, so rel does not need to be changed.
- return null;
- }
-
Review Comment:
Yes. We need these rules.
The query in the test added along with these rules
```
SELECT id FROM t1 WHERE NULL IN (SELECT NULL FROM t2 where t1.id = t2.id);
```
has a plan
```
HiveProject(id=[$0])
LogicalCorrelate(correlation=[$cor0], joinType=[semi], requiredColumns=[{}])
HiveTableScan(table=[[default, t1]], table:alias=[t1])
HiveValues(tuples=[[]])
```
The decorrelator doesn't find any `CorrelateId` in the right (Values) and abort decorrelation
https://github.com/apache/hive/blob/d55885ee5ef5036c3371ccd46cd46fa20715a58e/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java#L1241-L1253
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6360:
URL: https://github.com/apache/hive/pull/6360#issuecomment-4055906222
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_coverage&view=list)
 [5.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2959922437
##########
ql/src/test/queries/clientpositive/empty_result_correlate2.q:
##########
@@ -0,0 +1,22 @@
+set hive.support.concurrency=true;
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+-- To create a HiveValues operator before decorrelation automatic query rewrite with
+-- materialized views is used.
+-- All tables must be transactional to trigger automatic query rewrite.
+create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true');
+create table t1 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
+create table t2 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
+
+-- At least one materialized view must exist.
+create materialized view any_mv as
+select any_col from mv_source where any_col > 20;
+
+-- Automatic query rewrite traverses the plan and recreates the HiveFilter using RelBuilder.
+-- If the condition is always false, it replaces the filter with HiveValues.
+explain cbo
+select * from t1 where 1 = 2
+union
+select * from t1
+where exists (select a from t2 where t1.a > 10)
Review Comment:
The rules
* HiveRemoveEmptySingleRules.CORRELATE_LEFT_INSTANCE
* HiveRemoveEmptySingleRules.CORRELATE_RIGHT_INSTANCE
expect that the empty `Values` is one of the inputs of the `Correlate`.
However, if the plan contains an operator with multiple inputs (ex. Union) and one of the input is an empty branch, decorrelation is aborted—even when the `Correlate` is in a different input. Please see the unit test I added to the PR for an example.
https://github.com/apache/hive/blob/d55885ee5ef5036c3371ccd46cd46fa20715a58e/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java#L389-L394
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "zabetak (via GitHub)" <gi...@apache.org>.
zabetak commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2965295174
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+ TestRuleHelper.PlanFixture fixture() {
+ RelOptPlanner planner = buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+ planner.setExecutor(new HiveRexExecutorImpl());
+ return new TestRuleHelper.PlanFixture(planner)
+ .registerTable("t1", T1Record.class)
+ .registerTable("t2", T2Record.class);
+ }
+
+
+ @Test
+ public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
Review Comment:
Since the whole test is about the decorrelator the prefix `testDecorrelate` is redundant and combined with the rest of the line it makes the test name hard to read.
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+ TestRuleHelper.PlanFixture fixture() {
+ RelOptPlanner planner = buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+ planner.setExecutor(new HiveRexExecutorImpl());
+ return new TestRuleHelper.PlanFixture(planner)
+ .registerTable("t1", T1Record.class)
+ .registerTable("t2", T2Record.class);
+ }
+
+
+ @Test
+ public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
+ RelBuilder relBuilder = fixture().createRelBuilder();
+ Holder<RexCorrelVariable> v = Holder.empty();
+ RelNode base = relBuilder
+ .scan("t1")
+ .empty()
+ .scan("t1")
+ .variable(v)
+ .scan("t2")
+ .filter(relBuilder.call(SqlStdOperatorTable.EQUALS, relBuilder.getRexBuilder().makeFieldAccess(v.get(), 0), relBuilder.literal(10)))
+ .correlate(JoinRelType.SEMI, v.get().id, relBuilder.field(2, 0, "t1id"))
+ .union(false)
+ .build();
+
+ Assert.assertTrue("Plan before decorrelation does not contain correlate: \n" + RelOptUtil.toString(base),
+ RelOptUtil.toString(base).contains("Correlate"));
+ Assert.assertTrue("Plan before decorrelation does not contain Values: \n" + RelOptUtil.toString(base),
+ RelOptUtil.toString(base).contains("Values"));
+
+ RelNode decorrelatedPlan = HiveRelDecorrelator.decorrelateQuery(base);
+
+ Assert.assertFalse("Plan after decorrelation still has correlate: \n" + RelOptUtil.toString(decorrelatedPlan),
+ RelOptUtil.toString(decorrelatedPlan).contains("Correlate"));
+ Assert.assertTrue("Plan after decorrelation does not contain Values: \n" + RelOptUtil.toString(decorrelatedPlan),
+ RelOptUtil.toString(decorrelatedPlan).contains("Values"));
Review Comment:
I find the usual (full) plan comparisons which are used when testing rules and transformations easier to follow. They may require more frequent updates but seeing the plan before and after makes the test easier to follow.
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+ TestRuleHelper.PlanFixture fixture() {
+ RelOptPlanner planner = buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+ planner.setExecutor(new HiveRexExecutorImpl());
+ return new TestRuleHelper.PlanFixture(planner)
+ .registerTable("t1", T1Record.class)
+ .registerTable("t2", T2Record.class);
+ }
+
+
+ @Test
+ public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
Review Comment:
You may want to add `Union` in the test name since empty values could appear in many different places and apparently the decorrelator is not handling everything.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "zabetak (via GitHub)" <gi...@apache.org>.
zabetak commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2958952533
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java:
##########
@@ -461,16 +458,6 @@ public Frame decorrelateRel(Sort rel) {
frame.corDefOutputs);
}
- /**
- * Rewrites a {@link Values}.
- *
- * @param rel Values to be rewritten
- */
- public Frame decorrelateRel(Values rel) {
- // There are no inputs, so rel does not need to be changed.
- return null;
- }
-
Review Comment:
Are the following rules still relevant/necessary after we perform this change:
* HiveRemoveEmptySingleRules.CORRELATE_LEFT_INSTANCE
* HiveRemoveEmptySingleRules.CORRELATE_RIGHT_INSTANCE
##########
ql/src/test/queries/clientpositive/empty_result_correlate2.q:
##########
@@ -0,0 +1,22 @@
+set hive.support.concurrency=true;
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+-- To create a HiveValues operator before decorrelation automatic query rewrite with
+-- materialized views is used.
+-- All tables must be transactional to trigger automatic query rewrite.
+create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true');
+create table t1 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
+create table t2 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
+
+-- At least one materialized view must exist.
+create materialized view any_mv as
+select any_col from mv_source where any_col > 20;
+
+-- Automatic query rewrite traverses the plan and recreates the HiveFilter using RelBuilder.
+-- If the condition is always false, it replaces the filter with HiveValues.
+explain cbo
+select * from t1 where 1 = 2
+union
+select * from t1
+where exists (select a from t2 where t1.a > 10)
Review Comment:
Can you elaborate a bit on why the existing `HiveRemoveEmptySingleRules` are not helping in this case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6360:
URL: https://github.com/apache/hive/pull/6360#issuecomment-4092656635
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360) **Quality Gate passed**
Issues
 [10 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_coverage&view=list)
 [7.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2959777441
##########
ql/src/test/queries/clientpositive/empty_result_correlate2.q:
##########
@@ -0,0 +1,22 @@
+set hive.support.concurrency=true;
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+-- To create a HiveValues operator before decorrelation automatic query rewrite with
+-- materialized views is used.
+-- All tables must be transactional to trigger automatic query rewrite.
+create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true');
Review Comment:
I agree with Thomas.
I removed this q test and added a unit test focusing on testing `HiveRelDecorrelator` only because at this point the table and storage format doesn't matter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6360:
URL: https://github.com/apache/hive/pull/6360#issuecomment-4096154108
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360) **Quality Gate passed**
Issues
 [10 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_coverage&view=list)
 [7.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "zabetak (via GitHub)" <gi...@apache.org>.
zabetak commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2965278497
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java:
##########
@@ -461,16 +458,6 @@ public Frame decorrelateRel(Sort rel) {
frame.corDefOutputs);
}
- /**
- * Rewrites a {@link Values}.
- *
- * @param rel Values to be rewritten
- */
- public Frame decorrelateRel(Values rel) {
- // There are no inputs, so rel does not need to be changed.
- return null;
- }
-
Review Comment:
Got it thanks! It is strange though that the decorrelator cannot handle with this simplistic case which btw seems somewhat invalid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "thomasrebele (via GitHub)" <gi...@apache.org>.
thomasrebele commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2965230306
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+ TestRuleHelper.PlanFixture fixture() {
+ RelOptPlanner planner = buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+ planner.setExecutor(new HiveRexExecutorImpl());
+ return new TestRuleHelper.PlanFixture(planner)
+ .registerTable("t1", T1Record.class)
+ .registerTable("t2", T2Record.class);
+ }
+
+
+ @Test
+ public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
Review Comment:
`RelOptUtil.toString(decorrelatedPlan)` and `RelOptUtil.toString(base)` appear repeatedly. Assigning them to a variable saves a few computations.
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+ TestRuleHelper.PlanFixture fixture() {
+ RelOptPlanner planner = buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+ planner.setExecutor(new HiveRexExecutorImpl());
+ return new TestRuleHelper.PlanFixture(planner)
+ .registerTable("t1", T1Record.class)
+ .registerTable("t2", T2Record.class);
+ }
+
+
+ @Test
+ public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
+ RelBuilder relBuilder = fixture().createRelBuilder();
+ Holder<RexCorrelVariable> v = Holder.empty();
+ RelNode base = relBuilder
+ .scan("t1")
+ .empty()
+ .scan("t1")
+ .variable(v)
+ .scan("t2")
+ .filter(relBuilder.call(SqlStdOperatorTable.EQUALS, relBuilder.getRexBuilder().makeFieldAccess(v.get(), 0), relBuilder.literal(10)))
+ .correlate(JoinRelType.SEMI, v.get().id, relBuilder.field(2, 0, "t1id"))
+ .union(false)
+ .build();
+
+ Assert.assertTrue("Plan before decorrelation does not contain correlate: \n" + RelOptUtil.toString(base),
Review Comment:
I was a bit confused by the messages, until I realized that they apply only in the case of an assertion error.
How about reformulating them to
* "Plan before decorrelation must contain a Correlate node"
* "Plan before decorrelation must contain a Values node"
* "Plan after decorrelation may not contain a Correlate node"
* "Plan after decorrelation must still contain a Values node"
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+ TestRuleHelper.PlanFixture fixture() {
+ RelOptPlanner planner = buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+ planner.setExecutor(new HiveRexExecutorImpl());
+ return new TestRuleHelper.PlanFixture(planner)
+ .registerTable("t1", T1Record.class)
+ .registerTable("t2", T2Record.class);
+ }
+
+
+ @Test
+ public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
+ RelBuilder relBuilder = fixture().createRelBuilder();
+ Holder<RexCorrelVariable> v = Holder.empty();
+ RelNode base = relBuilder
+ .scan("t1")
+ .empty()
+ .scan("t1")
+ .variable(v)
+ .scan("t2")
+ .filter(relBuilder.call(SqlStdOperatorTable.EQUALS, relBuilder.getRexBuilder().makeFieldAccess(v.get(), 0), relBuilder.literal(10)))
+ .correlate(JoinRelType.SEMI, v.get().id, relBuilder.field(2, 0, "t1id"))
+ .union(false)
+ .build();
+
+ Assert.assertTrue("Plan before decorrelation does not contain correlate: \n" + RelOptUtil.toString(base),
+ RelOptUtil.toString(base).contains("Correlate"));
+ Assert.assertTrue("Plan before decorrelation does not contain Values: \n" + RelOptUtil.toString(base),
+ RelOptUtil.toString(base).contains("Values"));
+
+ RelNode decorrelatedPlan = HiveRelDecorrelator.decorrelateQuery(base);
+
+ Assert.assertFalse("Plan after decorrelation still has correlate: \n" + RelOptUtil.toString(decorrelatedPlan),
+ RelOptUtil.toString(decorrelatedPlan).contains("Correlate"));
+ Assert.assertTrue("Plan after decorrelation does not contain Values: \n" + RelOptUtil.toString(decorrelatedPlan),
Review Comment:
I would recommend to dump the before and after plan into a comment. The plans are reasonably small and they help to understand what's going on.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6360:
URL: https://github.com/apache/hive/pull/6360#issuecomment-4109958805
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360) **Quality Gate passed**
Issues
 [6 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6360&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6360&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_coverage&view=list)
 [7.6% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6360&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6360)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-29506: HiveRelDecorrelator fails to decorrelate plan with Values operator [hive]
Posted by "zabetak (via GitHub)" <gi...@apache.org>.
zabetak commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2965265713
##########
ql/src/test/queries/clientpositive/empty_result_correlate2.q:
##########
@@ -0,0 +1,22 @@
+set hive.support.concurrency=true;
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+
+-- To create a HiveValues operator before decorrelation automatic query rewrite with
+-- materialized views is used.
+-- All tables must be transactional to trigger automatic query rewrite.
+create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true');
+create table t1 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
+create table t2 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
+
+-- At least one materialized view must exist.
+create materialized view any_mv as
+select any_col from mv_source where any_col > 20;
+
+-- Automatic query rewrite traverses the plan and recreates the HiveFilter using RelBuilder.
+-- If the condition is always false, it replaces the filter with HiveValues.
+explain cbo
+select * from t1 where 1 = 2
+union
+select * from t1
+where exists (select a from t2 where t1.a > 10)
Review Comment:
I guess the empty branch can be removed by `HiveRemoveEmptySingleRules#UNION_INSTANCE` but in order for this work the rule should run before the decorrelator. Anyways, at this stage changing the decorrelator is probably a safer and better change than applying the removal rules in a different place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org