parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [parquet-mr] branch master updated: PARQUET-1344: Type builders don't honor new logical types (#500)
Date Wed, 04 Jul 2018 11:58:36 GMT
This is an automated email from the ASF dual-hosted git repository.

gabor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git


The following commit(s) were added to refs/heads/master by this push:
     new 94ae6c8  PARQUET-1344: Type builders don't honor new logical types (#500)
94ae6c8 is described below

commit 94ae6c84d22ed33e158b3cc822ca4a0484c829c9
Author: nandorKollar <nandorKollar@users.noreply.github.com>
AuthorDate: Wed Jul 4 13:58:33 2018 +0200

    PARQUET-1344: Type builders don't honor new logical types (#500)
    
    * PARQUET-1344: Type builders don't honor new logical types
    
    Call propert constructor when builder is caller with new logical type,
    call the deprecated OriginalType version otherwise.
    
    * Use static imports in test
---
 .../main/java/org/apache/parquet/schema/Types.java | 12 +++++++--
 .../apache/parquet/schema/TestTypeBuilders.java    | 29 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/parquet-column/src/main/java/org/apache/parquet/schema/Types.java b/parquet-column/src/main/java/org/apache/parquet/schema/Types.java
index 54fb1d8..165a5ac 100644
--- a/parquet-column/src/main/java/org/apache/parquet/schema/Types.java
+++ b/parquet-column/src/main/java/org/apache/parquet/schema/Types.java
@@ -514,7 +514,11 @@ public class Types {
         }
       }
 
-      return new PrimitiveType(repetition, primitiveType, length, name, getOriginalType(),
meta, id, columnOrder);
+      if (newLogicalTypeSet) {
+        return new PrimitiveType(repetition, primitiveType, length, name, logicalTypeAnnotation,
id, columnOrder);
+      } else {
+        return new PrimitiveType(repetition, primitiveType, length, name, getOriginalType(),
meta, id, columnOrder);
+      }
     }
 
     private static long maxPrecision(int numBytes) {
@@ -702,7 +706,11 @@ public class Types {
 
     @Override
     protected GroupType build(String name) {
-      return new GroupType(repetition, name, getOriginalType(), fields, id);
+      if (newLogicalTypeSet) {
+        return new GroupType(repetition, name, logicalTypeAnnotation, fields, id);
+      } else {
+        return new GroupType(repetition, name, getOriginalType(), fields, id);
+      }
     }
 
     public MapBuilder<THIS> map(
diff --git a/parquet-column/src/test/java/org/apache/parquet/schema/TestTypeBuilders.java
b/parquet-column/src/test/java/org/apache/parquet/schema/TestTypeBuilders.java
index a42e9e3..82e58ef 100644
--- a/parquet-column/src/test/java/org/apache/parquet/schema/TestTypeBuilders.java
+++ b/parquet-column/src/test/java/org/apache/parquet/schema/TestTypeBuilders.java
@@ -26,6 +26,9 @@ import org.junit.Test;
 import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName;
 import org.apache.parquet.schema.Type.Repetition;
 
+import static org.apache.parquet.schema.LogicalTypeAnnotation.TimeUnit.MICROS;
+import static org.apache.parquet.schema.LogicalTypeAnnotation.TimeUnit.MILLIS;
+import static org.apache.parquet.schema.LogicalTypeAnnotation.timestampType;
 import static org.apache.parquet.schema.OriginalType.*;
 import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.*;
 import static org.apache.parquet.schema.Type.Repetition.*;
@@ -1423,6 +1426,32 @@ public class TestTypeBuilders {
     Assert.assertEquals(expected, actual);
   }
 
+  @Test
+  public void testTimestampLogicalTypeWithUTCParameter() {
+    PrimitiveType utcMillisExpected = new PrimitiveType(REQUIRED, INT64, "aTimestamp",
+      timestampType(true, MILLIS));
+    PrimitiveType nonUtcMillisExpected = new PrimitiveType(REQUIRED, INT64, "aTimestamp",
+      timestampType(false, MILLIS));
+    PrimitiveType utcMicrosExpected = new PrimitiveType(REQUIRED, INT64, "aTimestamp",
+      timestampType(true, MICROS));
+    PrimitiveType nonUtcMicrosExpected = new PrimitiveType(REQUIRED, INT64, "aTimestamp",
+      timestampType(false, MICROS));
+
+    PrimitiveType utcMillisActual = Types.required(INT64)
+      .as(timestampType(true, MILLIS)).named("aTimestamp");
+    PrimitiveType nonUtcMillisActual = Types.required(INT64)
+      .as(timestampType(false, MILLIS)).named("aTimestamp");
+    PrimitiveType utcMicrosActual = Types.required(INT64)
+      .as(timestampType(true, MICROS)).named("aTimestamp");
+    PrimitiveType nonUtcMicrosActual = Types.required(INT64)
+      .as(timestampType(false, MICROS)).named("aTimestamp");
+
+    Assert.assertEquals(utcMillisExpected, utcMillisActual);
+    Assert.assertEquals(nonUtcMillisExpected, nonUtcMillisActual);
+    Assert.assertEquals(utcMicrosExpected, utcMicrosActual);
+    Assert.assertEquals(nonUtcMicrosExpected, nonUtcMicrosActual);
+  }
+
   @Test(expected = IllegalArgumentException.class)
   public void testDecimalLogicalTypeWithDeprecatedScaleMismatch() {
     Types.required(BINARY)


Mime
View raw message