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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]