You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/01/21 17:07:32 UTC

[GitHub] [iceberg] rdblue commented on a change in pull request #3865: Flink: SplitRecords for a batch of records for a single file; RecordAndPosi…

rdblue commented on a change in pull request #3865:
URL: https://github.com/apache/iceberg/pull/3865#discussion_r789846685



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/SplitRecords.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.flink.source.reader;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
+import org.apache.iceberg.io.CloseableIterator;
+
+/**
+ * A batch of records for one split
+ */
+@Internal
+public class SplitRecords<T> implements RecordsWithSplitIds<RecordAndPosition<T>> {
+  @Nullable
+  private final CloseableIterator<RecordAndPosition<T>> recordsForSplit;
+  private final Set<String> finishedSplits;
+
+  @Nullable
+  private String splitId;
+  @Nullable
+  private CloseableIterator<RecordAndPosition<T>> recordsForSplitCurrent;
+
+  private SplitRecords(
+      @Nullable String splitId,
+      @Nullable CloseableIterator<RecordAndPosition<T>> recordsForSplit,
+      Set<String> finishedSplits) {
+
+    this.splitId = splitId;
+    this.recordsForSplit = recordsForSplit;
+    this.finishedSplits = finishedSplits;
+  }
+
+  @Nullable
+  @Override
+  public String nextSplit() {
+    // move the split one (from current value to null)
+    String nextSplit = this.splitId;
+    this.splitId = null;
+
+    // move the iterator, from null to value (if first move) or to null (if second move)
+    this.recordsForSplitCurrent = nextSplit != null ? this.recordsForSplit : null;
+
+    return nextSplit;
+  }
+
+  @Nullable
+  @Override
+  public RecordAndPosition<T> nextRecordFromSplit() {
+    if (recordsForSplitCurrent != null) {
+      return recordsForSplitCurrent.next();
+    } else {
+      throw new IllegalStateException();
+    }
+  }
+
+  @Override
+  public void recycle() {
+    if (recordsForSplit != null) {
+      try {
+        recordsForSplit.close();
+      } catch (IOException e) {
+        throw new RuntimeException("Failed to close the record batch");

Review comment:
       This should be `UncheckedIOException` instead of a generic `RuntimeException`.




-- 
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-unsubscribe@iceberg.apache.org

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



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