Jackie-Jiang commented on code in PR #7358:
URL: https://github.com/apache/pinot/pull/7358#discussion_r847650708
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java:
##########
@@ -31,16 +34,19 @@
import org.apache.pinot.spi.data.readers.GenericRow;
import org.apache.pinot.spi.data.readers.RecordExtractorConfig;
-
-/**
- * Extractor for Avro Records
- */
+/** Extractor for Avro Records */
Review Comment:
(format) Is this auto-formatted? We usually keep the javadoc multi lines
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroSchemaUtil.java:
##########
@@ -61,9 +91,7 @@ public static DataType valueOf(Schema.Type avroType) {
}
}
- /**
- * @return if the given avro type is a primitive type.
- */
+ /** @return if the given avro type is a primitive type. */
Review Comment:
(format) We usually keep the javadoc multi lines
##########
pinot-spi/src/main/java/org/apache/pinot/spi/data/readers/RecordExtractorConfig.java:
##########
@@ -18,8 +18,13 @@
*/
package org.apache.pinot.spi.data.readers;
+import java.util.Map;
+import javax.annotation.Nonnull;
+
+
/**
* Interface for configs of {@link RecordExtractor}
*/
public interface RecordExtractorConfig {
+ default void init(@Nonnull Map<String, String> props) { }
Review Comment:
(convention) We don't usually annotate `non-null`, but only annotate
`nullable`. Also make it multiple lines
```suggestion
default void init(Map<String, String> props) {
}
```
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java:
##########
@@ -107,4 +120,23 @@ protected Object convertRecord(Object value) {
}
return convertedMap;
}
+
+ /**
+ * This method convert any Avro logical-type converted (or not) value to a
class supported by
+ * Pinot {@link GenericRow}
+ */
+ @Override
+ protected Object convertSingleValue(Object value) {
+ if (value instanceof BigDecimal) {
+ return Double.valueOf(((BigDecimal) value).doubleValue());
+ }
+ if (value instanceof LocalDate) {
+ return Long.valueOf(((LocalDate) value).toEpochDay());
+ }
+ if (value instanceof Instant) {
+ return Long.valueOf(((Instant) value).toEpochMilli());
+ }
Review Comment:
(minor) Can be simplified
```suggestion
if (value instanceof BigDecimal) {
return ((BigDecimal) value).doubleValue();
}
if (value instanceof LocalDate) {
return ((LocalDate) value).toEpochDay();
}
if (value instanceof Instant) {
return ((Instant) value).toEpochMilli();
}
```
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/test/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordReaderTest.java:
##########
@@ -39,7 +39,7 @@ public class AvroRecordReaderTest extends
AbstractRecordReaderTest {
protected RecordReader createRecordReader()
throws Exception {
AvroRecordReader avroRecordReader = new AvroRecordReader();
- avroRecordReader.init(_dataFile, _sourceFields, null);
+ avroRecordReader.init(_dataFile, _sourceFields, new
AvroRecordReaderConfig());
Review Comment:
We don't need to change this (also want to test the behavior of passing
`null`)
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java:
##########
@@ -31,16 +34,19 @@
import org.apache.pinot.spi.data.readers.GenericRow;
import org.apache.pinot.spi.data.readers.RecordExtractorConfig;
-
-/**
- * Extractor for Avro Records
- */
+/** Extractor for Avro Records */
public class AvroRecordExtractor extends BaseRecordExtractor<GenericRecord> {
private Set<String> _fields;
private boolean _extractAll = false;
+ private boolean _applyLogicalTypes;
@Override
- public void init(@Nullable Set<String> fields, @Nullable
RecordExtractorConfig recordExtractorConfig) {
+ public void init(
+ @Nullable Set<String> fields, @Nullable RecordExtractorConfig
recordExtractorConfig) {
Review Comment:
(format) This change does not follow the [Pinot
Style](https://docs.pinot.apache.org/developers/developers-and-contributors/code-setup#intellij)
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractorConfig.java:
##########
@@ -0,0 +1,43 @@
+/**
+ * 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.Map;
+import org.apache.pinot.spi.data.readers.RecordExtractorConfig;
+
+
+/**
+ * Config for {@link AvroRecordExtractor}
+ */
+public class AvroRecordExtractorConfig implements RecordExtractorConfig {
+ private boolean _enableLogicalTypes = false;
+
+ @Override
+ public void init(Map<String, String> props) {
+ _enableLogicalTypes =
Boolean.valueOf(props.getOrDefault("enableLogicalTypes",
Boolean.FALSE.toString()));
Review Comment:
```suggestion
_enableLogicalTypes =
Boolean.parseBoolean(props.get("enableLogicalTypes"));
```
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroSchemaUtil.java:
##########
@@ -20,19 +20,49 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.avro.Conversion;
+import org.apache.avro.Conversions;
+import org.apache.avro.LogicalType;
+import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
+import org.apache.avro.data.TimeConversions;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.utils.JsonUtils;
-
public class AvroSchemaUtil {
+ /*
+ * 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 AvroSchemaUtil() {
}
- /**
- * Returns the data type stored in Pinot that is associated with the given
Avro type.
- */
+ public static Conversion<?> findConversionFor(String typeName) {
+ return CONVERSION_MAP.get(typeName);
+ }
+
+ static {
+ 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());
+ }
+
+ /** Returns the data type stored in Pinot that is associated with the given
Avro type. */
Review Comment:
(format) We usually keep the javadoc multi lines
##########
pinot-plugins/pinot-input-format/pinot-avro-base/src/test/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordToPinotRowGeneratorTest.java:
##########
@@ -44,7 +44,7 @@ public void testIncomingTimeColumn()
Set<String> sourceFields = Sets.newHashSet("incomingTime", "outgoingTime");
AvroRecordExtractor avroRecordExtractor = new AvroRecordExtractor();
- avroRecordExtractor.init(sourceFields, null);
+ avroRecordExtractor.init(sourceFields, new AvroRecordExtractorConfig());
Review Comment:
We don't need to change this (also want to test the behavior of passing
`null`)
##########
pinot-plugins/pinot-input-format/pinot-confluent-avro/src/main/java/org/apache/pinot/plugin/inputformat/avro/confluent/KafkaConfluentSchemaRegistryAvroMessageDecoder.java:
##########
@@ -94,8 +95,10 @@ public void init(Map<String, String> props, Set<String>
fieldsToRead, String top
_deserializer = new KafkaAvroDeserializer(schemaRegistryClient);
Preconditions.checkNotNull(topicName, "Topic must be provided");
_topicName = topicName;
+ AvroRecordExtractorConfig config =
PluginManager.get().createInstance(AvroRecordExtractorConfig.class.getName());
Review Comment:
```suggestion
AvroRecordExtractorConfig config = new AvroRecordExtractorConfig();
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]