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/08/16 22:41:24 UTC

[GitHub] [pinot] navina opened a new pull request, #9224: Extract record keys, headers and metadata from Stream sources

navina opened a new pull request, #9224:
URL: https://github.com/apache/pinot/pull/9224

   This is an extension of PR #9096 
   
   Most stream systems provide a message envelope, which encapsulates the record payload, along with record headers, keys and other system-specific metadata  For e.g:
   1. Kafka allows keyed records and additionally, provides headers 
   2. Kinesis requires keyed records and includes some additional metadata such as sequenceId etc 
   3. Pulsar also supports keyed records and allows including arbitrary properties. 
   4. Pubsub supports keyed messages, along with user-defined attributes and message metadata. 
   
   Today, Pinot drops everything from the payload, other than the record value itself. Hence, there needs to be a way to extract these values and present them in the Pinot table as regular columns (of course, it has to be defined in the pinot schema). 
   
   This PR attempts to extract key, header and other metadata from any supported streaming connector. This can be very useful for the Pinot user as they don't have to "pre-process" the stream to make the record metadata available in the data payload. It also prevents custom solutions (such as [this](https://github.com/startreedata/startree-pinot/pull/484/files)).
   
   For Reviewers, please note:
   1. In the current patch, the record key (when available) is extracted as `__key` column , where as headers are extracted as `header$<HEADER_KEY_NAME>` . Does this sound like a good convention to follow for all stream connectors  -> Header columns will always be prefixed with `header$` and any other metadata such as key or offset will be prefixed as `__`
   2. I am in the process of adding some unit tests. I have tested with a pinot realtime quickstart. Need to do some more cleanup. 
   3. In `MessageBatch`, I have marked one of the methods as `@Deprecated` as I am hoping to eventually eliminate the need for typed interface there. The current changes are backwards compatible. Let me know if there is a better way. 
   


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


[GitHub] [pinot] mcvsubbu commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980631968


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   The API will be used by folks writing plugins for a new stream.  Imagine if you are writing a new stream, and need to implement getRecordTimeStamp() but your stream does not provide any field called RecordTimeStamp (but provides other ways to get the ingestion time).
   
   And hence my suggestion.
   
   I will let you decide.



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


