You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@drill.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/10/15 06:32:05 UTC

[jira] [Commented] (DRILL-3769) to_date function with one argument returns wrong data type

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

ASF GitHub Bot commented on DRILL-3769:
---------------------------------------

GitHub user hsuanyi opened a pull request:

    https://github.com/apache/drill/pull/205

    DRILL-3769: Allow to_date() to use castDate()'s implementations

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/hsuanyi/incubator-drill DRILL-3769

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/drill/pull/205.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #205
    
----
commit 639dcd7bb56483bb2e6ac0e1adbd918d7dd850e5
Author: Hsuan-Yi Chu <hs...@usc.edu>
Date:   2015-10-13T05:52:05Z

    DRILL-3769: Allow to_date() to use castDate()'s implementations

----


> to_date function with one argument returns wrong data type
> ----------------------------------------------------------
>
>                 Key: DRILL-3769
>                 URL: https://issues.apache.org/jira/browse/DRILL-3769
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Functions - Drill
>    Affects Versions: 1.1.0, 1.2.0
>            Reporter: Victoria Markman
>             Fix For: Future
>
>
> 1. to_date function is not part of SQL standard according to my research (checked ISO/IEC9075-2), so implementations of it may vary from database to database (our implementation of to_date is different from Postgres, for example)
> 2. Our documentation only talks about to_date with 2 parameters: format and actual string to be converted to date type
> 3. Calcite does not seem to have to_date, which makes me think that this is Drill UDF
> 4. Apparently, if you invoke to_date() with one argument in Drill: it runs.
>    
> So there are two possibilities: we implemented to_date with one argument to be compatible with some other SQL engine, Hive ?
>    or 
>    it is a bug and we should throw an error.
> You can use to_date with one argument in a simple query:
> {code}
> 0: jdbc:drill:schema=dfs> select to_date(c1 + interval '1' day) from t1 limit 1;
> +-------------+
> |   EXPR$0    |
> +-------------+
> | 2015-01-02  |
> +-------------+
> 1 row selected (0.242 seconds)
> {code}
> However, since return type is varbinary, joins, aggregations and CTAS are going to be problematic. 
> Here is to_date use in join to illustrate this (c1 is a date column):
> {code}
> 0: jdbc:drill:schema=dfs> select * from t1, t2 where to_date(t1.c1) = t2.c2;
> Error: SYSTEM ERROR: DrillRuntimeException: Join only supports implicit casts between 1. Numeric data
>  2. Varchar, Varbinary data 3. Date, Timestamp data Left type: DATE, Right type: VAR16CHAR. Add explicit casts to avoid this error
> Fragment 0:0
> [Error Id: 66ac8248-56c5-401a-aa53-de90cb828bc4 on atsqa4-133.qa.lab:31010] (state=,code=0)
> {code}
> Since we don't support cast between varbinary and date, attempt to cast it results in:
> {code}
> 0: jdbc:drill:schema=dfs> select * from t1, t2 where cast(to_date(t1.c1) as date) = t2.c2;
> Error: SYSTEM ERROR: SchemaChangeException: Failure while trying to materialize incoming schema.  Errors:
> Error in expression at index -1.  Error: Missing function implementation: [castBIGINT(VAR16CHAR-OPTIONAL)].  Full expression: --UNKNOWN EXPRESSION--..
> Fragment 0:0
> [Error Id: deeb040a-f1d3-4ea0-8849-7ced29508576 on atsqa4-133.qa.lab:31010] (state=,code=0)
> {code}
> Same with CTAS:
> {code}
> 0: jdbc:drill:schema=dfs> create table x(a1) as select to_date(c1) from t1;
> +-----------+----------------------------+
> | Fragment  | Number of records written  |
> +-----------+----------------------------+
> | 0_0       | 10                         |
> +-----------+----------------------------+
> 1 row selected (0.4 seconds)
> 0: jdbc:drill:schema=dfs> select * from x;
> +--------------+
> |      a1      |
> +--------------+
> | [B@28b5395d  |
> | [B@11c91d8c  |
> | [B@2ab2db73  |
> | [B@446570eb  |
> | [B@5fd87761  |
> | [B@7c85b26f  |
> | [B@2d85d547  |
> | [B@2d753faa  |
> | null         |
> | [B@6ca6c936  |
> +--------------+
> 10 rows selected (0.183 seconds)
> 0: jdbc:drill:schema=dfs> select cast(a1 as date) from x;
> Error: SYSTEM ERROR: IllegalFieldValueException: Value 0 for monthOfYear must be in the range [1,12]
> Fragment 0:0
> [Error Id: 71d8cd8f-6c88-4a13-9d24-b06ef52f6572 on atsqa4-133.qa.lab:31010] (state=,code=0)
> {code}



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