[ 
https://issues.apache.org/jira/browse/PARQUET-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16424015#comment-16424015
 ] 

ASF GitHub Bot commented on PARQUET-1253:
-----------------------------------------

gszadovszky commented on a change in pull request #463: PARQUET-1253: Support 
for new logical type representation
URL: https://github.com/apache/parquet-mr/pull/463#discussion_r178799024
 
 

 ##########
 File path: 
parquet-column/src/main/java/org/apache/parquet/schema/LogicalTypeAnnotation.java
 ##########
 @@ -0,0 +1,748 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.schema;
+
+import org.apache.parquet.format.BsonType;
+import org.apache.parquet.format.ConvertedType;
+import org.apache.parquet.format.DateType;
+import org.apache.parquet.format.DecimalType;
+import org.apache.parquet.format.EnumType;
+import org.apache.parquet.format.IntType;
+import org.apache.parquet.format.JsonType;
+import org.apache.parquet.format.ListType;
+import org.apache.parquet.format.LogicalType;
+import org.apache.parquet.format.MapType;
+import org.apache.parquet.format.MicroSeconds;
+import org.apache.parquet.format.MilliSeconds;
+import org.apache.parquet.format.NullType;
+import org.apache.parquet.format.StringType;
+import org.apache.parquet.format.TimeType;
+import org.apache.parquet.format.TimestampType;
+
+import java.util.Objects;
+
+public interface LogicalTypeAnnotation {
+  /**
+   * Convert this parquet-mr logical type to parquet-format LogicalType.
+   *
+   * @return the parquet-format LogicalType representation of this logical 
type implementation
+   */
+  LogicalType toLogicalType();
+
+  /**
+   * Convert this parquet-mr logical type to parquet-format ConvertedType.
+   *
+   * @return the parquet-format ConvertedType representation of this logical 
type implementation
+   */
+  ConvertedType toConvertedType();
+
+  /**
+   * Convert this logical type to old logical type representation in 
parquet-mr (if there's any).
+   * Those logical type implementations, which don't have a corresponding 
mapping should return null.
+   *
+   * @return the OriginalType representation of the new logical type, or null 
if there's none
+   */
+  OriginalType toOriginalType();
+
+  /**
+   * Helper method to convert the old representation of logical types 
(OriginalType) to new logical type.
+   */
+  static LogicalTypeAnnotation fromOriginalType(OriginalType originalType) {
+    if (originalType == null) {
+      return null;
+    }
+    switch (originalType) {
+      case UTF8:
+        return StringLogicalTypeAnnotation.create();
+      case MAP:
+        return MapLogicalTypeAnnotation.create();
+      case DECIMAL:
+        return DecimalLogicalTypeAnnotation.create();
+      case LIST:
+        return ListLogicalTypeAnnotation.create();
+      case DATE:
+        return DateLogicalTypeAnnotation.create();
+      case INTERVAL:
+        return IntervalLogicalTypeAnnotation.create();
+      case TIMESTAMP_MILLIS:
+        return TimestampLogicalTypeAnnotation.create(true, 
LogicalTypeAnnotation.TimeUnit.MILLIS);
+      case TIMESTAMP_MICROS:
+        return TimestampLogicalTypeAnnotation.create(true, 
LogicalTypeAnnotation.TimeUnit.MICROS);
+      case TIME_MILLIS:
+        return TimeLogicalTypeAnnotation.create(true, 
LogicalTypeAnnotation.TimeUnit.MILLIS);
+      case TIME_MICROS:
+        return TimeLogicalTypeAnnotation.create(true, 
LogicalTypeAnnotation.TimeUnit.MICROS);
+      case UINT_8:
+        return IntLogicalTypeAnnotation.create((byte) 8, false);
+      case UINT_16:
+        return IntLogicalTypeAnnotation.create((byte) 16, false);
+      case UINT_32:
+        return IntLogicalTypeAnnotation.create((byte) 32, false);
+      case UINT_64:
+        return IntLogicalTypeAnnotation.create((byte) 64, false);
+      case INT_8:
+        return IntLogicalTypeAnnotation.create((byte) 8, true);
+      case INT_16:
+        return IntLogicalTypeAnnotation.create((byte) 16, true);
+      case INT_32:
+        return IntLogicalTypeAnnotation.create((byte) 32, true);
+      case INT_64:
+        return IntLogicalTypeAnnotation.create((byte) 64, true);
+      case ENUM:
+        return EnumLogicalTypeAnnotation.create();
+      case JSON:
+        return JsonLogicalTypeAnnotation.create();
+      case BSON:
+        return BsonLogicalTypeAnnotation.create();
+      case MAP_KEY_VALUE:
+        return MapKeyValueTypeAnnotation.create();
+      default:
+        return NullLogicalTypeAnnotation.create();
+    }
+  }
+
+  class StringLogicalTypeAnnotation implements LogicalTypeAnnotation {
+    private static final StringLogicalTypeAnnotation INSTANCE = new 
StringLogicalTypeAnnotation();
+
+    public static LogicalTypeAnnotation create() {
+      return INSTANCE;
+    }
+
+    private StringLogicalTypeAnnotation() {
+    }
+
+    @Override
+    public LogicalType toLogicalType() {
+      return LogicalType.STRING(new StringType());
+    }
+
+    @Override
+    public ConvertedType toConvertedType() {
+      return ConvertedType.UTF8;
+    }
+
+    @Override
+    public OriginalType toOriginalType() {
+      return OriginalType.UTF8;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      return obj instanceof StringLogicalTypeAnnotation;
+    }
+
+    @Override
+    public int hashCode() {
+      // This type doesn't have any parameters, thus use class hashcode
+      return getClass().hashCode();
+    }
+  }
+
+  class MapLogicalTypeAnnotation implements LogicalTypeAnnotation {
+    private static final MapLogicalTypeAnnotation INSTANCE = new 
MapLogicalTypeAnnotation();
+
+    public static LogicalTypeAnnotation create() {
+      return INSTANCE;
+    }
+
+    private MapLogicalTypeAnnotation() {
+    }
+
+    @Override
+    public LogicalType toLogicalType() {
+      return LogicalType.MAP(new MapType());
+    }
+
+    @Override
+    public ConvertedType toConvertedType() {
+      return ConvertedType.MAP;
+    }
+
+    @Override
+    public OriginalType toOriginalType() {
+      return OriginalType.MAP;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      return obj instanceof MapLogicalTypeAnnotation;
+    }
+
+    @Override
+    public int hashCode() {
+      // This type doesn't have any parameters, thus use class hashcode
+      return getClass().hashCode();
+    }
+  }
+
+  class ListLogicalTypeAnnotation implements LogicalTypeAnnotation {
+    private static final ListLogicalTypeAnnotation INSTANCE = new 
ListLogicalTypeAnnotation();
+
+    public static LogicalTypeAnnotation create() {
+      return INSTANCE;
+    }
+
+    private ListLogicalTypeAnnotation() {
+    }
+
+    @Override
+    public LogicalType toLogicalType() {
+      return LogicalType.LIST(new ListType());
+    }
+
+    @Override
+    public ConvertedType toConvertedType() {
+      return ConvertedType.LIST;
+    }
+
+    @Override
+    public OriginalType toOriginalType() {
+      return OriginalType.LIST;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      return obj instanceof ListLogicalTypeAnnotation;
+    }
+
+    @Override
+    public int hashCode() {
+      // This type doesn't have any parameters, thus use class hashcode
+      return getClass().hashCode();
+    }
+  }
+
+  class EnumLogicalTypeAnnotation implements LogicalTypeAnnotation {
+    private static final EnumLogicalTypeAnnotation INSTANCE = new 
EnumLogicalTypeAnnotation();
+
+    public static LogicalTypeAnnotation create() {
+      return INSTANCE;
+    }
+
+    private EnumLogicalTypeAnnotation() {
+    }
+
+    @Override
+    public LogicalType toLogicalType() {
+      return LogicalType.ENUM(new EnumType());
+    }
+
+    @Override
+    public ConvertedType toConvertedType() {
+      return ConvertedType.ENUM;
+    }
+
+    @Override
+    public OriginalType toOriginalType() {
+      return OriginalType.ENUM;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      return obj instanceof EnumLogicalTypeAnnotation;
+    }
+
+    @Override
+    public int hashCode() {
+      // This type doesn't have any parameters, thus use class hashcode
+      return getClass().hashCode();
+    }
+  }
+
+  class DecimalLogicalTypeAnnotation implements LogicalTypeAnnotation {
+
+    private int scale;
+    private int precision;
+
+    public static LogicalTypeAnnotation create() {
+      return new DecimalLogicalTypeAnnotation(0, 0);
+    }
+
+    public static LogicalTypeAnnotation create(int scale, int precision) {
+      return new DecimalLogicalTypeAnnotation(scale, precision);
+    }
+
+    private DecimalLogicalTypeAnnotation(int scale, int precision) {
+      this.scale = scale;
+      this.precision = precision;
+    }
+
+    public void setPrecision(int precision) {
 
 Review comment:
   I don't really like this type being mutable. Is it possible to initialize 
the scale/precision values at construction only somehow?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Support for new logical type representation
> -------------------------------------------
>
>                 Key: PARQUET-1253
>                 URL: https://issues.apache.org/jira/browse/PARQUET-1253
>             Project: Parquet
>          Issue Type: Improvement
>          Components: parquet-mr
>            Reporter: Nandor Kollar
>            Assignee: Nandor Kollar
>            Priority: Major
>
> Latest parquet-format 
> [introduced|https://github.com/apache/parquet-format/commit/863875e0be3237c6aa4ed71733d54c91a51deabe#diff-0f9d1b5347959e15259da7ba8f4b6252]
>  a new representation for logical types. As of now this is not yet supported 
> in parquet-mr, thus there's no way to use parametrized UTC normalized 
> timestamp data types. When reading and writing Parquet files, besides 
> 'converted_type' parquet-mr should use the new 'logicalType' field in 
> SchemaElement to tell the current logical type annotation. To maintain 
> backward compatibility, the semantic of converted_type shouldn't change.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to