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 2025/02/27 14:39:06 UTC
[PR] HIVE-28792: Wrong results when query has function call with char parameter type in case expression [hive]
kasakrisz opened a new pull request, #5663:
URL: https://github.com/apache/hive/pull/5663
<!--
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'.
-->
### Is the change a dependency upgrade?
<!--
If yes, please attach a file with output from mvn dependency:tree to validate a complete upgrade of dependency.
If no, write 'No'.
-->
### How was this patch tested?
```
mvn test -Dtest.output.overwrite -Dtest=TestMiniLlapLocalCliDriver -Dqfile=cbo_case_when_type_conversion.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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz closed pull request #5663: HIVE-28792: Wrong results when query has function call with char parameter type in case expression
URL: https://github.com/apache/hive/pull/5663
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #5663:
URL: https://github.com/apache/hive/pull/5663#discussion_r1983096410
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/RexNodeConverter.java:
##########
@@ -366,8 +369,7 @@ public static RexNode handleExplicitCast(GenericUDF udf, RelDataType returnType,
* It will be transformed into:
* CASE WHEN =(x + y, 1) THEN 'fee' WHEN =(x + y, 2) THEN 'fie' ELSE null END
*/
- public static List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> childRexNodeLst,
- RexBuilder rexBuilder) throws SemanticException {
+ public List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> childRexNodeLst) throws SemanticException {
List<RexNode> newChildRexNodeLst = new ArrayList<>();
if (FunctionRegistry.getNormalizedFunctionName(funcText).equals("case")) {
Review Comment:
Having one UDF to handle case expressions is a good idea.
Submitted an alternative solution #5681
Let's see how it goes.
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "zabetak (via GitHub)" <gi...@apache.org>.
zabetak commented on code in PR #5663:
URL: https://github.com/apache/hive/pull/5663#discussion_r1981122813
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/RexNodeConverter.java:
##########
@@ -108,22 +109,24 @@
import java.util.Collections;
import java.util.List;
+import static java.util.Arrays.asList;
+
/**
* Class that contains logic to translate Hive expressions ({@link ExprNodeDesc})
* into Calcite expressions ({@link RexNode}).
*/
public class RexNodeConverter {
private final RexBuilder rexBuilder;
- private final RelDataTypeFactory typeFactory;
+ private final FunctionHelper functionHelper;
Review Comment:
The `HiveFunctionHelper` relies and calls `RexNodeConverter` and with this change make `RexNodeConverter` rely on `HiveFunctionHelper` thus creating a strange cyclic dependency between the classes.
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/RexNodeConverter.java:
##########
@@ -366,8 +369,7 @@ public static RexNode handleExplicitCast(GenericUDF udf, RelDataType returnType,
* It will be transformed into:
* CASE WHEN =(x + y, 1) THEN 'fee' WHEN =(x + y, 2) THEN 'fie' ELSE null END
*/
- public static List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> childRexNodeLst,
- RexBuilder rexBuilder) throws SemanticException {
+ public List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> childRexNodeLst) throws SemanticException {
List<RexNode> newChildRexNodeLst = new ArrayList<>();
if (FunctionRegistry.getNormalizedFunctionName(funcText).equals("case")) {
Review Comment:
I think it was a mistake to have two separate functions that are doing the same thing and one is basically syntactic sugar for the other.
I am wondering if we could somehow do the transformation (convert to WHEN EQUALS) at the AST level (or soon afterwards) to eliminate completely the occurrences of the `CASE` function in logical/physical/execution phase. If that's possible then we could drop quite some code and avoid ambiguities and subtle bugs as this one.
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/RexNodeConverter.java:
##########
@@ -377,14 +379,12 @@ public static List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> c
if (i % 2 == 1) {
// We rewrite it
RexNode node = childRexNodeLst.get(i);
- if (node.isA(SqlKind.LITERAL) && !node.getType().equals(firstPred.getType())) {
- // this effectively changes the type of the literal to that of the predicate
- // to which it is anyway going to be compared with
- // ex: CASE WHEN =($0:SMALLINT, 1:INTEGER) ... => CASE WHEN =($0:SMALLINT, 1:SMALLINT)
- node = rexBuilder.makeCast(firstPred.getType(), node);
- }
- newChildRexNodeLst.add(
- rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, firstPred, node));
+ List<RexNode> newInputs = functionHelper.convertInputs(
Review Comment:
The use of `functionHelper` here seems a bit out of place since it is not used anywhere else in this class. It does not seem appropriate to use it only for translating the `CASE` expression.
I guess there are various other places inside this class that we create an equality comparison between two operands. It doesn't seem appropriate to have different logic for those parts. Can't we somehow use the existing logic instead of introducing the functionHelper?
##########
ql/src/test/results/clientpositive/llap/cbo_case_when_wrong_type.q.out:
##########
@@ -56,7 +56,7 @@ POSTHOOK: Input: default@t
#### A masked pattern was here ####
CBO PLAN:
HiveProject($f0=[1])
- HiveFilter(condition=[IN($0, 1:SMALLINT, 2:SMALLINT)])
+ HiveFilter(condition=[AND(CASE(=(CAST($0):INTEGER, 1), true, =(CAST($0):INTEGER, 2), true, false), IN($0, 1:SMALLINT, 2:SMALLINT, 3:SMALLINT))])
Review Comment:
This seems like a regression from HIVE-25734. Moreover the CBO plan here is different from the CBO plan of the equivalent query with `case when a = 1 ...` showing that there is some inconsistency between equivalent expressions.
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on PR #5663:
URL: https://github.com/apache/hive/pull/5663#issuecomment-2716448734
Closing in favour of #5681
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5663:
URL: https://github.com/apache/hive/pull/5663#issuecomment-2688677986
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=5663) **Quality Gate passed**
Issues
 [11 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=5663&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=5663&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=5663&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=5663&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=5663&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=5663)
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5663:
URL: https://github.com/apache/hive/pull/5663#issuecomment-2693472178
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=5663) **Quality Gate passed**
Issues
 [11 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=5663&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=5663&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=5663&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=5663&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=5663&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=5663)
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5663:
URL: https://github.com/apache/hive/pull/5663#issuecomment-2690275168
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=5663) **Quality Gate passed**
Issues
 [11 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=5663&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=5663&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=5663&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=5663&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=5663&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=5663)
--
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-28792: Wrong results when query has function call with char parameter type in case expression [hive]
Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #5663:
URL: https://github.com/apache/hive/pull/5663#discussion_r1983096410
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/RexNodeConverter.java:
##########
@@ -366,8 +369,7 @@ public static RexNode handleExplicitCast(GenericUDF udf, RelDataType returnType,
* It will be transformed into:
* CASE WHEN =(x + y, 1) THEN 'fee' WHEN =(x + y, 2) THEN 'fie' ELSE null END
*/
- public static List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> childRexNodeLst,
- RexBuilder rexBuilder) throws SemanticException {
+ public List<RexNode> rewriteCaseChildren(String funcText, List<RexNode> childRexNodeLst) throws SemanticException {
List<RexNode> newChildRexNodeLst = new ArrayList<>();
if (FunctionRegistry.getNormalizedFunctionName(funcText).equals("case")) {
Review Comment:
Submitted an alternative solution #5681
--
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