kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From granthe...@apache.org
Subject [kudu] branch master updated: [KUDU-2632] Replaced new Date(0) with DateUtil.epochDaysToSqlDate(0)
Date Fri, 13 Mar 2020 02:24:20 GMT
This is an automated email from the ASF dual-hosted git repository.

granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 84eadd6  [KUDU-2632] Replaced new Date(0) with DateUtil.epochDaysToSqlDate(0)
84eadd6 is described below

commit 84eadd637cd890c8b0384f2d88b288dd73b28fd6
Author: Volodymyr Verovkin <verjovkin@cloudera.com>
AuthorDate: Thu Mar 12 18:16:23 2020 -0700

    [KUDU-2632] Replaced new Date(0) with DateUtil.epochDaysToSqlDate(0)
    
    "new Date" creates different dates depending on timezone. That causes
    tests to fail. In order to avoid it, "new Date" is replaced with
    DateUtil.epochDaysToSqlDate(0) which internally calls LocalDate
    which is timezone irrespective.
    
    Change-Id: Ic381bac8c68499445b6f00a1a76881dac513aede
    Reviewed-on: http://gerrit.cloudera.org:8080/15425
    Tested-by: Kudu Jenkins
    Reviewed-by: Grant Henke <granthenke@apache.org>
    Tested-by: Grant Henke <granthenke@apache.org>
---
 .../src/test/java/org/apache/kudu/client/TestKeyEncoding.java  |  3 ++-
 .../src/test/java/org/apache/kudu/client/TestPartialRow.java   |  4 ++--
 .../src/test/java/org/apache/kudu/client/TestRowResult.java    | 10 ++++++----
 .../src/main/java/org/apache/kudu/test/ClientTestUtil.java     |  3 ++-
 4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
index ade63ed..7aff44f 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
@@ -40,6 +40,7 @@ import org.apache.kudu.client.PartitionSchema.HashBucketSchema;
 import org.apache.kudu.client.PartitionSchema.RangeSchema;
 import org.apache.kudu.test.KuduTestHarness;
 import org.apache.kudu.util.CharUtil;
+import org.apache.kudu.util.DateUtil;
 import org.apache.kudu.util.DecimalUtil;
 
 public class TestKeyEncoding {
@@ -419,7 +420,7 @@ public class TestKeyEncoding {
     row.addDecimal(8, BigDecimal.valueOf(DecimalUtil.MAX_UNSCALED_DECIMAL64));
     row.addDecimal(9, new BigDecimal(DecimalUtil.MAX_UNSCALED_DECIMAL128));
     row.addVarchar(10, "varchar bar");
-    row.addDate(11, new Date(0));
+    row.addDate(11, DateUtil.epochDaysToSqlDate(0));
     row.addBoolean(12, true);
     row.addFloat(13, 7.8f);
     row.addDouble(14, 9.9);
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java
index 417f096..d64503b 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java
@@ -577,7 +577,7 @@ public class TestPartialRow {
         partialRow.addDecimal(columnName, BigDecimal.valueOf(12345, 3));
         break;
       case DATE:
-        partialRow.addDate(columnName, new Date(0));
+        partialRow.addDate(columnName, DateUtil.epochDaysToSqlDate(0));
         break;
       default:
         throw new UnsupportedOperationException();
@@ -623,7 +623,7 @@ public class TestPartialRow {
         partialRow.addDecimal(columnIndex, BigDecimal.valueOf(12345, 3));
         break;
       case DATE:
-        partialRow.addDate(columnIndex, new Date(0));
+        partialRow.addDate(columnIndex, DateUtil.epochDaysToSqlDate(0));
         break;
       default:
         throw new UnsupportedOperationException();
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestRowResult.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestRowResult.java
index 6aa8910..8b8bf0c 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestRowResult.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestRowResult.java
@@ -37,6 +37,7 @@ import org.junit.Test;
 import org.apache.kudu.Schema;
 import org.apache.kudu.Type;
 import org.apache.kudu.test.KuduTestHarness;
+import org.apache.kudu.util.DateUtil;
 
 public class TestRowResult {
 
@@ -78,7 +79,7 @@ public class TestRowResult {
     row.addTimestamp(11, new Timestamp(11));
     row.addDecimal(12, BigDecimal.valueOf(12345, 3));
     row.addVarchar(13, "varcharval");
-    row.addDate(14, new Date(0));
+    row.addDate(14, DateUtil.epochDaysToSqlDate(0));
 
     KuduClient client = harness.getClient();
     KuduSession session = client.newSession();
@@ -157,9 +158,10 @@ public class TestRowResult {
       assertEquals("varcharval",
           rr.getVarchar(allTypesSchema.getColumnByIndex(13).getName()));
 
-      assertEquals(new Date(0), rr.getDate(14));
-      assertEquals(new Date(0), rr.getObject(14));
-      assertEquals(new Date(0), rr.getDate(allTypesSchema.getColumnByIndex(14).getName()));
+      assertEquals(DateUtil.epochDaysToSqlDate(0), rr.getDate(14));
+      assertEquals(DateUtil.epochDaysToSqlDate(0), rr.getObject(14));
+      assertEquals(DateUtil.epochDaysToSqlDate(0),
+          rr.getDate(allTypesSchema.getColumnByIndex(14).getName()));
 
       // We test with the column name once since it's the same method for all types, unlike
above.
       assertEquals(Type.INT8, rr.getColumnType(allTypesSchema.getColumnByIndex(0).getName()));
diff --git a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/ClientTestUtil.java b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/ClientTestUtil.java
index 1f21dcc..df6a59a 100644
--- a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/ClientTestUtil.java
+++ b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/ClientTestUtil.java
@@ -60,6 +60,7 @@ import org.apache.kudu.client.RowResult;
 import org.apache.kudu.client.RowResultIterator;
 import org.apache.kudu.client.Upsert;
 import org.apache.kudu.util.CharUtil;
+import org.apache.kudu.util.DateUtil;
 import org.apache.kudu.util.DecimalUtil;
 
 /**
@@ -238,7 +239,7 @@ public abstract class ClientTestUtil {
     row.addInt("int32", 44);
     row.addLong("int64", 45);
     row.addTimestamp("timestamp", new Timestamp(1234567890));
-    row.addDate("date", new Date(0));
+    row.addDate("date", DateUtil.epochDaysToSqlDate(0));
     row.addBoolean("bool", true);
     row.addFloat("float", 52.35F);
     row.addDouble("double", 53.35);


Mime
View raw message