nastra commented on code in PR #9308: URL: https://github.com/apache/iceberg/pull/9308#discussion_r1432603265
########## flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/TestIcebergSourceSplitReader.java: ########## @@ -0,0 +1,170 @@ +/* + * 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 static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.connector.base.source.reader.splitreader.SplitsAddition; +import org.apache.flink.connector.testutils.source.reader.TestingReaderContext; +import org.apache.flink.table.data.RowData; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.Schema; +import org.apache.iceberg.data.GenericAppenderFactory; +import org.apache.iceberg.data.RandomGenericData; +import org.apache.iceberg.data.Record; +import org.apache.iceberg.encryption.PlaintextEncryptionManager; +import org.apache.iceberg.flink.source.split.IcebergSourceSplit; +import org.apache.iceberg.flink.source.split.SplitComparators; +import org.apache.iceberg.hadoop.HadoopFileIO; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.util.concurrent.MoreExecutors; +import org.apache.iceberg.types.Types; +import org.awaitility.Awaitility; +import org.awaitility.core.ConditionTimeoutException; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class TestIcebergSourceSplitReader { + @ClassRule public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); Review Comment: I don't think we need `GenAppenderHelper` from #9185. I've just checked and the below diff should make this work with JUnit5: ``` diff --git a/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/ReaderUtil.java b/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/ReaderUtil.java index bbf328da5..29a3b6d6e 100644 --- a/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/ReaderUtil.java +++ b/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/ReaderUtil.java @@ -20,6 +20,7 @@ package org.apache.iceberg.flink.source.reader; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import org.apache.flink.table.data.RowData; @@ -124,6 +125,27 @@ public class ReaderUtil { return new BaseCombinedScanTask(fileTasks); } + public static CombinedScanTask createCombinedScanTask( + List<List<Record>> recordBatchList, + Path temporaryFolder, + FileFormat fileFormat, + GenericAppenderFactory appenderFactory) + throws IOException { + List<FileScanTask> fileTasks = Lists.newArrayListWithCapacity(recordBatchList.size()); + + for (List<Record> recordBatch : recordBatchList) { + FileScanTask fileTask = + ReaderUtil.createFileTask( + recordBatch, + File.createTempFile("tmp", null, temporaryFolder.toFile()), + fileFormat, + appenderFactory); + fileTasks.add(fileTask); + } + + return new BaseCombinedScanTask(fileTasks); + } + public static IcebergSourceSplit createSplit( List<List<Record>> records, TemporaryFolder temporaryFolder, @@ -136,4 +158,17 @@ public class ReaderUtil { throw new RuntimeException("Split creation exception", e); } } + + public static IcebergSourceSplit createSplit( + List<List<Record>> records, + Path temporaryFolder, + FileFormat fileFormat, + GenericAppenderFactory appenderFactory) { + try { + return IcebergSourceSplit.fromCombinedScanTask( + ReaderUtil.createCombinedScanTask(records, temporaryFolder, fileFormat, appenderFactory)); + } catch (IOException e) { + throw new RuntimeException("Split creation exception", e); + } + } ``` ``` diff --git a/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/TestIcebergSourceSplitReader.java b/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/TestIcebergSourceSplitReader.java index 9e0f60da3..61031325c 100644 --- a/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/TestIcebergSourceSplitReader.java +++ b/flink/v1.18/flink/src/test/java/org/apache/iceberg/flink/source/reader/TestIcebergSourceSplitReader.java @@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutorService; @@ -48,12 +49,11 @@ import org.apache.iceberg.relocated.com.google.common.util.concurrent.MoreExecut import org.apache.iceberg.types.Types; import org.awaitility.Awaitility; import org.awaitility.core.ConditionTimeoutException; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class TestIcebergSourceSplitReader { - @ClassRule public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); + @TempDir private Path temp; private static final Schema SCHEMA = new Schema(required(1, "timestamp_column", Types.TimestampType.withoutZone())); @@ -68,7 +68,7 @@ public class TestIcebergSourceSplitReader { RandomGenericData.generate(SCHEMA, 2, 0L), RandomGenericData.generate(SCHEMA, 3, 1L)); IcebergSourceSplit split = - ReaderUtil.createSplit(records, TEMPORARY_FOLDER, FileFormat.PARQUET, APPENDER_FACTORY); + ReaderUtil.createSplit(records, temp, FileFormat.PARQUET, APPENDER_FACTORY); // Add the new split to the reader reader.handleSplitsChanges(new SplitsAddition<>(ImmutableList.of(split))); @@ -100,7 +100,7 @@ public class TestIcebergSourceSplitReader { ImmutableList.of( RandomGenericData.generate(SCHEMA, 2, 0L), RandomGenericData.generate(SCHEMA, 3, 1L)); IcebergSourceSplit split = - ReaderUtil.createSplit(records, TEMPORARY_FOLDER, FileFormat.PARQUET, APPENDER_FACTORY); + ReaderUtil.createSplit(records, temp, FileFormat.PARQUET, APPENDER_FACTORY); ``` -- 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]
