You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2023/06/13 13:18:07 UTC

[arrow-adbc] branch main updated: fix(java/driver/jdbc): return timestamps as MICROSECOND always (#771)

This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new a83a3972 fix(java/driver/jdbc): return timestamps as MICROSECOND always (#771)
a83a3972 is described below

commit a83a3972386276fc46770f3915da87a93f86830c
Author: David Li <li...@gmail.com>
AuthorDate: Tue Jun 13 09:18:01 2023 -0400

    fix(java/driver/jdbc): return timestamps as MICROSECOND always (#771)
    
    Fixes #770.
---
 .../driver/jdbc/postgresql/PostgreSqlTypeTest.java |  8 +++----
 .../arrow/adbc/driver/jdbc/StandardJdbcQuirks.java | 28 +++++-----------------
 2 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/java/driver/jdbc-validation-postgresql/src/test/java/org/apache/arrow/adbc/driver/jdbc/postgresql/PostgreSqlTypeTest.java b/java/driver/jdbc-validation-postgresql/src/test/java/org/apache/arrow/adbc/driver/jdbc/postgresql/PostgreSqlTypeTest.java
index 0eab44c3..2a02ff5c 100644
--- a/java/driver/jdbc-validation-postgresql/src/test/java/org/apache/arrow/adbc/driver/jdbc/postgresql/PostgreSqlTypeTest.java
+++ b/java/driver/jdbc-validation-postgresql/src/test/java/org/apache/arrow/adbc/driver/jdbc/postgresql/PostgreSqlTypeTest.java
@@ -76,27 +76,27 @@ class PostgreSqlTypeTest extends AbstractSqlTypeTest {
   protected void timestamp3WithoutTimeZoneType() throws Exception {
     final Schema schema = connection.getTableSchema(null, null, "adbc_alltypes");
     assertThat(schema.findField("timestamp_without_time_zone_p3_t").getType())
-        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MILLISECOND, null));
+        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null));
   }
 
   @Test
   protected void timestamp2WithoutTimeZoneType() throws Exception {
     final Schema schema = connection.getTableSchema(null, null, "adbc_alltypes");
     assertThat(schema.findField("timestamp_without_time_zone_p2_t").getType())
-        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MILLISECOND, null));
+        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null));
   }
 
   @Test
   protected void timestamp1WithoutTimeZoneType() throws Exception {
     final Schema schema = connection.getTableSchema(null, null, "adbc_alltypes");
     assertThat(schema.findField("timestamp_without_time_zone_p1_t").getType())
-        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MILLISECOND, null));
+        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null));
   }
 
   @Test
   protected void timestamp0WithoutTimeZoneType() throws Exception {
     final Schema schema = connection.getTableSchema(null, null, "adbc_alltypes");
     assertThat(schema.findField("timestamp_without_time_zone_p0_t").getType())
-        .isEqualTo(new ArrowType.Timestamp(TimeUnit.SECOND, null));
+        .isEqualTo(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null));
   }
 }
diff --git a/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/StandardJdbcQuirks.java b/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/StandardJdbcQuirks.java
index d65182fa..aa38150f 100644
--- a/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/StandardJdbcQuirks.java
+++ b/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/StandardJdbcQuirks.java
@@ -60,29 +60,13 @@ public final class StandardJdbcQuirks {
   private static ArrowType postgresql(JdbcFieldInfoExtra field) {
     switch (field.getJdbcType()) {
       case Types.TIMESTAMP:
-        {
-          int decimalDigits = field.getScale();
-          final TimeUnit unit;
-          if (decimalDigits == 0) {
-            unit = TimeUnit.SECOND;
-          } else if (decimalDigits > 0 && decimalDigits <= 3) {
-            unit = TimeUnit.MILLISECOND;
-          } else if (decimalDigits > 0 && decimalDigits <= 6) {
-            unit = TimeUnit.MICROSECOND;
-          } else if (decimalDigits > 6) {
-            unit = TimeUnit.NANOSECOND;
-          } else {
-            // Negative precision?
-            return null;
-          }
-          if ("timestamptz".equals(field.getTypeName())) {
-            return new ArrowType.Timestamp(unit, "UTC");
-          } else if ("timestamp".equals(field.getTypeName())) {
-            return new ArrowType.Timestamp(unit, /*timezone*/ null);
-          }
-          // Unknown type
-          return null;
+        if ("timestamptz".equals(field.getTypeName())) {
+          return new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC");
+        } else if ("timestamp".equals(field.getTypeName())) {
+          return new ArrowType.Timestamp(TimeUnit.MICROSECOND, /*timezone*/ null);
         }
+        // Unknown type
+        return null;
       default:
         return JdbcToArrowUtils.getArrowTypeFromJdbcType(field.getFieldInfo(), /*calendar*/ null);
     }