[GitHub] [pinot] npawar commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
npawar commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971435459


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamMessageMetadata.java:
##########
@@ -18,26 +18,38 @@
  */
 package org.apache.pinot.spi.stream;
 
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
 /**
  * A class that provides metadata associated with the message of a stream, for e.g.,

Review Comment:
   this is a little confusing, since the design doc called out headers and metadata separately, but here we're creating a StreamMessageMetadata object that contains metadata and headers. We should at least update the javadoc if we're going with putting these 2 together in this class



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   is RowMetadata interface needed? There doesnt seem to be much value add between RowMetadata and StreamMessageMetadata, and it's a bit confusing to have both. RowMetadata is also under stream package, so it cannot really be the metadata for anything else



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderImpl.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.spi.stream;
+
+import java.util.Map;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class StreamDataDecoderImpl implements StreamDataDecoder {
+  private static final String KEY = "__key";
+  private static final String HEADER_KEY_PREFIX = "header$";
+  private static final Logger LOGGER = LoggerFactory.getLogger(StreamDataDecoderImpl.class);
+
+  private final StreamMessageDecoder _valueDecoder;
+
+  // Maybe simplify by allowing only string keys ?
+  public StreamDataDecoderImpl(StreamMessageDecoder valueDecoder) {
+    _valueDecoder = valueDecoder;
+  }
+
+  @Override
+  public StreamDataDecoderResult decode(StreamMessage message) {
+    assert message.getValue() != null;
+
+    try {
+      GenericRow row = _valueDecoder.decode(message.getValue(), 0, message.getValue().length, new GenericRow());

Review Comment:
   we used to use the variant where we could pass in a reuse GenericRow, can we keep that?



##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaPartitionLevelConsumer.java:
##########
@@ -43,30 +45,36 @@ public KafkaPartitionLevelConsumer(String clientId, StreamConfig streamConfig, i
   }
 
   @Override
-  public MessageBatch<byte[]> fetchMessages(StreamPartitionMsgOffset startMsgOffset,
+  public MessageBatch<KafkaStreamMessage> fetchMessages(StreamPartitionMsgOffset startMsgOffset,
       StreamPartitionMsgOffset endMsgOffset, int timeoutMillis) {
     final long startOffset = ((LongMsgOffset) startMsgOffset).getOffset();
     final long endOffset = endMsgOffset == null ? Long.MAX_VALUE : ((LongMsgOffset) endMsgOffset).getOffset();
     return fetchMessages(startOffset, endOffset, timeoutMillis);
   }
 
-  public MessageBatch<byte[]> fetchMessages(long startOffset, long endOffset, int timeoutMillis) {
+  public MessageBatch<KafkaStreamMessage> fetchMessages(long startOffset, long endOffset, int timeoutMillis) {
     if (LOGGER.isDebugEnabled()) {
       LOGGER.debug("poll consumer: {}, startOffset: {}, endOffset:{} timeout: {}ms", _topicPartition, startOffset,
           endOffset, timeoutMillis);
     }
     _consumer.seek(_topicPartition, startOffset);
     ConsumerRecords<String, Bytes> consumerRecords = _consumer.poll(Duration.ofMillis(timeoutMillis));
     List<ConsumerRecord<String, Bytes>> messageAndOffsets = consumerRecords.records(_topicPartition);
-    List<MessageAndOffsetAndMetadata> filtered = new ArrayList<>(messageAndOffsets.size());
+    List<KafkaStreamMessage> filtered = new ArrayList<>(messageAndOffsets.size());
     long lastOffset = startOffset;
     for (ConsumerRecord<String, Bytes> messageAndOffset : messageAndOffsets) {
+      String key = messageAndOffset.key();
+      byte[] keyBytes = key == null ? null : key.getBytes(StandardCharsets.UTF_8);
       Bytes message = messageAndOffset.value();
       long offset = messageAndOffset.offset();
       if (offset >= startOffset & (endOffset > offset | endOffset == -1)) {
         if (message != null) {
+          StreamMessageMetadata rowMetadata = null;
+          if (_config.isPopulateMetadata()) {
+            rowMetadata = (StreamMessageMetadata) _rowMetadataExtractor.extract(messageAndOffset);
+          }
           filtered.add(
-              new MessageAndOffsetAndMetadata(message.get(), offset, _rowMetadataExtractor.extract(messageAndOffset)));
+              new KafkaStreamMessage(keyBytes, message.get(), offset, rowMetadata));

Review Comment:
   why do we treat offset as special case, instead of within the rowMetadataExtractor?



##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaStreamMessage.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.kafka20;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.StreamMessage;
+import org.apache.pinot.spi.stream.StreamMessageMetadata;
+
+
+public class KafkaStreamMessage extends StreamMessage {
+  private static final GenericRow EMPTY_ROW_REUSE = new GenericRow();
+
+  // should distinguish stream-specific record metadata in the table??
+  private final long _offset;

Review Comment:
   wouldn't this be part of StreamMessageMetadata within the KafkaStreamMessage?



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderResult.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.spi.stream;
+
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
+/**
+ * A container class for holding the result of a decoder
+ * At any point in time, only one of Result or exception is set as null.
+ */
+public final class StreamDataDecoderResult {
+  private final GenericRow _result;
+  private final Exception _exception;
+
+  public StreamDataDecoderResult(GenericRow result, Exception exception) {
+    _result = result;
+    _exception = exception;
+  }
+
+  public GenericRow getResult() {

Review Comment:
   Mark them both as Nullable



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderImpl.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.spi.stream;
+
+import java.util.Map;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class StreamDataDecoderImpl implements StreamDataDecoder {
+  private static final String KEY = "__key";
+  private static final String HEADER_KEY_PREFIX = "header$";
+  private static final Logger LOGGER = LoggerFactory.getLogger(StreamDataDecoderImpl.class);
+
+  private final StreamMessageDecoder _valueDecoder;
+
+  // Maybe simplify by allowing only string keys ?
+  public StreamDataDecoderImpl(StreamMessageDecoder valueDecoder) {
+    _valueDecoder = valueDecoder;
+  }
+
+  @Override
+  public StreamDataDecoderResult decode(StreamMessage message) {
+    assert message.getValue() != null;
+
+    try {
+      GenericRow row = _valueDecoder.decode(message.getValue(), 0, message.getValue().length, new GenericRow());
+      if (row != null) {
+        if (message.getKey() != null) {
+          row.putValue(KEY, message.getKey());
+        }
+        RowMetadata metadata = message.getMetadata();

Review Comment:
   won't thsi be the right place to also extract and add the other metadata fields? seems we only do key, value, headers here



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/RealtimeClusterIntegrationTest.java:
##########
@@ -76,6 +76,8 @@ public void setUp()
 
     // Wait for all documents loaded
     waitForAllDocsLoaded(600_000L);
+
+    Thread.currentThread().join();

Review Comment:
   remove before merging?



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r973939545


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   I tried to remove `RowMetadata`. But it looks like it is being passed around in other interfaces like `MutableSegment` .  
   
   I think it is fine to leave the interface as it will be convenient to include in other interface APIs and also, possibly extend it. I am wondering if there is a lot of value in distinguishing `RowMetadata` from a `StreamMessage`'s metadata. 
   
   `RowMetadata` can refer to Pinot related row metadata (Ex. time at which a record was indexed in Pinot) . Where as, `StreamMessageMetadata` continues to simply hold the incoming record related metadata (ex. when record was ingested into upstream etc).  Wdyt @npawar ?



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r974134696


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamMessageMetadata.java:
##########
@@ -18,26 +18,38 @@
  */
 package org.apache.pinot.spi.stream;
 
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
 /**
  * A class that provides metadata associated with the message of a stream, for e.g.,

Review Comment:
   Separated the metadata and headers in `StreamMessageMetadata` into 2 separate fields.



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


[GitHub] [pinot] codecov-commenter commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1218743695

   # [Codecov](https://codecov.io/gh/apache/pinot/pull/9224?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#9224](https://codecov.io/gh/apache/pinot/pull/9224?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b2f08b7) into [master](https://codecov.io/gh/apache/pinot/commit/3a655d2d0e86cf208a1d84e4d7c776fa093dbb2a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3a655d2) will **decrease** coverage by `54.63%`.
   > The diff coverage is `14.06%`.
   
   ```diff
   @@              Coverage Diff              @@
   ##             master    #9224       +/-   ##
   =============================================
   - Coverage     70.01%   15.37%   -54.64%     
   + Complexity     4762      170     -4592     
   =============================================
     Files          1857     1811       -46     
     Lines         99136    97054     -2082     
     Branches      15076    14842      -234     
   =============================================
   - Hits          69406    14926    -54480     
   - Misses        24833    81003    +56170     
   + Partials       4897     1125     -3772     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration1 | `?` | |
   | integration2 | `?` | |
   | unittests1 | `?` | |
   | unittests2 | `15.37% <14.06%> (+<0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/pinot/pull/9224?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../pinot/common/function/scalar/StringFunctions.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vZnVuY3Rpb24vc2NhbGFyL1N0cmluZ0Z1bmN0aW9ucy5qYXZh) | `0.00% <0.00%> (-77.46%)` | :arrow_down: |
   | [...manager/realtime/LLRealtimeSegmentDataManager.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL21hbmFnZXIvcmVhbHRpbWUvTExSZWFsdGltZVNlZ21lbnREYXRhTWFuYWdlci5qYXZh) | `0.00% <0.00%> (-70.36%)` | :arrow_down: |
   | [...lugin/stream/kafka20/server/KafkaDataProducer.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcGx1Z2lucy9waW5vdC1zdHJlYW0taW5nZXN0aW9uL3Bpbm90LWthZmthLTIuMC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcGx1Z2luL3N0cmVhbS9rYWZrYTIwL3NlcnZlci9LYWZrYURhdGFQcm9kdWNlci5qYXZh) | `0.00% <0.00%> (-57.70%)` | :arrow_down: |
   | [...local/indexsegment/mutable/MutableSegmentImpl.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9pbmRleHNlZ21lbnQvbXV0YWJsZS9NdXRhYmxlU2VnbWVudEltcGwuamF2YQ==) | `0.00% <0.00%> (-54.26%)` | :arrow_down: |
   | [...java/org/apache/pinot/spi/stream/MessageBatch.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL01lc3NhZ2VCYXRjaC5qYXZh) | `0.00% <0.00%> (-60.00%)` | :arrow_down: |
   | [.../java/org/apache/pinot/spi/stream/RowMetadata.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL1Jvd01ldGFkYXRhLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...apache/pinot/spi/stream/StreamDataDecoderImpl.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL1N0cmVhbURhdGFEZWNvZGVySW1wbC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ache/pinot/spi/stream/StreamDataDecoderResult.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL1N0cmVhbURhdGFEZWNvZGVyUmVzdWx0LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...rg/apache/pinot/spi/stream/StreamDataProducer.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL1N0cmVhbURhdGFQcm9kdWNlci5qYXZh) | `0.00% <0.00%> (-44.00%)` | :arrow_down: |
   | [...ava/org/apache/pinot/spi/stream/StreamMessage.java](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvc3RyZWFtL1N0cmVhbU1lc3NhZ2UuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | ... and [1426 more](https://codecov.io/gh/apache/pinot/pull/9224/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


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


[GitHub] [pinot] navina commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1219953283

   > if the header is broken but somehow the payload is ok. what's the behavior before/after this change
   
   Not sure if I follow what you mean by " header is broken "? Today, if a record cannot be decoded, it throws an exception and stops ingestion. The behavior will remain the same. 
   
   > if header doesn't agree with the pre-process info, which one should we trust?
   >if payload doesn't agree with the pre-process info but align with header, which one should we trust?
   
   I think the PR description needs more details on what kind of pre-processing I was referring to. I was referring to pre-processing on the source that is outside of Pinot. 
   
   >another question ii what's the performance cost of skipping headers vs parsing headers? do we have any benchmarks? 
   
   There shouldn't be any performance cost for parsing headers as typically, when the headers are returned via the client API, they are already decoded. If the user-specified headers are non-primitives, then it will add to the cost. But in my current implementation, I haven't even added support for a header value decoder. It assumes that header key is a string and the value is a primitive. this is a good question. I will add more details in the PR description. 
   
   


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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980752230


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -544,16 +547,16 @@ private boolean processStreamEvents(MessageBatch messagesAndOffsets, long idlePi
 
       // Index each message
       reuse.clear();
-      // retrieve metadata from the message batch if available
-      // this can be overridden by the decoder if there is a better indicator in the message payload
-      RowMetadata msgMetadata = messagesAndOffsets.getMetadataAtIndex(index);
-
-      GenericRow decodedRow = _messageDecoder
-          .decode(messagesAndOffsets.getMessageAtIndex(index), messagesAndOffsets.getMessageOffsetAtIndex(index),
-              messagesAndOffsets.getMessageLengthAtIndex(index), reuse);
-      if (decodedRow != null) {
+      StreamDataDecoderResult decodedRow = _streamDataDecoder.decode(messagesAndOffsets.getStreamMessage(index));
+      RowMetadata msgMetadata = messagesAndOffsets.getStreamMessage(index).getMetadata();
+      if (decodedRow.getException() != null) {
+        // TODO: handle exception as we do today - do we silently drop the record or throw exception?

Review Comment:
   I am open to introducing a class of retriable and non-retriable exceptions if we can clearly articulate them in a manner that is common to all decoders. As of today, I only see this to be the case in avro decoder. Hence, for now, I would leave this capability within the individual decoders and not surface it in `LLRealtimeSegmentManager`. 
   
   We can iterate on it if the need arises in the future. 



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


[GitHub] [pinot] mcvsubbu commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980329107


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   What is the semantic that you want here? Time at which the record was ingested into the stream? Time at which the record was generated upstream? Or some other?
   In other words, in Pinot, if I write an expression `(System.currentTimeMillis() - getRecordTimeStampMs())` what do you expect this value to signify (independent of any underlying stream, of course)?
   
   As a side note, please modify the javadoc with the answer to the q above.



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


[GitHub] [pinot] mcvsubbu commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980630417


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -544,16 +547,16 @@ private boolean processStreamEvents(MessageBatch messagesAndOffsets, long idlePi
 
       // Index each message
       reuse.clear();
-      // retrieve metadata from the message batch if available
-      // this can be overridden by the decoder if there is a better indicator in the message payload
-      RowMetadata msgMetadata = messagesAndOffsets.getMetadataAtIndex(index);
-
-      GenericRow decodedRow = _messageDecoder
-          .decode(messagesAndOffsets.getMessageAtIndex(index), messagesAndOffsets.getMessageOffsetAtIndex(index),
-              messagesAndOffsets.getMessageLengthAtIndex(index), reuse);
-      if (decodedRow != null) {
+      StreamDataDecoderResult decodedRow = _streamDataDecoder.decode(messagesAndOffsets.getStreamMessage(index));
+      RowMetadata msgMetadata = messagesAndOffsets.getStreamMessage(index).getMetadata();
+      if (decodedRow.getException() != null) {
+        // TODO: handle exception as we do today - do we silently drop the record or throw exception?

Review Comment:
   Since you are defining the StreamDataDecoderResult now to contain exceptions, don't you think it is better than we introduce a class of exceptions there -- ones in which we need to retry and others in which we don't? Of course, we can always change it later.
   
   I am fine if you are handling the exception stuff in another PR, and are open to changing the definition of StreamDataDecoderResult if it makes sense.



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980792005


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   Created an issues for this https://github.com/apache/pinot/issues/9470 . Let's resolve this conversation and follow-up. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r978359178


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaStreamMessage.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.kafka20;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.StreamMessage;
+import org.apache.pinot.spi.stream.StreamMessageMetadata;
+
+
+public class KafkaStreamMessage extends StreamMessage {
+  private static final GenericRow EMPTY_ROW_REUSE = new GenericRow();
+
+  // should distinguish stream-specific record metadata in the table??
+  private final long _offset;

Review Comment:
   Done



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r978359828


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/RowMetadataExtractor.java:
##########
@@ -18,15 +18,35 @@
  */
 package org.apache.pinot.plugin.stream.kafka20;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Header;
+import org.apache.kafka.common.header.Headers;
+import org.apache.pinot.spi.data.readers.GenericRow;
 import org.apache.pinot.spi.stream.RowMetadata;
 import org.apache.pinot.spi.stream.StreamMessageMetadata;
 
 
 @FunctionalInterface
 public interface RowMetadataExtractor {
   static RowMetadataExtractor build(boolean populateMetadata) {
-    return populateMetadata ? record -> new StreamMessageMetadata(record.timestamp()) : record -> null;
+    return record -> {
+      if (!populateMetadata) {
+        return null;
+      }
+      GenericRow headerGenericRow = new GenericRow();
+      Headers headers = record.headers();
+      if (headers != null) {
+        Header[] headersArray = headers.toArray();
+        for (Header header : headersArray) {
+          headerGenericRow.putValue(header.key(), header.value());
+        }
+      }
+      Map<String, String> metadata = new HashMap<>();
+      metadata.put("offset", String.valueOf(record.offset()));

Review Comment:
   Removed the class variable. 



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


[GitHub] [pinot] navina commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1220098245

   Let's continue any design related discussions in the [design doc](https://docs.google.com/document/d/1kTUfBud1SBSh_703mvu6ybkbIwiKKH9eXpdcpEmhC2E/edit)
   Thanks! 


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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971755233


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   I agree with you about the confusion. I was trying not to blow up/break existing interfaces in pinot-spi. 
   
   Let me create a separate PR that just renames `RowMetadata` into `StreamMessageMetadata`. I want to avoid using the term "row" when we talk about input from a stream. I find that confusing :/ 



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderResult.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.spi.stream;
+
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
+/**
+ * A container class for holding the result of a decoder
+ * At any point in time, only one of Result or exception is set as null.
+ */
+public final class StreamDataDecoderResult {
+  private final GenericRow _result;
+  private final Exception _exception;
+
+  public StreamDataDecoderResult(GenericRow result, Exception exception) {
+    _result = result;
+    _exception = exception;
+  }
+
+  public GenericRow getResult() {

Review Comment:
   ack



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971756569


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderImpl.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.spi.stream;
+
+import java.util.Map;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class StreamDataDecoderImpl implements StreamDataDecoder {
+  private static final String KEY = "__key";
+  private static final String HEADER_KEY_PREFIX = "header$";
+  private static final Logger LOGGER = LoggerFactory.getLogger(StreamDataDecoderImpl.class);
+
+  private final StreamMessageDecoder _valueDecoder;
+
+  // Maybe simplify by allowing only string keys ?
+  public StreamDataDecoderImpl(StreamMessageDecoder valueDecoder) {
+    _valueDecoder = valueDecoder;
+  }
+
+  @Override
+  public StreamDataDecoderResult decode(StreamMessage message) {
+    assert message.getValue() != null;
+
+    try {
+      GenericRow row = _valueDecoder.decode(message.getValue(), 0, message.getValue().length, new GenericRow());

Review Comment:
   ack. will look it up. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980790177


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   renamed!



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


[GitHub] [pinot] walterddr commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
walterddr commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1219819416

   is there a backward compatibility story for this change. 
   - if the header is broken but somehow the payload is ok. what's the behavior before/after this change
   - if header doesn't agree with the pre-process info, which one should we trust?
   - if payload doesn't agree with the pre-process info but align with header, which one should we trust?
   
   another question ii what's the performance cost of skipping headers vs parsing headers? do we have any benchmarks?


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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r979753631


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   I disagree here. I don't think the semantics are clear. 
   
   1. Ingestion time is vague. It can be interpreted as the time at which the record was ingested into Pinot table or the time at which the record was ingested into the upstream source. Looking at the implementation today, it seems to refer to the latter case. So , recordtimestamp is more accurate as it is the timestamp which comes with the incoming stream record.  
   2. Oddly enough, this interface is named `RowMetadata`. However, a row is usually an entity in a table. It is not typically referred to the data in a streaming source. We need to start making the distinction more clear in Pinot. 
   



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r978359462


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/RowMetadataExtractor.java:
##########
@@ -18,15 +18,35 @@
  */
 package org.apache.pinot.plugin.stream.kafka20;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Header;
+import org.apache.kafka.common.header.Headers;
+import org.apache.pinot.spi.data.readers.GenericRow;
 import org.apache.pinot.spi.stream.RowMetadata;
 import org.apache.pinot.spi.stream.StreamMessageMetadata;
 
 
 @FunctionalInterface
 public interface RowMetadataExtractor {
   static RowMetadataExtractor build(boolean populateMetadata) {
-    return populateMetadata ? record -> new StreamMessageMetadata(record.timestamp()) : record -> null;
+    return record -> {
+      if (!populateMetadata) {
+        return null;
+      }
+      GenericRow headerGenericRow = new GenericRow();
+      Headers headers = record.headers();
+      if (headers != null) {
+        Header[] headersArray = headers.toArray();
+        for (Header header : headersArray) {
+          headerGenericRow.putValue(header.key(), header.value());
+        }
+      }
+      Map<String, String> metadata = new HashMap<>();
+      metadata.put("offset", String.valueOf(record.offset()));

Review Comment:
   I have renamed this to KafkaMetadataExtractor



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r979772662


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderResult.java:
##########
@@ -16,27 +16,32 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.pinot.plugin.stream.kafka20;
+package org.apache.pinot.spi.stream;
 
-import java.nio.ByteBuffer;
-import org.apache.pinot.plugin.stream.kafka.MessageAndOffset;
-import org.apache.pinot.spi.stream.RowMetadata;
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
 
 
-public class MessageAndOffsetAndMetadata extends MessageAndOffset {
-  private final RowMetadata _rowMetadata;
+/**
+ * A container class for holding the result of a decoder
+ * At any point in time, only one of Result or exception is set as null.
+ */
+public final class StreamDataDecoderResult {
+  private final GenericRow _result;
+  private final Exception _exception;

Review Comment:
   > You have an exception declared here. I see that the decode() operation is guaranteed not to throw an exception. You may also want to add a comment on the decode() interface that it is NOT supposed to throw an exception (just to guard against someone changing it).
   
   Added
   
   > Also, instead of a generic exception, I suggest that we define some specific ones (or at least specific categories) -- retryable or not. See PR https://github.com/apache/pinot/pull/9051
   
   I specifically don't want to add any "types" of exception. The reason is that typically, when decoding fails, the caller either ignores the record or aborts the process. It is very uncommon to try and "handle" decoding errors. That's why I preferred encapsulating the exception into a class, instead of throwing it. It is then, completely left to the caller to determine whether to handle specific exceptions or not. This leaves the interface more flexible for usage as well.
   
   For #9051 and the like: The current `StreamDecoder` interface allows returning `null` value, which seems to the main source of confusion. The interface is defining how a specific caller should handle a `null` value when there can be more than 1 caller. At the time of writing #9051, there was only one caller for this method `LLRealtimeSegmentDataManager`. Now that we have one more, `StreamDataDecoder`, it is prone to error. 
    
   I will ensure that the existing functionalities are not affected or find a workaround. Thanks for pointing it out.
   
   



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971758010


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaPartitionLevelConsumer.java:
##########
@@ -43,30 +45,36 @@ public KafkaPartitionLevelConsumer(String clientId, StreamConfig streamConfig, i
   }
 
   @Override
-  public MessageBatch<byte[]> fetchMessages(StreamPartitionMsgOffset startMsgOffset,
+  public MessageBatch<KafkaStreamMessage> fetchMessages(StreamPartitionMsgOffset startMsgOffset,
       StreamPartitionMsgOffset endMsgOffset, int timeoutMillis) {
     final long startOffset = ((LongMsgOffset) startMsgOffset).getOffset();
     final long endOffset = endMsgOffset == null ? Long.MAX_VALUE : ((LongMsgOffset) endMsgOffset).getOffset();
     return fetchMessages(startOffset, endOffset, timeoutMillis);
   }
 
-  public MessageBatch<byte[]> fetchMessages(long startOffset, long endOffset, int timeoutMillis) {
+  public MessageBatch<KafkaStreamMessage> fetchMessages(long startOffset, long endOffset, int timeoutMillis) {
     if (LOGGER.isDebugEnabled()) {
       LOGGER.debug("poll consumer: {}, startOffset: {}, endOffset:{} timeout: {}ms", _topicPartition, startOffset,
           endOffset, timeoutMillis);
     }
     _consumer.seek(_topicPartition, startOffset);
     ConsumerRecords<String, Bytes> consumerRecords = _consumer.poll(Duration.ofMillis(timeoutMillis));
     List<ConsumerRecord<String, Bytes>> messageAndOffsets = consumerRecords.records(_topicPartition);
-    List<MessageAndOffsetAndMetadata> filtered = new ArrayList<>(messageAndOffsets.size());
+    List<KafkaStreamMessage> filtered = new ArrayList<>(messageAndOffsets.size());
     long lastOffset = startOffset;
     for (ConsumerRecord<String, Bytes> messageAndOffset : messageAndOffsets) {
+      String key = messageAndOffset.key();
+      byte[] keyBytes = key == null ? null : key.getBytes(StandardCharsets.UTF_8);
       Bytes message = messageAndOffset.value();
       long offset = messageAndOffset.offset();
       if (offset >= startOffset & (endOffset > offset | endOffset == -1)) {
         if (message != null) {
+          StreamMessageMetadata rowMetadata = null;
+          if (_config.isPopulateMetadata()) {
+            rowMetadata = (StreamMessageMetadata) _rowMetadataExtractor.extract(messageAndOffset);
+          }
           filtered.add(
-              new MessageAndOffsetAndMetadata(message.get(), offset, _rowMetadataExtractor.extract(messageAndOffset)));
+              new KafkaStreamMessage(keyBytes, message.get(), offset, rowMetadata));

Review Comment:
   I don't think there is a good reason behind this. just how the code evolved. I can make record offset to be part of metadata. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r974043892


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaStreamMessage.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.kafka20;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.StreamMessage;
+import org.apache.pinot.spi.stream.StreamMessageMetadata;
+
+
+public class KafkaStreamMessage extends StreamMessage {
+  private static final GenericRow EMPTY_ROW_REUSE = new GenericRow();
+
+  // should distinguish stream-specific record metadata in the table??
+  private final long _offset;

Review Comment:
   ah I get your question. `offset` is something that is specific to kafka. So, I am not sure if it should be bundled into the StreamMessageMetadata or create a `KafkaStreamMessageMetadata` that extends `StreamMessageMetadata`. 
   



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971756300


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/RealtimeClusterIntegrationTest.java:
##########
@@ -76,6 +76,8 @@ public void setUp()
 
     // Wait for all documents loaded
     waitForAllDocsLoaded(600_000L);
+
+    Thread.currentThread().join();

Review Comment:
   yep



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


[GitHub] [pinot] npawar commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
npawar commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1247456006

   > Design doc: https://docs.google.com/document/d/1kTUfBud1SBSh_703mvu6ybkbIwiKKH9eXpdcpEmhC2E/edit
   > 
   > This is an extension of PR #9096
   > 
   > # Motivation
   > Most stream systems provide a message envelope, which encapsulates the record payload, along with record headers, keys and other system-specific metadata For e.g:
   > 
   > 1. Kafka allows keyed records and additionally, provides headers
   > 2. Kinesis requires keyed records and includes some additional metadata such as sequenceId etc
   > 3. Pulsar also supports keyed records and allows including arbitrary properties.
   > 4. Pubsub supports keyed messages, along with user-defined attributes and message metadata.
   > 
   > Today, Pinot drops everything from the payload, other than the record value itself. Hence, there needs to be a way to extract these values and present them in the Pinot table as regular columns (of course, it has to be defined in the pinot schema).
   > 
   > This can be very useful for the Pinot user as they don't have to "pre-process" the stream to make the record metadata available in the data payload. It also prevents custom solutions (such as [this](https://github.com/startreedata/startree-pinot/pull/484/files)).
   > 
   > # Context
   > Want to clarify the terminology here. Typically, in most streaming systems, a record is composed of the following:
   > 
   > 1. Record key - usually, a string, although kafka allows any type (today, `pinot-kafka` connector assumes the key to always be a key)
   > 2. Record value - actual data paylaod. Pinot extract only this value and decodes it.
   > 3. Record headers - these are user-defined record header that can be specific to the publishing application. Typically, headers are meant to be efficient and small. For example, in Kafka , it allows <String, byte[]>. technically, `byte[]` can be anything and we can make a call on whether to support arbitrary header value types or not.
   > 4. Record Metadata - these may or may not be included in the record payload and it is system-defined. For example, for message identifiers, kinesis has `sequenceId`, kafka has `offset`, pubsub has `messageId` etc. While these may not be useful for the user-facing application, it comes-in handy for debugging.
   > 
   > # What does this PR do?
   > This PR attempts to extract key, header and other metadata from any supported streaming connector. This feature is opt-in, meaning it can be enabled by setting `stream.$streamType.metadata.populate` as `true`
   > 
   > please note:
   > 
   > 1. I am in the process of adding some unit tests. I have tested with a pinot realtime quickstart. Need to do some more cleanup.
   > 2. For whatever reason, the integration tests fail in the CI pipeline here, where as it runs fine on my laptop. Still fixing forward.
   > 3. Documentation for this feature will follow after this PR is merged.
   > 
   > For Reviewers, things to discuss:
   > 
   > 1. In the current patch, the record key (when available) is extracted as `__key` column , where as headers are extracted as `header$<HEADER_KEY_NAME>` . Does this sound like a good convention to follow for all stream connectors  -> Header columns will always be prefixed with `header$` and any other metadata such as key or offset will be prefixed as `__`
   > 2. In `MessageBatch`, I have marked one of the methods as `@Deprecated` as I am hoping to eventually eliminate the need for typed interface there. The current changes are backwards compatible. Let me know if there is a better way.
   
   Would prefer if we're able to keep it all consistent in terms of the prefix (if going with __, then __key, __header$headerName, __metadata)


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


[GitHub] [pinot] navina commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1255908191

   Drew out the class diagram for easy reference. RowMetadata seems redundant. But I think we can keep it around for now.
   
   ![stream-message-apis](https://user-images.githubusercontent.com/1909480/191916665-bb4a46d5-c89e-4927-a666-8fcdd7032fca.png)
   


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


[GitHub] [pinot] mcvsubbu commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r979468325


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderResult.java:
##########
@@ -16,27 +16,32 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.pinot.plugin.stream.kafka20;
+package org.apache.pinot.spi.stream;
 
-import java.nio.ByteBuffer;
-import org.apache.pinot.plugin.stream.kafka.MessageAndOffset;
-import org.apache.pinot.spi.stream.RowMetadata;
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
 
 
-public class MessageAndOffsetAndMetadata extends MessageAndOffset {
-  private final RowMetadata _rowMetadata;
+/**
+ * A container class for holding the result of a decoder
+ * At any point in time, only one of Result or exception is set as null.
+ */
+public final class StreamDataDecoderResult {
+  private final GenericRow _result;
+  private final Exception _exception;

Review Comment:
   You have an exception declared here. I see that the decode() operation is guaranteed not to throw an exception. You may also want to add a comment on the decode() interface that it is NOT supposed to throw an exception (just to guard against someone changing it).
   
   Also, instead of a generic exception, I suggest that we define some specific ones (or at least specific categories) -- retryable or not. See PR #9051 
   



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   What is wrong with `getIngestionTimeMs()`? I think it conveys the semantics perfectly well instead of `getRecordTimeStampMs()`



##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -544,16 +547,16 @@ private boolean processStreamEvents(MessageBatch messagesAndOffsets, long idlePi
 
       // Index each message
       reuse.clear();
-      // retrieve metadata from the message batch if available
-      // this can be overridden by the decoder if there is a better indicator in the message payload
-      RowMetadata msgMetadata = messagesAndOffsets.getMetadataAtIndex(index);
-
-      GenericRow decodedRow = _messageDecoder
-          .decode(messagesAndOffsets.getMessageAtIndex(index), messagesAndOffsets.getMessageOffsetAtIndex(index),
-              messagesAndOffsets.getMessageLengthAtIndex(index), reuse);
-      if (decodedRow != null) {
+      StreamDataDecoderResult decodedRow = _streamDataDecoder.decode(messagesAndOffsets.getStreamMessage(index));
+      RowMetadata msgMetadata = messagesAndOffsets.getStreamMessage(index).getMetadata();
+      if (decodedRow.getException() != null) {
+        // TODO: handle exception as we do today - do we silently drop the record or throw exception?

Review Comment:
   This area is a little wild. There were a couple of PRs before as well, that kind of made it even more messy (someone needed decoder exceptions to retry to fetch new schema). It will be great if you can add Javadocs as appropriate in the decoder interfaces that clearly indicates how the exceptions will be treated by this class.
   
   Thanks



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   +1, we should find ways of removing rowmetadata with the introduction of more generic class. Can we mark it deprecated?



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980374900


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   I will follow up with this in a separate PR (deprecation/deletion of `RowMetadata`) 



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


[GitHub] [pinot] navina commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1255907438

   Drew out the class diagram for easy reference. `RowMetadata` seems redundant. But I think we can keep it around for now. 
   
   ![stream-message-apis](https://user-images.githubusercontent.com/1909480/191916433-8bb693ae-d3dc-4bf6-a575-80841e9c424f.svg)
   


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


[GitHub] [pinot] npawar commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
npawar commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r976903107


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/RowMetadataExtractor.java:
##########
@@ -18,15 +18,35 @@
  */
 package org.apache.pinot.plugin.stream.kafka20;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Header;
+import org.apache.kafka.common.header.Headers;
+import org.apache.pinot.spi.data.readers.GenericRow;
 import org.apache.pinot.spi.stream.RowMetadata;
 import org.apache.pinot.spi.stream.StreamMessageMetadata;
 
 
 @FunctionalInterface
 public interface RowMetadataExtractor {
   static RowMetadataExtractor build(boolean populateMetadata) {
-    return populateMetadata ? record -> new StreamMessageMetadata(record.timestamp()) : record -> null;
+    return record -> {
+      if (!populateMetadata) {
+        return null;
+      }
+      GenericRow headerGenericRow = new GenericRow();
+      Headers headers = record.headers();
+      if (headers != null) {
+        Header[] headersArray = headers.toArray();
+        for (Header header : headersArray) {
+          headerGenericRow.putValue(header.key(), header.value());
+        }
+      }
+      Map<String, String> metadata = new HashMap<>();
+      metadata.put("offset", String.valueOf(record.offset()));

Review Comment:
   since we're putting the "offset" into the StreamMessageMetadata in this kafka specific rowMetadataExtractor, do we still need the "offset" as param in KafkaStreamMessage? the calls can extract it from the StreamMessageMetadata object instead? just trying to remove that special casing, since it seems we already are encapsulating it inside the StreamMessageMetadata 



##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/RowMetadataExtractor.java:
##########
@@ -18,15 +18,35 @@
  */
 package org.apache.pinot.plugin.stream.kafka20;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Header;
+import org.apache.kafka.common.header.Headers;
+import org.apache.pinot.spi.data.readers.GenericRow;
 import org.apache.pinot.spi.stream.RowMetadata;
 import org.apache.pinot.spi.stream.StreamMessageMetadata;
 
 
 @FunctionalInterface
 public interface RowMetadataExtractor {
   static RowMetadataExtractor build(boolean populateMetadata) {
-    return populateMetadata ? record -> new StreamMessageMetadata(record.timestamp()) : record -> null;
+    return record -> {
+      if (!populateMetadata) {
+        return null;
+      }
+      GenericRow headerGenericRow = new GenericRow();
+      Headers headers = record.headers();
+      if (headers != null) {
+        Header[] headersArray = headers.toArray();
+        for (Header header : headersArray) {
+          headerGenericRow.putValue(header.key(), header.value());
+        }
+      }
+      Map<String, String> metadata = new HashMap<>();
+      metadata.put("offset", String.valueOf(record.offset()));

Review Comment:
   just realized that this RowMetadataExtractor is within the Kafka module. So to support metadata extraction for other streams, we'd have to add respective implementations? in which case (not introduced by this PR but) should this class be renamed to KafkaRowMetadataExtractor?



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   and StreamMessageMetadata would still extend RowMetadata or you'd completely separate and unlink the 2? 
   If it's hard to remove, i'm okay with leaving this as is for now



##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaStreamMessage.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.kafka20;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.StreamMessage;
+import org.apache.pinot.spi.stream.StreamMessageMetadata;
+
+
+public class KafkaStreamMessage extends StreamMessage {
+  private static final GenericRow EMPTY_ROW_REUSE = new GenericRow();
+
+  // should distinguish stream-specific record metadata in the table??
+  private final long _offset;

Review Comment:
   I think the latter would be clean - "create a KafkaStreamMessageMetadata that extends StreamMessageMetadata".  In which case we wouldn't need a impl of StreamMessage for every stream, we'd just need to add an impl of StreamMessageMetadata for each stream. wdyt?



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r973939545


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -31,6 +32,8 @@
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public interface RowMetadata {
+  GenericRow EMPTY_ROW = new GenericRow();

Review Comment:
   I tried to remove `RowMetadata`. But it looks like it is being passed around in other interfaces like `MutableSegment` .  
   
   I think it is fine to leave the interface as it will be convenient to include in other interface APIs and also, possibly extend it. I am wondering if there is a lot of value in distinguishing `RowMetadata` from a `StreamMessage`'s metadata. 
   
   `RowMetadata` can refer to Pinot related row metadata (Ex. time at which a record was indexed in Pinot) . Where as, `StreamMessageMetadata` continues to simply hold the incoming record related metadata (ex. when record was ingested into upstream, headers etc).  Wdyt @npawar ?



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r974133710


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaPartitionLevelConsumer.java:
##########
@@ -43,30 +45,36 @@ public KafkaPartitionLevelConsumer(String clientId, StreamConfig streamConfig, i
   }
 
   @Override
-  public MessageBatch<byte[]> fetchMessages(StreamPartitionMsgOffset startMsgOffset,
+  public MessageBatch<KafkaStreamMessage> fetchMessages(StreamPartitionMsgOffset startMsgOffset,
       StreamPartitionMsgOffset endMsgOffset, int timeoutMillis) {
     final long startOffset = ((LongMsgOffset) startMsgOffset).getOffset();
     final long endOffset = endMsgOffset == null ? Long.MAX_VALUE : ((LongMsgOffset) endMsgOffset).getOffset();
     return fetchMessages(startOffset, endOffset, timeoutMillis);
   }
 
-  public MessageBatch<byte[]> fetchMessages(long startOffset, long endOffset, int timeoutMillis) {
+  public MessageBatch<KafkaStreamMessage> fetchMessages(long startOffset, long endOffset, int timeoutMillis) {
     if (LOGGER.isDebugEnabled()) {
       LOGGER.debug("poll consumer: {}, startOffset: {}, endOffset:{} timeout: {}ms", _topicPartition, startOffset,
           endOffset, timeoutMillis);
     }
     _consumer.seek(_topicPartition, startOffset);
     ConsumerRecords<String, Bytes> consumerRecords = _consumer.poll(Duration.ofMillis(timeoutMillis));
     List<ConsumerRecord<String, Bytes>> messageAndOffsets = consumerRecords.records(_topicPartition);
-    List<MessageAndOffsetAndMetadata> filtered = new ArrayList<>(messageAndOffsets.size());
+    List<KafkaStreamMessage> filtered = new ArrayList<>(messageAndOffsets.size());
     long lastOffset = startOffset;
     for (ConsumerRecord<String, Bytes> messageAndOffset : messageAndOffsets) {
+      String key = messageAndOffset.key();
+      byte[] keyBytes = key == null ? null : key.getBytes(StandardCharsets.UTF_8);
       Bytes message = messageAndOffset.value();
       long offset = messageAndOffset.offset();
       if (offset >= startOffset & (endOffset > offset | endOffset == -1)) {
         if (message != null) {
+          StreamMessageMetadata rowMetadata = null;
+          if (_config.isPopulateMetadata()) {
+            rowMetadata = (StreamMessageMetadata) _rowMetadataExtractor.extract(messageAndOffset);
+          }
           filtered.add(
-              new MessageAndOffsetAndMetadata(message.get(), offset, _rowMetadataExtractor.extract(messageAndOffset)));
+              new KafkaStreamMessage(keyBytes, message.get(), offset, rowMetadata));

Review Comment:
   Looks like it is used to calculate the next upcoming offset and hence, stored in the metadata object.



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980381894


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -544,16 +547,16 @@ private boolean processStreamEvents(MessageBatch messagesAndOffsets, long idlePi
 
       // Index each message
       reuse.clear();
-      // retrieve metadata from the message batch if available
-      // this can be overridden by the decoder if there is a better indicator in the message payload
-      RowMetadata msgMetadata = messagesAndOffsets.getMetadataAtIndex(index);
-
-      GenericRow decodedRow = _messageDecoder
-          .decode(messagesAndOffsets.getMessageAtIndex(index), messagesAndOffsets.getMessageOffsetAtIndex(index),
-              messagesAndOffsets.getMessageLengthAtIndex(index), reuse);
-      if (decodedRow != null) {
+      StreamDataDecoderResult decodedRow = _streamDataDecoder.decode(messagesAndOffsets.getStreamMessage(index));
+      RowMetadata msgMetadata = messagesAndOffsets.getStreamMessage(index).getMetadata();
+      if (decodedRow.getException() != null) {
+        // TODO: handle exception as we do today - do we silently drop the record or throw exception?

Review Comment:
   Looks like, we increment a metric today when an exception is thrown by the decoder itself or if `null` is returned.  I am leaving this part unchanged for now. 
   In a follow-up PR, I think we can elegantly handle decode errors for all supported streams - my proposal would be to use a config to decide whether to re-throw exception or skip the record. 



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


[GitHub] [pinot] npawar merged pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
npawar merged PR #9224:
URL: https://github.com/apache/pinot/pull/9224


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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971758726


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamMessageMetadata.java:
##########
@@ -18,26 +18,38 @@
  */
 package org.apache.pinot.spi.stream;
 
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
 /**
  * A class that provides metadata associated with the message of a stream, for e.g.,

Review Comment:
   > Would prefer if we're able to keep it all consistent in terms of the prefix (if going with __, then __key, __header$headerName, __metadata)
   
   Makes sense
   



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971763327


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamDataDecoderImpl.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.spi.stream;
+
+import java.util.Map;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class StreamDataDecoderImpl implements StreamDataDecoder {
+  private static final String KEY = "__key";
+  private static final String HEADER_KEY_PREFIX = "header$";
+  private static final Logger LOGGER = LoggerFactory.getLogger(StreamDataDecoderImpl.class);
+
+  private final StreamMessageDecoder _valueDecoder;
+
+  // Maybe simplify by allowing only string keys ?
+  public StreamDataDecoderImpl(StreamMessageDecoder valueDecoder) {
+    _valueDecoder = valueDecoder;
+  }
+
+  @Override
+  public StreamDataDecoderResult decode(StreamMessage message) {
+    assert message.getValue() != null;
+
+    try {
+      GenericRow row = _valueDecoder.decode(message.getValue(), 0, message.getValue().length, new GenericRow());
+      if (row != null) {
+        if (message.getKey() != null) {
+          row.putValue(KEY, message.getKey());
+        }
+        RowMetadata metadata = message.getMetadata();

Review Comment:
   the metadata and other parts are already extracted when the consumer returns results for `fetchMessages` . This decoder decodes/deserializes each part of the `StreamMessage` , namely, key, value, metadata and headers, and adds it into a single`GenericRow` object that will be passed down through the transformers. 
   



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


[GitHub] [pinot] npawar commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
npawar commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980399230


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -544,16 +547,17 @@ private boolean processStreamEvents(MessageBatch messagesAndOffsets, long idlePi
 
       // Index each message
       reuse.clear();

Review Comment:
   minor: `reuse` can be deleted now



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


[GitHub] [pinot] mcvsubbu commented on pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on PR #9224:
URL: https://github.com/apache/pinot/pull/9224#issuecomment-1256747133

   We would like to review this.  thanks


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


[GitHub] [pinot] mcvsubbu commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980629587


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   > > What is the semantic that you want here?
   > 
   > Time at which the record was ingested into the stream.
   
   And hence the API getRecordIngestionTime()
   



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r971747264


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamMessageMetadata.java:
##########
@@ -18,26 +18,38 @@
  */
 package org.apache.pinot.spi.stream;
 
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
 /**
  * A class that provides metadata associated with the message of a stream, for e.g.,

Review Comment:
   good point. I will update the doc. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980376435


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   I have already updated the javadoc for `RowMetadata#getRecordTimestampMs` . Let me know if you need more clarity or are referring to some other javadoc you want me to update. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980754445


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   I was one of the folks writing plugin for a new stream and it wasn't clear to me :) 
   
   I am fine changing it to `recordIngestionTime`. Previously, it was just "ingestionTime" and it was within "RowMetadata". So, altogether, it didn't make sense to me. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980374389


##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/RowMetadata.java:
##########
@@ -39,5 +44,27 @@ public interface RowMetadata {
    * @return timestamp (epoch in milliseconds) when the row was ingested upstream
    *         Long.MIN_VALUE if not available
    */
-  long getIngestionTimeMs();
+  long getRecordTimestampMs();

Review Comment:
   > What is the semantic that you want here?
   
   Time at which the record was ingested into the stream. 
   
   > Time at which the record was generated upstream
   
   This would be event time and it is possible that the event time is used as the record timestamps (this is possible in Kafka by allowing record to use producer's timestamp). However, from Pinot's point of view, we only care about how soon a record became available for consumption. 
   
   > In other words, in Pinot, if I write an expression (System.currentTimeMillis() - getRecordTimeStampMs()) what do you expect this value to signify (independent of any underlying stream, of course)?
   
   I want this expression `System.currentTimeMillis() - getRecordTimestampMs()` to indicate the message availability for consumption since the time it became available in source. It should _tend towards 0_ when the consumer is fully caught up the upstream data



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r978298050


##########
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaStreamMessage.java:
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.kafka20;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.StreamMessage;
+import org.apache.pinot.spi.stream.StreamMessageMetadata;
+
+
+public class KafkaStreamMessage extends StreamMessage {
+  private static final GenericRow EMPTY_ROW_REUSE = new GenericRow();
+
+  // should distinguish stream-specific record metadata in the table??
+  private final long _offset;

Review Comment:
   yeah makes sense. I will make that change. 



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


[GitHub] [pinot] navina commented on a diff in pull request #9224: Extract record keys, headers and metadata from Stream sources

Posted by GitBox <gi...@apache.org>.
navina commented on code in PR #9224:
URL: https://github.com/apache/pinot/pull/9224#discussion_r980752230


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/LLRealtimeSegmentDataManager.java:
##########
@@ -544,16 +547,16 @@ private boolean processStreamEvents(MessageBatch messagesAndOffsets, long idlePi
 
       // Index each message
       reuse.clear();
-      // retrieve metadata from the message batch if available
-      // this can be overridden by the decoder if there is a better indicator in the message payload
-      RowMetadata msgMetadata = messagesAndOffsets.getMetadataAtIndex(index);
-
-      GenericRow decodedRow = _messageDecoder
-          .decode(messagesAndOffsets.getMessageAtIndex(index), messagesAndOffsets.getMessageOffsetAtIndex(index),
-              messagesAndOffsets.getMessageLengthAtIndex(index), reuse);
-      if (decodedRow != null) {
+      StreamDataDecoderResult decodedRow = _streamDataDecoder.decode(messagesAndOffsets.getStreamMessage(index));
+      RowMetadata msgMetadata = messagesAndOffsets.getStreamMessage(index).getMetadata();
+      if (decodedRow.getException() != null) {
+        // TODO: handle exception as we do today - do we silently drop the record or throw exception?

Review Comment:
   I am open to introducing a class of retriable and non-retriable exceptions if we can clearly articulate them in a manner that is common to all decoders. As of today, I only see this to be the case in avro decoder. Hence, for now, I would leave this retry capability within the individual decoders and not surface it in `LLRealtimeSegmentManager`. 
   
   We can iterate on it if the need arises in the future. 



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