This is an automated email from the ASF dual-hosted git repository.

pvary pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 2e847c044a MR: Keep computed block locations in 
IcebergSplit.getLocations (#18036)
2e847c044a is described below

commit 2e847c044a04894882cf2704cbd99e1498431cc1
Author: Eunbin Son <[email protected]>
AuthorDate: Fri Nov 6 21:05:05 2026 +0900

    MR: Keep computed block locations in IcebergSplit.getLocations (#18036)
---
 .../java/org/apache/iceberg/mr/mapreduce/IcebergSplit.java |  7 +++----
 .../org/apache/iceberg/mr/TestIcebergInputFormats.java     | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergSplit.java 
b/mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergSplit.java
index e4aeeaee6d..7295ff79ea 100644
--- a/mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergSplit.java
+++ b/mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergSplit.java
@@ -71,11 +71,10 @@ public class IcebergSplit extends InputSplit
   public String[] getLocations() {
     // The implementation of getLocations() is only meant to be used during 
split computation
     // getLocations() won't be accurate when called on worker nodes and will 
always return "*"
-    if (locations == null && conf != null) {
-      boolean localityPreferred = conf.getBoolean(InputFormatConfig.LOCALITY, 
false);
+    if (locations == null) {
+      boolean localityPreferred =
+          conf != null && conf.getBoolean(InputFormatConfig.LOCALITY, false);
       locations = localityPreferred ? Util.blockLocations(task, conf) : 
ANYWHERE.clone();
-    } else {
-      locations = ANYWHERE.clone();
     }
 
     return locations;
diff --git 
a/mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java 
b/mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java
index 7be03cd7bc..d753863915 100644
--- a/mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java
+++ b/mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java
@@ -380,6 +380,20 @@ public class TestIcebergInputFormats {
     }
   }
 
+  @TestTemplate
+  public void testLocalityIsKeptAcrossCalls() throws Exception {
+    helper.createUnpartitionedTable();
+    List<Record> expectedRecords = helper.generateRandomRecords(1, 0L);
+    helper.appendToTable(null, expectedRecords);
+
+    builder.preferLocality();
+
+    for (InputSplit split : 
testInputFormat.create(builder.conf()).getSplits()) {
+      assertThat(split.getLocations()).containsExactly("localhost");
+      assertThat(split.getLocations()).containsExactly("localhost");
+    }
+  }
+
   @TestTemplate
   public void testCustomCatalog() throws IOException {
     String warehouseLocation = 
temp.resolve("hadoop_catalog").toAbsolutePath().toString();

Reply via email to