Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
None
Description
If t is a char column, this statement behaves a bit strangely - since the RHS is a STRING, I would have expected it to behave consistently with other CHAR/STRING comparisons, where the CHAR column has its trailing spaces removed and the STRING does not have its trailing spaces removed.
select count(*) from ax where t = cast('a ' as string);
Instead it seems to be treated the same as if it was a plain literal, interpreted as CHAR, i.e.
select count(*) from ax where t = 'a ';
Here are some more experiments I did based on https://github.com/apache/hive/blob/master/ql/src/test/queries/clientpositive/in_typecheck_char.q that seem to show some inconsistencies.
-- 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 | +------+
Attachments
Issue Links
- is related to
-
IMPALA-1652 Fix CHAR datatype: Incorrect results with basic predicate on CHAR typed column.
- Open