[
https://issues.apache.org/jira/browse/IMPALA-1652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17178108#comment-17178108
]
Tim Armstrong commented on IMPALA-1652:
---------------------------------------
We can probably get similar behaviour to Hive by carefully converting string
literals to char values if they are arguments to operators with other CHAR
values. It interacts with constant folding though - we wouldn't want to do it
after folding exprs. Hive actually has some weird behaviour here with literals.
{noformat}
-- Hive version 3.1.3000.7.2.1.0-287 r4e72e59f1c2a51a64e0ff37b14bd396cd4e97b98
create table ax(s char(1),t char(10));
insert into ax values ('a','a'),('a','a '),('b','bb');
-- varchar literal preserves trailing space
select count(*) from ax where t = cast('a ' as varchar(50));
+------+
| _c0 |
+------+
| 0 |
+------+
-- explicit cast of literal to string removes trailing space
select count(*) from ax where t = cast('a ' as string);
+------+
| _c0 |
+------+
| 2 |
+------+
-- other string expressions preserve trailing space
select count(*) from ax where t = concat('a', ' ');
+------+
| _c0 |
+------+
| 0 |
+------+
-- varchar col preserves trailing space
create table stringv as select cast('a ' as varchar(50));
select count(*) from ax, stringv where t = `_c0`;
+------+
| _c0 |
+------+
| 0 |
+------+
-- string col preserves trailing space
create table stringa as select 'a ';
select count(*) from ax, stringa where t = `_c0`;
+------+
| _c0 |
+------+
| 0 |
+------+
{noformat}
> Fix CHAR datatype: Incorrect results with basic predicate on CHAR typed
> column.
> -------------------------------------------------------------------------------
>
> Key: IMPALA-1652
> URL: https://issues.apache.org/jira/browse/IMPALA-1652
> Project: IMPALA
> Issue Type: Bug
> Components: Backend
> Affects Versions: Impala 2.1, Impala 2.3.0
> Reporter: Alexander Behm
> Priority: Major
> Labels: correctness, downgraded, usability
> Attachments: 8be18d4.diff
>
>
> Repro:
> {code}
> create table foo(col1 char(10));
> insert into foo values (cast('test1' as char(10)));
> select * from foo where col1 = 'test1'; <-- returns an empty result set
> select * from foo where col1 = cast('test1' as char(10)); <-- correctly
> returns 1 row
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]