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 e4aeeaee6d3f..7295ff79ea94 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 long getLength() { 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 ce588a7e83e2..ad63b0b58c35 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java +++ b/mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java @@ -326,6 +326,8 @@ public void testLocality() throws Exception { for (InputSplit split : testInputFormat.create(builder.conf()).getSplits()) { assertThat(split.getLocations()).containsExactly("localhost"); + // repeated calls must return the same locations that were computed and cached above + assertThat(split.getLocations()).containsExactly("localhost"); } }