Return-Path: X-Original-To: apmail-drill-issues-archive@minotaur.apache.org Delivered-To: apmail-drill-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8A12218812 for ; Thu, 15 Oct 2015 04:32:05 +0000 (UTC) Received: (qmail 15799 invoked by uid 500); 15 Oct 2015 04:32:05 -0000 Delivered-To: apmail-drill-issues-archive@drill.apache.org Received: (qmail 15774 invoked by uid 500); 15 Oct 2015 04:32:05 -0000 Mailing-List: contact issues-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list issues@drill.apache.org Received: (qmail 15762 invoked by uid 99); 15 Oct 2015 04:32:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2015 04:32:05 +0000 Date: Thu, 15 Oct 2015 04:32:05 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@drill.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DRILL-3769) to_date function with one argument returns wrong data type MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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 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)