fqaiser94 commented on code in PR #10351:
URL: https://github.com/apache/iceberg/pull/10351#discussion_r1663397086


##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/channel/Worker.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.iceberg.connect.channel;
+
+import java.time.Duration;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.iceberg.connect.IcebergSinkConfig;
+import org.apache.iceberg.connect.data.Offset;
+import org.apache.iceberg.connect.data.SinkWriter;
+import org.apache.iceberg.connect.data.SinkWriterResult;
+import org.apache.iceberg.connect.events.DataComplete;
+import org.apache.iceberg.connect.events.DataWritten;
+import org.apache.iceberg.connect.events.Event;
+import org.apache.iceberg.connect.events.PayloadType;
+import org.apache.iceberg.connect.events.StartCommit;
+import org.apache.iceberg.connect.events.TableReference;
+import org.apache.iceberg.connect.events.TopicPartitionOffset;
+import org.apache.kafka.connect.sink.SinkRecord;
+import org.apache.kafka.connect.sink.SinkTaskContext;
+
+class Worker extends Channel {
+
+  private final IcebergSinkConfig config;
+  private final SinkTaskContext context;
+  private final SinkWriter sinkWriter;
+
+  Worker(
+      IcebergSinkConfig config,
+      KafkaClientFactory clientFactory,
+      SinkWriter sinkWriter,
+      SinkTaskContext context) {
+    // pass transient consumer group ID to which we never commit offsets
+    super(
+        "worker",
+        IcebergSinkConfig.DEFAULT_CONTROL_GROUP_PREFIX + UUID.randomUUID(),
+        config,
+        clientFactory,
+        context);
+
+    this.config = config;
+    this.context = context;
+    this.sinkWriter = sinkWriter;
+  }
+
+  void process() {
+    consumeAvailable(Duration.ZERO);
+  }
+
+  @Override
+  protected boolean receive(Envelope envelope) {
+    Event event = envelope.event();
+    if (event.payload().type() != PayloadType.START_COMMIT) {
+      return false;
+    }
+
+    SinkWriterResult results = sinkWriter.completeWrite();
+
+    // include all assigned topic partitions even if no messages were read
+    // from a partition, as the coordinator will use that to determine
+    // when all data for a commit has been received
+    List<TopicPartitionOffset> assignments =
+        context.assignment().stream()
+            .map(
+                tp -> {
+                  Offset offset = results.sourceOffsets().get(tp);
+                  if (offset == null) {
+                    offset = Offset.NULL_OFFSET;
+                  }
+                  return new TopicPartitionOffset(
+                      tp.topic(), tp.partition(), offset.offset(), 
offset.timestamp());
+                })
+            .collect(Collectors.toList());
+
+    UUID commitId = ((StartCommit) event.payload()).commitId();
+
+    List<Event> events =
+        results.writerResults().stream()
+            .map(
+                writeResult ->
+                    new Event(
+                        config.connectGroupId(),
+                        new DataWritten(
+                            writeResult.partitionStruct(),
+                            commitId,
+                            TableReference.of(config.catalogName(), 
writeResult.tableIdentifier()),
+                            writeResult.dataFiles(),
+                            writeResult.deleteFiles())))
+            .collect(Collectors.toList());
+
+    Event readyEvent = new Event(config.connectGroupId(), new 
DataComplete(commitId, assignments));
+    events.add(readyEvent);
+
+    send(events, results.sourceOffsets());
+    context.requestCommit();

Review Comment:
   abc



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to