Alessandro Solimando created HIVE-26722: -------------------------------------------
Summary: HiveFilterSetOpTransposeRule incorrectly prune UNION ALL operands Key: HIVE-26722 URL: https://issues.apache.org/jira/browse/HIVE-26722 Project: Hive Issue Type: Bug Components: CBO Affects Versions: 4.0.0-alpha-1 Reporter: Alessandro Solimando Assignee: Alessandro Solimando Consider the following query: {code:java} set hive.cbo.rule.exclusion.regex=ReduceExpressionsRule\(Project\); CREATE EXTERNAL TABLE t (a string, b string); INSERT INTO t VALUES ('1000', 'b1'); INSERT INTO t VALUES ('2000', 'b2'); SELECT * FROM ( SELECT a, b FROM t UNION ALL SELECT a, CAST(NULL AS string) FROM t) AS t2 WHERE a = 1000;EXPLAIN CBO SELECT * FROM ( SELECT a, b FROM t UNION ALL SELECT a, CAST(NULL AS string) FROM t) AS t2 WHERE a = 1000; {code} The expected result is: {code:java} 1000 b1 1000 NULL{code} An example of correct plan is as follows: {noformat} CBO PLAN: HiveUnion(all=[true]) HiveProject(a=[$0], b=[$1]) HiveFilter(condition=[=(CAST($0):DOUBLE, 1000)]) HiveTableScan(table=[[default, t]], table:alias=[t]) HiveProject(a=[$0], _o__c1=[null:VARCHAR(2147483647) CHARACTER SET "UTF-16LE"]) HiveFilter(condition=[=(CAST($0):DOUBLE, 1000)]) HiveTableScan(table=[[default, t]], table:alias=[t]){noformat} Consider now a scenario where expression reduction in projections is disabled by setting the following property{_}:{_} {noformat} set hive.cbo.rule.exclusion.regex=ReduceExpressionsRule\(Project\); {noformat} In this case, the simplification of _CAST(NULL)_ into _NULL_ does not happen, and we get the following (invalid) result: 1000 b1 -- This message was sent by Atlassian Jira (v8.20.10#820010)