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


##########
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:
   > and use the Pulsar MessageId field to directly extract the full original 
Message from Pulsar to get the full object
   
   Why is MessageId needed to extract the original pulsar message? And when you 
say "original message", are you referring to the value in the pulsar message or 
the whole payload (includes key, value and headers) ? 
   
   >  I've switched everything over to use the the JDK implementation. 
   👍 
   
   >  that is only when the data size approaches 1kb, which I think is highly 
unlikely for these fields (schema version, ordering key, MessageId).
   
   It's typically the ingestion rate rather than the payload size that can 
cause a performance or throughput degradation. Moreover, in the current stream 
consumer contract, it is expected to consume raw bytes and de-serialization 
happens in the stream decoder. Hence, adding any extra decode operation is 
considered as an overhead for pure ingestion . 
   
   As of today, the record metadata extractor is in the consumer layer and 
hence, the recommendation to avoid any unnecessary overhead. Going forward, we 
should delegate all payload extraction (key/value/headers) into the decoder 
stage. We are not there yet. :) 
   
   > 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?
   
   We don't have any standard pinot benchmarks yet. That will be a good thing 
to have and we are open to suggestions. :) 
   
   



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