Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
Impala 2.5.0
-
None
Description
Joe Prosser reports this odd behaviour:
[jvp1-3.vpc.cloudera.com:21000] > create table c (v char(1)); Query: create table c (v char(1)) Fetched 0 row(s) in 0.26s -- This simple cast works for an insert [jvp1-3.vpc.cloudera.com:21000] > insert into c select cast('a' as char(1)); Query: insert into c select cast('a' as char(1)) Inserted 1 row(s) in 5.20s -- this one when using a case statement gives a precision error [jvp1-3.vpc.cloudera.com:21000] > insert into c select case when 5 < 3 then cast('L' as char(1)) else cast('M' as char(1)) end as v; Query: insert into c select case when 5 < 3 then cast('L' as char(1)) else cast('M' as char(1)) end as v ERROR: AnalysisException: Possible loss of precision for target table 'ilimisp01_eciw.c'. Expression 'CASE WHEN 5 < 3 THEN CAST('L' AS CHAR(1)) ELSE CAST('M' AS CHAR(1)) END' (type: STRING) would need to be cast to CHAR(1) for column 'v' -- the same thing works with varchar though: [jvp1-3.vpc.cloudera.com:21000] > create table vc (v varchar(1)); Query: create table vc (v varchar(1)) Fetched 0 row(s) in 0.23s [jvp1-3.vpc.cloudera.com:21000] > insert into vc select case when 5 < 3 then cast('L' as varchar(1)) else cast('M' as varchar(1)) end as v; Query: insert into vc select case when 5 < 3 then cast('L' as varchar(1)) else cast('M' as varchar(1)) end as v Inserted 1 row(s) in 4.88s