Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 16055200CF9 for ; Sun, 3 Sep 2017 07:52:39 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 12A67164802; Sun, 3 Sep 2017 05:52:39 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 32480164803 for ; Sun, 3 Sep 2017 07:52:38 +0200 (CEST) Received: (qmail 8704 invoked by uid 500); 3 Sep 2017 05:52:37 -0000 Mailing-List: contact commits-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: commits@drill.apache.org Delivered-To: mailing list commits@drill.apache.org Received: (qmail 8625 invoked by uid 99); 3 Sep 2017 05:52:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Sep 2017 05:52:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A094BF5621; Sun, 3 Sep 2017 05:52:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: amansinha@apache.org To: commits@drill.apache.org Date: Sun, 03 Sep 2017 05:52:38 -0000 Message-Id: In-Reply-To: <854ecd938b294738a69b2155d83430ce@git.apache.org> References: <854ecd938b294738a69b2155d83430ce@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/3] drill git commit: DRILL-1051: Casting timestamp as date gives wrong result for dates earlier than 1883 archived-at: Sun, 03 Sep 2017 05:52:39 -0000 DRILL-1051: Casting timestamp as date gives wrong result for dates earlier than 1883 - Fix DateAccessor's, TimestampAccessor's and TimeAccessor's converting joda time to java.sql close apache/drill#915 Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/406dd2a5 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/406dd2a5 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/406dd2a5 Branch: refs/heads/master Commit: 406dd2a58d2168faf47636fcd9829f29a93175bd Parents: 33f17aa Author: Vitalii Diravka Authored: Tue Aug 15 17:51:10 2017 +0000 Committer: Aman Sinha Committed: Sat Sep 2 13:38:02 2017 -0700 ---------------------------------------------------------------------- .../main/codegen/templates/SqlAccessors.java | 28 +++++++++----------- .../apache/drill/jdbc/test/TestJdbcQuery.java | 25 ++++++++++++++++- 2 files changed, 36 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/406dd2a5/exec/java-exec/src/main/codegen/templates/SqlAccessors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java index 49a91c2..888d1c6 100644 --- a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java +++ b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -264,9 +264,10 @@ public class ${name}Accessor extends AbstractSqlAccessor { return null; } - org.joda.time.DateTime date = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC); - date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault()); - return new Date(date.getMillis()); + org.joda.time.LocalDate date = new org.joda.time.LocalDate(ac.get(index), org.joda.time.DateTimeZone.UTC); + // Use "toDate()" to get java.util.Date object with exactly the same year the same year, month and day as Joda date. + // See more in Javadoc for "LocalDate#toDate()" + return new Date(date.toDate().getTime()); } <#elseif minor.class == "TimeStamp"> @@ -293,9 +294,10 @@ public class ${name}Accessor extends AbstractSqlAccessor { return null; } - org.joda.time.DateTime date = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC); - date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault()); - return new Timestamp(date.getMillis()); + org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(ac.get(index), org.joda.time.DateTimeZone.UTC); + // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time. + // See more in Javadoc for "LocalDateTime#toDate()" + return new Timestamp(dateTime.toDate().getTime()); } <#elseif minor.class == "Time"> @@ -317,9 +319,9 @@ public class ${name}Accessor extends AbstractSqlAccessor { return null; } - org.joda.time.DateTime time = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC); - time = time.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault()); - return new TimePrintMillis(time.getMillis()); + org.joda.time.LocalTime time = new org.joda.time.LocalTime(ac.get(index), org.joda.time.DateTimeZone.UTC); + // use "toDateTimeToday()" and "getMillis()" to get the local milliseconds from the Java epoch of 1970-01-01T00:00:00 + return new TimePrintMillis(time.toDateTimeToday().getMillis()); } <#else> @@ -330,7 +332,6 @@ public class ${name}Accessor extends AbstractSqlAccessor { } - <#if minor.class == "Bit" > public boolean getBoolean(int index) { <#if mode == "Nullable"> @@ -341,13 +342,8 @@ public class ${name}Accessor extends AbstractSqlAccessor { return 1 == ac.get(index); } - - <#-- not VarLen --> - } - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/drill/blob/406dd2a5/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java index bff620e..1dd172f 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -367,4 +367,27 @@ public class TestJdbcQuery extends JdbcTestQueryBase { "TIME_INT_ADD=6\n" ); } + + @Test // DRILL-1051 + public void testOldDateTimeJulianCalendar() throws Exception { + // Should be work with any timezone + JdbcAssert.withNoDefaultSchema() + .sql("select cast(to_timestamp('1581-12-01 23:32:01', 'yyyy-MM-dd HH:mm:ss') as date) as `DATE`, " + + "to_timestamp('1581-12-01 23:32:01', 'yyyy-MM-dd HH:mm:ss') as `TIMESTAMP`, " + + "cast(to_timestamp('1581-12-01 23:32:01', 'yyyy-MM-dd HH:mm:ss') as time) as `TIME` " + + "from (VALUES(1))") + .returns("DATE=1581-12-01; TIMESTAMP=1581-12-01 23:32:01.0; TIME=23:32:01"); + } + + @Test // DRILL-1051 + public void testOldDateTimeLocalMeanTime() throws Exception { + // Should be work with any timezone + JdbcAssert.withNoDefaultSchema() + .sql("select cast(to_timestamp('1883-11-16 01:32:01', 'yyyy-MM-dd HH:mm:ss') as date) as `DATE`, " + + "to_timestamp('1883-11-16 01:32:01', 'yyyy-MM-dd HH:mm:ss') as `TIMESTAMP`, " + + "cast(to_timestamp('1883-11-16 01:32:01', 'yyyy-MM-dd HH:mm:ss') as time) as `TIME` " + + "from (VALUES(1))") + .returns("DATE=1883-11-16; TIMESTAMP=1883-11-16 01:32:01.0; TIME=01:32:01"); + } + }