Skip to content

Commit 92ae3d9

Browse files
authored
Core: Fix failure when not finding a column during time travel (#14438)
1 parent a99dc4f commit 92ae3d9

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

core/src/main/java/org/apache/iceberg/SnapshotScan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected Map<Integer, PartitionSpec> specs() {
9595
ImmutableMap.Builder<Integer, PartitionSpec> newSpecs =
9696
ImmutableMap.builderWithExpectedSize(specs.size());
9797
for (Map.Entry<Integer, PartitionSpec> entry : specs.entrySet()) {
98-
newSpecs.put(entry.getKey(), entry.getValue().toUnbound().bind(snapshotSchema));
98+
newSpecs.put(entry.getKey(), entry.getValue().toUnbound().bind(snapshotSchema, true));
9999
}
100100

101101
return newSpecs.build();

core/src/test/java/org/apache/iceberg/TestScansAndSchemaEvolution.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,45 @@ public void testPartitionSourceRename() throws IOException {
134134
assertThat(tasks).hasSize(1);
135135
}
136136

137+
@TestTemplate
138+
public void testPartitionSourceAdd() throws IOException {
139+
Table table = TestTables.create(temp, "test", SCHEMA, SPEC, formatVersion);
140+
141+
DataFile fileOne = createDataFile("one");
142+
DataFile fileTwo = createDataFile("two");
143+
144+
table.newAppend().appendFile(fileOne).appendFile(fileTwo).commit();
145+
long firstSnapshotId = table.currentSnapshot().snapshotId();
146+
147+
List<FileScanTask> tasks =
148+
Lists.newArrayList(table.newScan().filter(Expressions.equal("part", "one")).planFiles());
149+
150+
assertThat(tasks).hasSize(1);
151+
152+
// add a new partition column
153+
table.updateSchema().addColumn("hour", Types.IntegerType.get()).commit();
154+
table.updateSpec().addField("hour").commit();
155+
156+
// plan the scan using the new column in a filter
157+
tasks = Lists.newArrayList(table.newScan().filter(Expressions.isNull("hour")).planFiles());
158+
159+
assertThat(tasks).hasSize(2);
160+
161+
// create a new commit
162+
table.newAppend().appendFile(createDataFile("three")).commit();
163+
164+
// plan the scan using the existing column in a filter
165+
tasks =
166+
Lists.newArrayList(
167+
table
168+
.newScan()
169+
.useSnapshot(firstSnapshotId)
170+
.filter(Expressions.equal("part", "one"))
171+
.planFiles());
172+
173+
assertThat(tasks).hasSize(1);
174+
}
175+
137176
@TestTemplate
138177
public void testPartitionSourceDrop() throws IOException {
139178
Table table = TestTables.create(temp, "test", SCHEMA, SPEC, formatVersion);
@@ -179,6 +218,37 @@ public void testPartitionSourceDrop() throws IOException {
179218
.collect(Collectors.toList()));
180219
}
181220

221+
@TestTemplate
222+
public void testColumnAdd() throws IOException {
223+
Table table = TestTables.create(temp, "test", SCHEMA, SPEC, formatVersion);
224+
225+
DataFile fileOne = createDataFile("one");
226+
DataFile fileTwo = createDataFile("two");
227+
228+
table.newAppend().appendFile(fileOne).appendFile(fileTwo).commit();
229+
long firstSnapshotId = table.currentSnapshot().snapshotId();
230+
231+
table.updateSchema().addColumn("hour", Types.IntegerType.get()).commit();
232+
233+
DataFile fileThree = createDataFile("three", table.schema(), table.spec());
234+
table.newAppend().appendFile(fileThree).commit();
235+
236+
// plan the scan using the new column in a filter
237+
List<FileScanTask> tasks =
238+
Lists.newArrayList(table.newScan().filter(Expressions.isNull("hour")).planFiles());
239+
assertThat(tasks).hasSize(3);
240+
241+
// plan the scan using the existing column in a filter
242+
tasks =
243+
Lists.newArrayList(
244+
table
245+
.newScan()
246+
.useSnapshot(firstSnapshotId)
247+
.filter(Expressions.equal("data", "xyz"))
248+
.planFiles());
249+
assertThat(tasks).hasSize(2);
250+
}
251+
182252
@TestTemplate
183253
public void testColumnRename() throws IOException {
184254
Table table = TestTables.create(temp, "test", SCHEMA, SPEC, formatVersion);

0 commit comments

Comments
 (0)