zachjsh commented on code in PR #16190:
URL: https://github.com/apache/druid/pull/16190#discussion_r1566576116


##########
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaSeekableStreamEndSequenceNumbers.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.druid.indexing.kafka;
+
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.apache.druid.data.input.kafka.KafkaTopicPartition;
+import 
org.apache.druid.indexing.seekablestream.SeekableStreamEndSequenceNumbers;
+import org.apache.druid.indexing.seekablestream.SeekableStreamSequenceNumbers;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.utils.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+@JsonTypeName(SeekableStreamEndSequenceNumbers.TYPE)

Review Comment:
   added information about serialization to javadoc, let me know if ok



##########
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaSeekableStreamStartSequenceNumbers.java:
##########
@@ -0,0 +1,220 @@
+/*
+ * 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.druid.indexing.kafka;
+
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.apache.druid.data.input.kafka.KafkaTopicPartition;
+import org.apache.druid.indexing.seekablestream.SeekableStreamSequenceNumbers;
+import 
org.apache.druid.indexing.seekablestream.SeekableStreamStartSequenceNumbers;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.utils.CollectionUtils;
+
+import javax.annotation.Nullable;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+@JsonTypeName(SeekableStreamStartSequenceNumbers.TYPE)
+public class KafkaSeekableStreamStartSequenceNumbers extends 
SeekableStreamStartSequenceNumbers<KafkaTopicPartition, Long>
+{
+  private static final String TYPE = "start";
+  private final boolean isMultiTopicPartition;
+
+  public KafkaSeekableStreamStartSequenceNumbers(
+      String stream,
+      String topic,
+      Map<KafkaTopicPartition, Long> partitionSequenceNumberMap,
+      Map<KafkaTopicPartition, Long> partitionOffsetMap,
+      @Nullable Set<KafkaTopicPartition> exclusivePartitions
+  )
+  {
+    super(stream, topic, partitionSequenceNumberMap, partitionOffsetMap, 
exclusivePartitions);
+    // how to know it topicPattern if the partitionSequenceNumberMap is empty?
+    isMultiTopicPartition = !partitionSequenceNumberMap.isEmpty() && 
partitionSequenceNumberMap.keySet()
+        .stream()
+        .findFirst()
+        .get()
+        .isMultiTopicPartition();
+  }
+
+  @Override
+  public boolean isMultiTopicPartition()
+  {
+    return isMultiTopicPartition;
+  }
+
+  @Override
+  public SeekableStreamSequenceNumbers<KafkaTopicPartition, Long> plus(
+      SeekableStreamSequenceNumbers<KafkaTopicPartition, Long> other
+  )
+  {
+    if (this.getClass() != other.getClass()) {
+      throw new IAE(
+          "Expected instance of %s, got %s",
+          this.getClass().getName(),
+          other.getClass().getName()
+      );
+    }
+
+    KafkaSeekableStreamStartSequenceNumbers that = 
(KafkaSeekableStreamStartSequenceNumbers) other;
+
+    if (!this.isMultiTopicPartition() && !that.isMultiTopicPartition()) {
+      return super.plus(other);
+    }
+
+
+    String thisTopic = getStream();
+    String thatTopic = that.getStream();
+    final Map<KafkaTopicPartition, Long> newMap;
+    final Set<KafkaTopicPartition> newExclusivePartitions = new HashSet<>();
+    if (!isMultiTopicPartition()) {
+      // going from topicPattern to single topic
+
+      // start with existing sequence numbers which in this case will be all 
single topic.
+      newMap = new HashMap<>(getPartitionSequenceNumberMap());
+
+      // add all sequence numbers from other where the topic name matches this 
topic. Transform to single topic
+      // as in this case we will be returning a single topic based sequence 
map.
+      newMap.putAll(that.getPartitionSequenceNumberMap().entrySet().stream()
+          .filter(e -> {
+            if (e.getKey().topic().isPresent()) {
+              return e.getKey().topic().get().equals(thisTopic);
+            } else {
+              // this branch shouldn't really be hit since other should be 
multi-topic here, but adding this
+              // just int case.

Review Comment:
   fixed



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