You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@drill.apache.org by "Bridget Bevens (JIRA)" <ji...@apache.org> on 2018/12/18 23:12:00 UTC

[jira] [Commented] (DRILL-6768) Improve to_date, to_time and to_timestamp and corresponding cast functions to handle empty string when `drill.exec.functions.cast_empty_string_to_null` option is enabled

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

Bridget Bevens commented on DRILL-6768:
---------------------------------------

Hi [~KazydubB],

I will add this note to this page: [https://drill.apache.org/docs/data-type-conversion/]

*NOTE*
 _Starting in Drill 1.15, all cast and data type conversion functions return an empty string ('') as NULL when the drill.exec.functions.cast_empty_string_to_null option is enabled. Prior to 1.15, casting an empty string to null worked only for numeric types; in Drill 1.15 and later casting an empty string to null works for DATE, TIME, TIMESTAMP, INTERVAL YEAR, INTERVAL MONTH, and INTERVAL DAY data types. You do not have to use the CASE statement to cast empty strings to values null._

Also, on this page [https://drill.apache.org/docs/text-files-csv-tsv-psv/#cast-data] 
 There is a bullet point that says you can use the CASE statement to cast empty strings to the values you want.

• How would you write the query now, in Drill 1.15, when the drill.exec.functions.cast_empty_string_to_null option is enabled?
 • Do you still need to use the CASE statement or will Drill implicitly cast the empty strings to null if you exclude the CASE statement, as follows?


 CREATE TABLE test AS SELECT
 CAST(COLUMNS[0] AS INTEGER) end AS c1,
 CAST(COLUMNS[1] AS VARCHAR(20)) end AS c2,
 CAST(COLUMNS[2] AS DOUBLE) end AS c3,
 CAST(COLUMNS[3] AS DATE) end AS c4,
 CAST(COLUMNS[4] AS VARCHAR(20)) end AS c5
 FROM `test.csv`;

I will document this JIRA in the release notes also. Is there any other information I need to include in the documentation for this JIRA or DRILL-6817?

Thanks,
 Bridget

> Improve to_date, to_time and to_timestamp and corresponding cast functions to handle empty string when `drill.exec.functions.cast_empty_string_to_null` option is enabled
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DRILL-6768
>                 URL: https://issues.apache.org/jira/browse/DRILL-6768
>             Project: Apache Drill
>          Issue Type: Improvement
>    Affects Versions: 1.14.0
>            Reporter: Bohdan Kazydub
>            Assignee: Bohdan Kazydub
>            Priority: Major
>              Labels: doc-impacting, ready-to-commit
>             Fix For: 1.15.0
>
>
> When `drill.exec.functions.cast_empty_string_to_null` option is enabled
> `to_date`, `to_time` and `to_timestamp` functions while converting string to according type in case if null or empty string values are passed will return NULL (to avoid CASE clauses which are littering a query and will work in accordance with their respective CAST counterparts) for both cases.
>  
>   
>   
> CASTs will  be handled in a similar way (uniformly with numeric types):
>  
> ||Value to cast||Now||Will be||
> |NULL|NULL|NULL|
> |'' (empty string)|Error in many cases (except numerical types)|NULL|
>  CAST empty string to null (in case of enabled option) will be supported by DATE, TIME, TIMESTAMP, INTERVAL YEAR, INTERVAL MONTH and INTERVAL DAY functions in addition to numeric types.
>  
> *For documentation*
> TBA



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)