You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by jl...@apache.org on 2020/09/11 17:44:30 UTC

[incubator-pinot] branch fix-AvroRecordExtractor updated (f4add59 -> bfb5954)

This is an automated email from the ASF dual-hosted git repository.

jlli pushed a change to branch fix-AvroRecordExtractor
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git.


 discard f4add59  Fix extract method in AvroRecordExtractor
     new bfb5954  Fix extract method in AvroRecordExtractor

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (f4add59)
            \
             N -- N -- N   refs/heads/fix-AvroRecordExtractor (bfb5954)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java   | 2 --
 1 file changed, 2 deletions(-)


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


[incubator-pinot] 01/01: Fix extract method in AvroRecordExtractor

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jlli pushed a commit to branch fix-AvroRecordExtractor
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit bfb59545cdd13e94f34c882be579afd917fbdd80
Author: Jack Li(Analytics Engineering) <jl...@jlli-mn1.linkedin.biz>
AuthorDate: Fri Sep 11 10:33:09 2020 -0700

    Fix extract method in AvroRecordExtractor
---
 .../plugin/inputformat/avro/AvroRecordExtractor.java    | 17 ++++++++---------
 .../main/java/org/apache/pinot/spi/utils/JsonUtils.java | 13 -------------
 2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java b/pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java
index 339ab67..ede8586 100644
--- a/pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java
+++ b/pinot-plugins/pinot-input-format/pinot-avro-base/src/main/java/org/apache/pinot/plugin/inputformat/avro/AvroRecordExtractor.java
@@ -18,14 +18,14 @@
  */
 package org.apache.pinot.plugin.inputformat.avro;
 
-import java.util.Map;
+import java.util.List;
 import java.util.Set;
 import javax.annotation.Nullable;
+import org.apache.avro.Schema;
 import org.apache.avro.generic.GenericRecord;
 import org.apache.pinot.spi.data.readers.GenericRow;
 import org.apache.pinot.spi.data.readers.RecordExtractor;
 import org.apache.pinot.spi.data.readers.RecordExtractorConfig;
-import org.apache.pinot.spi.utils.JsonUtils;
 
 
 /**
@@ -46,14 +46,13 @@ public class AvroRecordExtractor implements RecordExtractor<GenericRecord> {
   @Override
   public GenericRow extract(GenericRecord from, GenericRow to) {
     if (_extractAll) {
-      Map<String, Object> jsonMap = JsonUtils.genericRecordToJson(from);
-      jsonMap.forEach((fieldName, value) -> to.putValue(fieldName, AvroUtils.convert(value)));
+      List<Schema.Field> fields = from.getSchema().getFields();
+      fields.forEach(field -> {
+        String fieldName = field.name();
+        to.putValue(fieldName, AvroUtils.convert(from.get(fieldName)));
+      });
     } else {
-      for (String fieldName : _fields) {
-        Object value = from.get(fieldName);
-        Object convertedValue = AvroUtils.convert(value);
-        to.putValue(fieldName, convertedValue);
-      }
+      _fields.forEach(fieldName -> to.putValue(fieldName, AvroUtils.convert(from.get(fieldName))));
     }
     return to;
   }
diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java
index f5bf9d3..419b5ce 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java
@@ -193,17 +193,4 @@ public class JsonUtils {
         throw new IllegalArgumentException(String.format("Unsupported data type %s", dataType));
     }
   }
-
-  /**
-   * Converts from a GenericRecord to a json map
-   */
-  public static Map<String, Object> genericRecordToJson(GenericRecord genericRecord) {
-    try {
-      String jsonString = genericRecord.toString();
-      return DEFAULT_MAPPER.readValue(jsonString, new TypeReference<Map<String, Object>>() {
-      });
-    } catch (IOException e) {
-      throw new IllegalStateException("Caught exception when converting generic record " + genericRecord + " to JSON");
-    }
-  }
 }


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