[ 
https://issues.apache.org/jira/browse/HIVE-28792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17931113#comment-17931113
 ] 

Krisztian Kasa commented on HIVE-28792:
---------------------------------------

The issue is caused by that the literal \{{'A'}} in the case expression is 
converted to char(3) and padded:
{code}
CBO PLAN:
HiveProject(col1=[$0], col2=[CAST(CASE(=(UPPER($0), _UTF-16LE'A  '), 
_UTF-16LE'OK':VARCHAR(2147483647) CHARACTER SET "UTF-16LE", 
_UTF-16LE'N/A':VARCHAR(2147483647) CHARACTER SET 
"UTF-16LE")):VARCHAR(2147483647) CHARACTER SET "UTF-16LE"])
  HiveTableScan(table=[[default, testchar]], table:alias=[testchar])
{code}
{code}
STAGE DEPENDENCIES:
  Stage-0 is a root stage

STAGE PLANS:
  Stage: Stage-0
    Fetch Operator
      limit: -1
      Processor Tree:
        TableScan
          alias: testchar
          Select Operator
            expressions: col1 (type: char(3)), if((upper(col1) = 'A  '), 'OK', 
'N/A') (type: string)
            outputColumnNames: _col0, _col1
            ListSink
{code}
However at the Hive operator level in the expression
{code}
upper(col1) = 'A  '
{code}
The function call {{upper(col1)}} has {{char(3)}} type and the literal {{'A  
'}} has {{string}} type. The result of the function is converted to string and 
during the conversion trailing spaces are trimmed.

> Wrong results when query has function call with char parameter type in case 
> expression
> --------------------------------------------------------------------------------------
>
>                 Key: HIVE-28792
>                 URL: https://issues.apache.org/jira/browse/HIVE-28792
>             Project: Hive
>          Issue Type: Bug
>          Components: CBO
>            Reporter: Krisztian Kasa
>            Priority: Major
>
> Repro
> {code:java}
> CREATE EXTERNAL TABLE testchar (col1 char(3));
> INSERT INTO testchar VALUES ('A'),('B');
> select col1, case upper(col1) when 'A' then 'OK' else 'N/A' end as col2 from 
> testchar;
> {code}
> The query should return
> {code:java}
> A     OK
> B     N/A
> {code}
> but it returns
> {code:java}
> A     N/A
> B     N/A
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to