sajjad-moradi commented on a change in pull request #8057:
URL: https://github.com/apache/pinot/pull/8057#discussion_r792037438



##########
File path: 
pinot-spi/src/main/java/org/apache/pinot/spi/stream/OffsetCriteria.java
##########
@@ -168,24 +183,30 @@ public OffsetCriteria withOffsetCustom(String 
customString) {
      */
     public OffsetCriteria withOffsetString(String offsetString) {

Review comment:
       To be consistent with other types, could you add method 
`withOffsetAsTimestamp`?

##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-kafka-2.0/src/main/java/org/apache/pinot/plugin/stream/kafka20/KafkaStreamMetadataProvider.java
##########
@@ -63,6 +69,28 @@ public StreamPartitionMsgOffset 
fetchStreamPartitionOffset(OffsetCriteria offset
         offset =
             
_consumer.beginningOffsets(Collections.singletonList(_topicPartition), 
Duration.ofMillis(timeoutMillis))
                 .get(_topicPartition);
+      } else if (offsetCriteria.isPeriod()) {
+        String offsetString = offsetCriteria.getOffsetString();
+        Long periodToMillis = TimeUtils.convertPeriodToMillis(offsetString);
+        TopicPartition tp = new TopicPartition(_topic, _partition);
+        _offsetsForTimes.put(tp, System.currentTimeMillis() - periodToMillis);
+        if (_consumer.offsetsForTimes(_offsetsForTimes).get(tp) == null) {
+          offset = 
_consumer.endOffsets(Collections.singletonList(_topicPartition), 
Duration.ofMillis(timeoutMillis))
+              .get(_topicPartition);
+        } else {
+          offset = 
_consumer.offsetsForTimes(_offsetsForTimes).get(tp).offset();
+        }
+      } else if (offsetCriteria.isTimestamp()) {
+        String offsetString = offsetCriteria.getOffsetString();
+        Long timestampToMillis = 
TimeUtils.convertDateTimeStringToMillis(offsetString);
+        TopicPartition tp = new TopicPartition(_topic, _partition);
+        _offsetsForTimes.put(tp, timestampToMillis);
+        if (_consumer.offsetsForTimes(_offsetsForTimes).get(tp) == null) {
+          offset = 
_consumer.endOffsets(Collections.singletonList(_topicPartition), 
Duration.ofMillis(timeoutMillis))
+              .get(_topicPartition);
+        } else {
+          offset = 
_consumer.offsetsForTimes(_offsetsForTimes).get(tp).offset();
+        }

Review comment:
       IMO this is a bit complicated for a rather simple logic. 
`_consumer.offsetForTimes` fetches offset for the given timestamp in millis. It 
can be called only once. If the offset criteria is timestamp, directly use its 
value. If it's period, subtract the period in millis from current time in 
millis and use this value as timestamp for offsetForTimes.

##########
File path: 
pinot-spi/src/main/java/org/apache/pinot/spi/stream/OffsetCriteria.java
##########
@@ -168,24 +183,30 @@ public OffsetCriteria withOffsetCustom(String 
customString) {
      */
     public OffsetCriteria withOffsetString(String offsetString) {
       Preconditions.checkNotNull(offsetString, "Must provide offset string");
+      _offsetCriteria.setOffsetString(offsetString);
 
       if (offsetString.equalsIgnoreCase(OffsetType.SMALLEST.toString())) {
         _offsetCriteria.setOffsetType(OffsetType.SMALLEST);
       } else if (offsetString.equalsIgnoreCase(OffsetType.LARGEST.toString())) 
{
         _offsetCriteria.setOffsetType(OffsetType.LARGEST);
       } else {
-        try {
-          Long periodToMillis = TimeUtils.convertPeriodToMillis(offsetString);
-          if (periodToMillis >= 0) {
-            _offsetCriteria.setOffsetType(OffsetType.PERIOD);
+        Long periodToMillis = TimeUtils.convertPeriodToMillis(offsetString);
+        if (periodToMillis >= 0) {
+          _offsetCriteria.setOffsetType(OffsetType.PERIOD);
+          return _offsetCriteria;
+        } else {
+          LOGGER.error("Invalid time spec: '" + offsetString + "' (Valid 
examples: '3h', '4h30m')");
+          Long timestampToMillis = 
TimeUtils.convertDateTimeStringToMillis(offsetString);

Review comment:
       This is problematic. If offsetString is not of type period, 
convertPeriodToMillis throws parsing exception and it doesn't get to the else 
part.

##########
File path: 
pinot-spi/src/main/java/org/apache/pinot/spi/stream/OffsetCriteria.java
##########
@@ -48,6 +52,9 @@
     // Consumes from the time as provided in the period string
     PERIOD,
 
+    // Consumes from the timestamp specified

Review comment:
       Please specify the acceptable time format.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to