You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/03/03 18:25:54 UTC

[GitHub] [pinot] richardstartin commented on a change in pull request #7358: [issue-7357] Add support for Avro logical types in realtime ingestion

richardstartin commented on a change in pull request #7358:
URL: https://github.com/apache/pinot/pull/7358#discussion_r818946683



##########
File path: pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroLogicalTypeConversionRegistry.java
##########
@@ -0,0 +1,58 @@
+/**
+ * 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.pinot.plugin.inputformat.avro;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.avro.Conversion;
+import org.apache.avro.Conversions;
+import org.apache.avro.data.TimeConversions;
+
+public final class AvroLogicalTypeConversionRegistry {
+  /*
+   * These constants are copied from org.apache.avro.LogicalTypes
+   */
+  private static final String DECIMAL = "decimal";
+  private static final String UUID = "uuid";
+  private static final String DATE = "date";
+  private static final String TIME_MILLIS = "time-millis";
+  private static final String TIME_MICROS = "time-micros";
+  private static final String TIMESTAMP_MILLIS = "timestamp-millis";
+  private static final String TIMESTAMP_MICROS = "timestamp-micros";
+  private static final Map<String, Conversion<?>> CONVERSION_MAP = new HashMap<>();
+
+  private AvroLogicalTypeConversionRegistry() {
+  }
+
+  public static Conversion<?> findConversionFor(String typeName) {
+    return CONVERSION_MAP.get(typeName);
+  }
+
+  static {
+    synchronized (CONVERSION_MAP) {
+      CONVERSION_MAP.put(DECIMAL, new Conversions.DecimalConversion());
+      CONVERSION_MAP.put(UUID, new Conversions.UUIDConversion());
+      CONVERSION_MAP.put(DATE, new TimeConversions.DateConversion());
+      CONVERSION_MAP.put(TIME_MILLIS, new TimeConversions.TimeMillisConversion());
+      CONVERSION_MAP.put(TIME_MICROS, new TimeConversions.TimeMicrosConversion());
+      CONVERSION_MAP.put(TIMESTAMP_MILLIS, new TimeConversions.TimestampMillisConversion());
+      CONVERSION_MAP.put(TIMESTAMP_MICROS, new TimeConversions.TimestampMicrosConversion());
+    }
+  }

Review comment:
       This doesn't need to be synchronised because static initialisers can only be invoked once per class loader, and if you look at the bytecode you'll notice a synthetic method called `<clinit>` in which `CONVERSION_MAP` is initialised, along with the block of code here.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org