[
https://issues.apache.org/jira/browse/PARQUET-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16445581#comment-16445581
]
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_r183008754
##########
File path:
parquet-column/src/main/java/org/apache/parquet/schema/LogicalTypeAnnotation.java
##########
@@ -0,0 +1,714 @@
+/*
+ * 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,
DecimalMetadata decimalMetadata) {
+ if (originalType == null) {
+ return null;
+ }
+ switch (originalType) {
+ case UTF8:
+ return StringLogicalTypeAnnotation.create();
+ case MAP:
+ return MapLogicalTypeAnnotation.create();
+ case DECIMAL:
+ int scale = (decimalMetadata == null ? 0 : decimalMetadata.getScale());
+ int precision = (decimalMetadata == null ? 0 :
decimalMetadata.getPrecision());
+ return DecimalLogicalTypeAnnotation.create(scale, precision);
+ 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:
+ throw new RuntimeException("Can't convert original type to logical
type, unknown original type " + originalType);
+ }
+ }
+
+ class StringLogicalTypeAnnotation implements LogicalTypeAnnotation {
+ private static final StringLogicalTypeAnnotation INSTANCE = new
StringLogicalTypeAnnotation();
+
+ public static LogicalTypeAnnotation create() {
Review comment:
I don't really like the pattern how the client has to write the whole
classnames of the specialized `LogicalTypeAnnotataion` implementations to
create one. What do you think about having named static factory methods one
level up instead?
For example instead of calling
`LogicalTypeAnnotation.StringLogicalTypeAnnotation.create()` you might call
`LogicalTypeAnnotation.string()` or more simply `string()` if static import is
used.
----------------------------------------------------------------
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)