drill-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hao Zhu (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DRILL-3727) Drill should return NULL instead of failure if cast column is empty
Date Tue, 01 Sep 2015 00:31:46 GMT

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

Hao Zhu commented on DRILL-3727:
--------------------------------

PostgreSQL's behavior is the similar as Drill. 
{code}
test=# create table testempty(col0 varchar);
CREATE TABLE

test=# insert into testempty values
test-# ('');
INSERT 0 1

test=# insert into testempty values('2015-01-01');
INSERT 0 1

test=# select * from testempty ;
    col0
------------

 2015-01-01
(2 rows)

test=# select cast(col0 as date) from testempty;
ERROR:  invalid input syntax for type date: ""

test=# select case when col0='' then null else cast(col0 as date) end from testempty;
    col0
------------

 2015-01-01
(2 rows)

{code}

> Drill should return NULL instead of failure if cast column is empty
> -------------------------------------------------------------------
>
>                 Key: DRILL-3727
>                 URL: https://issues.apache.org/jira/browse/DRILL-3727
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Functions - Hive
>    Affects Versions: 1.1.0
>         Environment: 1.1
>            Reporter: Hao Zhu
>            Assignee: Mehant Baid
>
> If Drill is casting an empty string to date, it will fail with error:
> Error: SYSTEM ERROR: IllegalFieldValueException: Value 0 for monthOfYear must be in the
range [1,12]
> However Hive can just return a NULL instead.
> I think it makes sense for Drill to have the same behavior as Hive in this case.
> Repro:
> Hive:
> {code}
> create table h1db.testempty(col0 string)
> ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'
> STORED AS TEXTFILE
> ;
> hive> select * from h1db.testempty ;
> OK
> 2015-01-01
> Time taken: 0.28 seconds, Fetched: 2 row(s)
> hive> select cast(col0 as date) from  h1db.testempty;
> OK
> NULL
> 2015-01-01
> Time taken: 0.078 seconds, Fetched: 2 row(s)
> {code}
> Drill:
> {code}
> use hive;
> > select * from h1db.testempty ;
> +-------------+
> |    col0     |
> +-------------+
> |             |
> | 2015-01-01  |
> +-------------+
> 2 rows selected (0.232 seconds)
> > select cast(col0 as date) from  h1db.testempty;
> Error: SYSTEM ERROR: IllegalFieldValueException: Value 0 for monthOfYear must be in the
range [1,12]
> {code}
> Workaround:
> {code}
> > select case when col0='' then null else cast(col0 as date) end from  h1db.testempty;
> +-------------+
> |   EXPR$0    |
> +-------------+
> | null        |
> | 2015-01-01  |
> +-------------+
> 2 rows selected (0.287 seconds)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message