pvary commented on code in PR #14435:
URL: https://github.com/apache/iceberg/pull/14435#discussion_r2675628338


##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/actions/TestSparkParquetFileMergeRunner.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.actions;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.Collections;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.actions.RewriteFileGroup;
+import org.apache.iceberg.hadoop.HadoopTables;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.spark.TestBase;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+public class TestSparkParquetFileMergeRunner extends TestBase {
+
+  private static final HadoopTables TABLES = new HadoopTables(new 
Configuration());
+  private static final Schema SCHEMA =
+      new Schema(
+          optional(1, "c1", Types.IntegerType.get()),
+          optional(2, "c2", Types.StringType.get()),
+          optional(3, "c3", Types.StringType.get()));
+
+  @TempDir private File tableDir;
+  private String tableLocation;
+
+  @BeforeEach
+  public void setupTableLocation() {
+    this.tableLocation = tableDir.toURI().toString();
+  }
+
+  @Test
+  public void testCanMergeAndGetSchemaReturnsFalseForSortedTable() {
+    // Create a table with a sort order
+    Table table = TABLES.create(SCHEMA, tableLocation);
+    table.updateProperties().set("write.metadata.metrics.default", 
"full").commit();
+    table
+        .replaceSortOrder()
+        .asc("c1") // Sort by column c1 in ascending order
+        .commit();
+
+    // Verify the table has a sort order
+    assertThat(table.sortOrder().isSorted()).isTrue();
+
+    // Create a mock RewriteFileGroup with Parquet files but no deletes
+    RewriteFileGroup group = mock(RewriteFileGroup.class);
+    DataFile parquetFile1 = mock(DataFile.class);
+
+    when(parquetFile1.format()).thenReturn(FileFormat.PARQUET);
+    when(parquetFile1.specId()).thenReturn(0);
+    when(parquetFile1.fileSizeInBytes()).thenReturn(100L);
+    when(parquetFile1.path()).thenReturn(tableLocation + 
"/data/file1.parquet");
+    when(group.rewrittenFiles()).thenReturn(Sets.newHashSet(parquetFile1));
+    when(group.expectedOutputFiles()).thenReturn(1);
+    when(group.maxOutputFileSize()).thenReturn(Long.MAX_VALUE);
+    when(group.fileScanTasks()).thenReturn(Collections.emptyList());

Review Comment:
   This is more like a question:
   - In other tests we create Data files, and Tasks instead of mocks? We have 
several occasions where we had issues with mocks, so we try to avoid them, or 
limit the place where we use them as much as possible.
   
   Maybe something like `FileGenerationUtil.generateDataFile`, or 
`TestBase.FILE_A` for files?
   Also for the tasks we might be able to use `MockFileScanTask.mockTask`?
   We could also create real `RewriteFileGroup` objects instead of mocks
   
   
   



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