calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject calcite git commit: [CALCITE-1072] CSV adapter incorrectly parses TIMESTAMP values after noon
Date Tue, 02 Feb 2016 18:15:23 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 446d1122b -> 7b944ade8


[CALCITE-1072] CSV adapter incorrectly parses TIMESTAMP values after noon


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/7b944ade
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/7b944ade
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/7b944ade

Branch: refs/heads/master
Commit: 7b944ade81f600e74b43f9ab8ef7ce84f05b3e2a
Parents: 446d112
Author: Julian Hyde <jhyde@apache.org>
Authored: Mon Feb 1 20:56:12 2016 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon Feb 1 20:56:12 2016 -0800

----------------------------------------------------------------------
 .../calcite/adapter/csv/CsvEnumerator.java      | 10 ++---
 .../java/org/apache/calcite/test/CsvTest.java   | 40 ++++++++++++++++++++
 example/csv/src/test/resources/bug/DATE.csv     |  2 +
 3 files changed, 47 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/7b944ade/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
----------------------------------------------------------------------
diff --git a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
index a534daf..8db969c 100644
--- a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
+++ b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
@@ -56,9 +56,9 @@ class CsvEnumerator<E> implements Enumerator<E> {
   static {
     TimeZone gmt = TimeZone.getTimeZone("GMT");
     TIME_FORMAT_DATE = FastDateFormat.getInstance("yyyy-MM-dd", gmt);
-    TIME_FORMAT_TIME = FastDateFormat.getInstance("hh:mm:ss", gmt);
-    TIME_FORMAT_TIMESTAMP = FastDateFormat.getInstance(
-        "yyyy-MM-dd hh:mm:ss", gmt);
+    TIME_FORMAT_TIME = FastDateFormat.getInstance("HH:mm:ss", gmt);
+    TIME_FORMAT_TIMESTAMP =
+        FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss", gmt);
   }
 
   public CsvEnumerator(File file, List<CsvFieldType> fieldTypes) {
@@ -96,8 +96,8 @@ class CsvEnumerator<E> implements Enumerator<E> {
    * of a CSV file. */
   static RelDataType deduceRowType(JavaTypeFactory typeFactory, File file,
       List<CsvFieldType> fieldTypes) {
-    final List<RelDataType> types = new ArrayList<RelDataType>();
-    final List<String> names = new ArrayList<String>();
+    final List<RelDataType> types = new ArrayList<>();
+    final List<String> names = new ArrayList<>();
     CSVReader reader = null;
     try {
       reader = openCsv(file);

http://git-wip-us.apache.org/repos/asf/calcite/blob/7b944ade/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
----------------------------------------------------------------------
diff --git a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
index 650dce1..4040867 100644
--- a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
+++ b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
@@ -425,6 +425,46 @@ public class CsvTest {
 
     }
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1072">[CALCITE-1072]
+   * CSV adapter incorrectly parses TIMESTAMP values after noon</a>. */
+  @Test public void testDateType2() throws SQLException {
+    Properties info = new Properties();
+    info.put("model", jsonPath("bug"));
+
+    try (Connection connection
+        = DriverManager.getConnection("jdbc:calcite:", info)) {
+      Statement statement = connection.createStatement();
+      ResultSet resultSet =
+          statement.executeQuery("select * from \"DATE\" where EMPNO >= 140");
+      int n = 0;
+      while (resultSet.next()) {
+        ++n;
+        final int empId = resultSet.getInt(1);
+        final String date = resultSet.getString(2);
+        final String time = resultSet.getString(3);
+        final String timestamp = resultSet.getString(4);
+        assertThat(date, is("2015-12-31"));
+        switch (empId) {
+        case 140:
+          assertThat(time, is("07:15:56"));
+          assertThat(timestamp, is("2015-12-31 07:15:56"));
+          break;
+        case 150:
+          assertThat(time, is("13:31:21"));
+          assertThat(timestamp, is("2015-12-31 13:31:21"));
+          break;
+        default:
+          throw new AssertionError();
+        }
+      }
+      assertThat(n, is(2));
+      resultSet.close();
+      statement.close();
+    }
+  }
+
 }
 
 // End CsvTest.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/7b944ade/example/csv/src/test/resources/bug/DATE.csv
----------------------------------------------------------------------
diff --git a/example/csv/src/test/resources/bug/DATE.csv b/example/csv/src/test/resources/bug/DATE.csv
index ea5ef35..57a0d65 100644
--- a/example/csv/src/test/resources/bug/DATE.csv
+++ b/example/csv/src/test/resources/bug/DATE.csv
@@ -4,3 +4,5 @@ EMPNO:int,JOINEDAT:date,JOINTIME:time,JOINTIMES:timestamp
 110,"2002-05-03","00:00:00","2002-05-03 00:00:00"
 120,"2005-09-07","00:00:00","2005-09-07 00:00:00"
 130,"2007-01-01","00:00:00","2007-01-01 00:00:00"
+140,"2015-12-31","07:15:56","2015-12-31 07:15:56"
+150,"2015-12-31","13:31:21","2015-12-31 13:31:21"


Mime
View raw message