parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ziva...@apache.org
Subject [parquet-mr] branch master updated: PARQUET-1452: Deprecate old logical types API (#535)
Date Wed, 07 Nov 2018 11:31:48 GMT
This is an automated email from the ASF dual-hosted git repository.

zivanfi 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 ca294f9  PARQUET-1452: Deprecate old logical types API (#535)
ca294f9 is described below

commit ca294f94a9908d25174648cd1c325a994af6a56d
Author: nandorKollar <nandorKollar@users.noreply.github.com>
AuthorDate: Wed Nov 7 12:31:43 2018 +0100

    PARQUET-1452: Deprecate old logical types API (#535)
---
 .../column/columnindex/BinaryTruncator.java        | 37 +++++++++++++++-------
 .../org/apache/parquet/schema/DecimalMetadata.java | 11 +++++--
 .../parquet/schema/LogicalTypeAnnotation.java      | 16 ++++++++++
 .../org/apache/parquet/schema/OriginalType.java    |  4 +++
 .../org/apache/parquet/schema/PrimitiveType.java   |  1 +
 5 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/BinaryTruncator.java
b/parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/BinaryTruncator.java
index bcc43fb..a301f67 100644
--- a/parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/BinaryTruncator.java
+++ b/parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/BinaryTruncator.java
@@ -25,9 +25,10 @@ import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
+import java.util.Optional;
 
 import org.apache.parquet.io.api.Binary;
-import org.apache.parquet.schema.OriginalType;
+import org.apache.parquet.schema.LogicalTypeAnnotation;
 import org.apache.parquet.schema.PrimitiveType;
 
 /**
@@ -184,19 +185,31 @@ abstract class BinaryTruncator {
         return NO_OP_TRUNCATOR;
       case BINARY:
       case FIXED_LEN_BYTE_ARRAY:
-        OriginalType originalType = type.getOriginalType();
-        if (originalType == null) {
+        LogicalTypeAnnotation logicalTypeAnnotation = type.getLogicalTypeAnnotation();
+        if (logicalTypeAnnotation == null) {
           return DEFAULT_UTF8_TRUNCATOR;
         }
-        switch (originalType) {
-          case UTF8:
-          case ENUM:
-          case JSON:
-          case BSON:
-            return DEFAULT_UTF8_TRUNCATOR;
-          default:
-            return NO_OP_TRUNCATOR;
-        }
+        return logicalTypeAnnotation.accept(new LogicalTypeAnnotation.LogicalTypeAnnotationVisitor<BinaryTruncator>()
{
+          @Override
+          public Optional<BinaryTruncator> visit(LogicalTypeAnnotation.StringLogicalTypeAnnotation
stringLogicalType) {
+            return Optional.of(DEFAULT_UTF8_TRUNCATOR);
+          }
+
+          @Override
+          public Optional<BinaryTruncator> visit(LogicalTypeAnnotation.EnumLogicalTypeAnnotation
enumLogicalType) {
+            return Optional.of(DEFAULT_UTF8_TRUNCATOR);
+          }
+
+          @Override
+          public Optional<BinaryTruncator> visit(LogicalTypeAnnotation.JsonLogicalTypeAnnotation
jsonLogicalType) {
+            return Optional.of(DEFAULT_UTF8_TRUNCATOR);
+          }
+
+          @Override
+          public Optional<BinaryTruncator> visit(LogicalTypeAnnotation.BsonLogicalTypeAnnotation
bsonLogicalType) {
+            return Optional.of(DEFAULT_UTF8_TRUNCATOR);
+          }
+        }).orElse(NO_OP_TRUNCATOR);
       default:
         throw new IllegalArgumentException("No truncator is available for the type: " + type);
     }
diff --git a/parquet-column/src/main/java/org/apache/parquet/schema/DecimalMetadata.java b/parquet-column/src/main/java/org/apache/parquet/schema/DecimalMetadata.java
index 446b956..df4c4f6 100644
--- a/parquet-column/src/main/java/org/apache/parquet/schema/DecimalMetadata.java
+++ b/parquet-column/src/main/java/org/apache/parquet/schema/DecimalMetadata.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
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,6 +18,11 @@
  */
 package org.apache.parquet.schema;
 
+/**
+ * @deprecated use {@link org.apache.parquet.schema.LogicalTypeAnnotation.DecimalLogicalTypeAnnotation}
+ * with proper precision and scale parameters instead
+ */
+@Deprecated
 public class DecimalMetadata {
   private final int precision;
   private final int scale;
diff --git a/parquet-column/src/main/java/org/apache/parquet/schema/LogicalTypeAnnotation.java
b/parquet-column/src/main/java/org/apache/parquet/schema/LogicalTypeAnnotation.java
index c1b7d99..5f61ed6 100644
--- a/parquet-column/src/main/java/org/apache/parquet/schema/LogicalTypeAnnotation.java
+++ b/parquet-column/src/main/java/org/apache/parquet/schema/LogicalTypeAnnotation.java
@@ -19,6 +19,7 @@
 package org.apache.parquet.schema;
 
 import org.apache.parquet.Preconditions;
+import org.apache.yetus.audience.InterfaceAudience;
 
 import java.util.Collections;
 import java.util.HashSet;
@@ -145,6 +146,7 @@ public abstract class LogicalTypeAnnotation {
    *
    * @return the OriginalType representation of the new logical type, or null if there's
none
    */
+  @InterfaceAudience.Private
   public abstract OriginalType toOriginalType();
 
   /**
@@ -179,6 +181,7 @@ public abstract class LogicalTypeAnnotation {
   /**
    * Helper method to convert the old representation of logical types (OriginalType) to new
logical type.
    */
+  @InterfaceAudience.Private
   public static LogicalTypeAnnotation fromOriginalType(OriginalType originalType, DecimalMetadata
decimalMetadata) {
     if (originalType == null) {
       return null;
@@ -290,6 +293,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.UTF8;
     }
@@ -328,6 +332,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.MAP;
     }
@@ -361,6 +366,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.LIST;
     }
@@ -394,6 +400,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.ENUM;
     }
@@ -445,6 +452,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.DECIMAL;
     }
@@ -497,6 +505,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.DATE;
     }
@@ -544,6 +553,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       switch (unit) {
         case MILLIS:
@@ -622,6 +632,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       switch (unit) {
         case MILLIS:
@@ -707,6 +718,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       switch (bitWidth) {
         case 8:
@@ -778,6 +790,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.JSON;
     }
@@ -816,6 +829,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.BSON;
     }
@@ -861,6 +875,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.INTERVAL;
     }
@@ -911,6 +926,7 @@ public abstract class LogicalTypeAnnotation {
     }
 
     @Override
+    @InterfaceAudience.Private
     public OriginalType toOriginalType() {
       return OriginalType.MAP_KEY_VALUE;
     }
diff --git a/parquet-column/src/main/java/org/apache/parquet/schema/OriginalType.java b/parquet-column/src/main/java/org/apache/parquet/schema/OriginalType.java
index 78421b3..6c27be3 100644
--- a/parquet-column/src/main/java/org/apache/parquet/schema/OriginalType.java
+++ b/parquet-column/src/main/java/org/apache/parquet/schema/OriginalType.java
@@ -18,6 +18,10 @@
  */
 package org.apache.parquet.schema;
 
+/**
+ * @deprecated use {@link LogicalTypeAnnotation} to represent logical types instead
+ */
+@Deprecated
 public enum OriginalType {
   MAP,
   LIST,
diff --git a/parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveType.java b/parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveType.java
index 6a7382e..9ab53b2 100644
--- a/parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveType.java
+++ b/parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveType.java
@@ -575,6 +575,7 @@ public final class PrimitiveType extends Type {
   /**
    * @return the decimal type metadata
    */
+  @Deprecated
   public DecimalMetadata getDecimalMetadata() {
     return decimalMeta;
   }


Mime
View raw message