Skip to content

Commit

Permalink
apache#10668 - Support case-insensitivity for column names in Partiti…
Browse files Browse the repository at this point in the history
…onSpec

Make PartitionSpec.Builder search for columns in a case-insensitive way, i.e. `"COLUMN_1" == "column_1"`
  • Loading branch information
sl255051 committed Jul 10, 2024
1 parent 1f6ff6c commit 486075c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/apache/iceberg/PartitionSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Builder checkConflicts(boolean check) {
}

private void checkAndAddPartitionName(String name, Integer sourceColumnId) {
Types.NestedField schemaField = schema.findField(name);
Types.NestedField schemaField = schema.caseInsensitiveFindField(name);
if (checkConflicts) {
if (sourceColumnId != null) {
// for identity transform case we allow conflicts between partition and schema field name
Expand Down Expand Up @@ -433,7 +433,7 @@ public Builder withSpecId(int newSpecId) {
}

private Types.NestedField findSourceColumn(String sourceName) {
Types.NestedField sourceColumn = schema.findField(sourceName);
Types.NestedField sourceColumn = schema.caseInsensitiveFindField(sourceName);
Preconditions.checkArgument(
sourceColumn != null, "Cannot find source column: %s", sourceName);
return sourceColumn;
Expand Down
16 changes: 14 additions & 2 deletions core/src/test/java/org/apache/iceberg/TestPartitionSpecInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,20 @@ public void testSpecInfoPartitionedTable() {
assertThat(table.spec()).isEqualTo(spec);
assertThat(table.spec().lastAssignedFieldId()).isEqualTo(spec.lastAssignedFieldId());
assertThat(table.specs())
.containsExactly(entry(spec.specId(), spec))
.doesNotContainKey(Integer.MAX_VALUE);
.containsExactly(entry(spec.specId(), spec))
.doesNotContainKey(Integer.MAX_VALUE);
}

@TestTemplate
public void testSpecInfoPartitionedTableCaseInsensitive() {
PartitionSpec spec = PartitionSpec.builderFor(schema).identity("DATA").build();
TestTables.TestTable table = TestTables.create(tableDir, "test", schema, spec, formatVersion);

assertThat(table.spec()).isEqualTo(spec);
assertThat(table.spec().lastAssignedFieldId()).isEqualTo(spec.lastAssignedFieldId());
assertThat(table.specs())
.containsExactly(entry(spec.specId(), spec))
.doesNotContainKey(Integer.MAX_VALUE);
}

@TestTemplate
Expand Down

0 comments on commit 486075c

Please sign in to comment.