JeffBolle commented on code in PR #10995:
URL: https://github.com/apache/pinot/pull/10995#discussion_r1258293030


##########
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarMetadataExtractor.java:
##########
@@ -0,0 +1,124 @@
+/**
+ * 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.stream.pulsar;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.RowMetadata;
+import org.apache.pulsar.client.api.Message;
+
+
+public interface PulsarMetadataExtractor {
+  static PulsarMetadataExtractor build(boolean populateMetadata, boolean 
setRecordTimeFromEventTime) {
+    return message -> {
+      long eventTime = message.getEventTime();
+      long publishTime = message.getPublishTime();
+      long recordTimestamp = setRecordTimeFromEventTime ? eventTime : 
publishTime;
+
+      Map<String, String> metadataMap = populateMetadataMap(populateMetadata, 
message);
+
+      if (!populateMetadata) {
+        return new PulsarStreamMessageMetadata(recordTimestamp, null, 
metadataMap);
+      }
+      GenericRow headerGenericRow = buildGenericRow(message);
+      return new PulsarStreamMessageMetadata(recordTimestamp, 
headerGenericRow, metadataMap);
+    };
+  }
+
+  RowMetadata extract(Message<?> record);
+
+  static GenericRow buildGenericRow(Message<?> message) {
+    if (MapUtils.isEmpty(message.getProperties())) {
+      return null;
+    }
+    GenericRow genericRow = new GenericRow();
+    for (Map.Entry<String, String> entry : message.getProperties().entrySet()) 
{
+      genericRow.putValue(entry.getKey(), entry.getValue());
+    }
+    return genericRow;
+  }
+
+  static Map<String, String> populateMetadataMap(boolean populateAllFields, 
Message<?> message) {

Review Comment:
   With respect to Pulsar, the use-case we are using this for is to directly 
query from Pulsar the full protobuf object that was indexed. Pinot's flat table 
structure requires us to lose a lot of the structure we have in our native 
objects during indexing.  We don't generally need to search over all of the 
fields in an object, so we are planning to build indexes around the fields we 
search on, and use the Pulsar MessageId field to directly extract the full 
original Message from Pulsar to get the full object.
   
   With respect to performance, the fields are already parsed, and in most 
cases we are doing a blank or empty check and then setting a value in a Map. 
Not likely the slowest operations in the message ingest process.
   
   I researched base64 encoding performance and saw some research that there 
was a substantial performance difference between Apache Commons and the JDK 
Base64 implementations 
(https://dkomanov.medium.com/base64-encoding-performance-jdk-vs-apache-commons-3fb83323414b).
 I've switched everything over to use the the JDK implementation. It appears 
that given the size of the fields we are talking about, we are in the realm of 
a few thousand nanos, and that is only when the data size approaches 1kb, which 
I think is highly unlikely for these fields (schema version, ordering key, 
MessageId). 
   
   I'd rather not guess at performance implications. Are there some standard 
pinot benchmarks I can run to get some data on the performance impacts of the 
metadata changes? 
   



-- 
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]

Reply via email to