RussellSpitzer commented on code in PR #14948:
URL: https://github.com/apache/iceberg/pull/14948#discussion_r3983706337


##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestMergingSortedRowDataReader.java:
##########
@@ -0,0 +1,802 @@
+/*
+ * 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.spark.source;
+
+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 static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import org.apache.iceberg.BaseScanTaskGroup;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DataFiles;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.ScanTaskGroup;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableUtil;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.data.FileHelpers;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.spark.TestBase;
+import org.apache.iceberg.transforms.Transform;
+import org.apache.iceberg.transforms.Transforms;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.Pair;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mockito;
+
+class TestMergingSortedRowDataReader extends TestBase {
+
+  private static final Schema SCHEMA =
+      new Schema(
+          required(1, "id", Types.IntegerType.get()), required(2, "data", 
Types.StringType.get()));
+
+  private static final PartitionSpec SPEC = PartitionSpec.unpartitioned();
+
+  private Table table;
+
+  @TempDir private Path temp;
+
+  @BeforeEach
+  void before() {
+    table = catalog.createTable(TableIdentifier.of("default", 
"test_merging_reader"), SCHEMA, SPEC);
+    table.replaceSortOrder().asc("id").commit();
+  }
+
+  @AfterEach
+  void after() {
+    catalog.dropTable(TableIdentifier.of("default", "test_merging_reader"));
+  }
+
+  @Test
+  void mergeTwoSortedFiles() throws IOException {
+    DataFile file1 = writeDataFile(record(1, "a"), record(3, "c"), record(5, 
"e"));
+    DataFile file2 = writeDataFile(record(2, "b"), record(4, "d"), record(6, 
"f"));
+
+    table.newAppend().appendFile(file1).appendFile(file2).commit();
+
+    List<InternalRow> rows = readMerged(table);
+
+    assertThat(extractIds(rows)).containsExactly(1, 2, 3, 4, 5, 6);
+  }
+
+  @Test
+  void mergeWithDuplicateKeys() throws IOException {
+    DataFile file1 = writeDataFile(record(1, "a"), record(2, "b"));
+    DataFile file2 = writeDataFile(record(1, "c"), record(2, "d"));
+    DataFile file3 = writeDataFile(record(1, "e"), record(3, "f"));
+
+    
table.newAppend().appendFile(file1).appendFile(file2).appendFile(file3).commit();
+
+    List<InternalRow> rows = readMerged(table);
+
+    assertThat(extractIds(rows)).containsExactly(1, 1, 1, 2, 2, 3);
+  }
+
+  @Test
+  void mergeDescendingOrder() throws IOException {
+    catalog.dropTable(TableIdentifier.of("default", "test_merging_reader"));
+    table = catalog.createTable(TableIdentifier.of("default", 
"test_merging_reader"), SCHEMA, SPEC);
+    table.replaceSortOrder().desc("id").commit();
+
+    DataFile file1 = writeDataFile(record(6, "f"), record(4, "d"));
+    DataFile file2 = writeDataFile(record(5, "e"), record(3, "c"), record(1, 
"a"));
+
+    table.newAppend().appendFile(file1).appendFile(file2).commit();
+
+    List<InternalRow> rows = readMerged(table);
+
+    assertThat(extractIds(rows)).containsExactly(6, 5, 4, 3, 1);
+  }
+
+  @Test
+  void mergeWithNulls() throws IOException {
+    Schema nullableSchema =
+        new Schema(
+            Types.NestedField.optional(1, "id", Types.IntegerType.get()),
+            required(2, "data", Types.StringType.get()));
+
+    catalog.dropTable(TableIdentifier.of("default", "test_merging_reader"));

Review Comment:
   Yeah doesn't feel right that we are dropping and recreating the default 
table. I'd either change the schema or just parameterize create and destroy 
table.
   
   createTable() // default name and schema
   createTable(Schema foo) // default name and custom schema
   
   Then on afterEach
   
   just drop default name table



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