You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by "Victoria Markman (JIRA)" <ji...@apache.org> on 2015/09/12 02:04:45 UTC

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

Victoria Markman created DRILL-3769:
---------------------------------------

             Summary: 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
            Reporter: Victoria Markman


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)