Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ public int getFieldIndex(String fieldName) {
Map<String, Integer> tmp = new TreeMap<>();
for (int i = 0; i < getStructFields().size(); ++i) {
Type.StructField field = getStructFields().get(i);
if (tmp.put(field.getName(), i) != null) {
if (tmp.put(field.getName().toLowerCase(), i) != null) {
// Column name appears more than once: mark as ambiguous.
tmp.put(field.getName(), AMBIGUOUS_FIELD);
tmp.put(field.getName().toLowerCase(), AMBIGUOUS_FIELD);
}
}
// Benign race: Java's final field semantics mean that if we see a non-null "fieldsByName",
Expand All @@ -485,7 +485,10 @@ public int getFieldIndex(String fieldName) {
fieldsByName = ImmutableMap.copyOf(tmp);
}

Integer index = fieldsByName.get(fieldName);
if (fieldName == null) {
throw new IllegalArgumentException("Field name cannot be null");
}
Integer index = fieldsByName.get(fieldName.toLowerCase());
if (index == null) {
throw new IllegalArgumentException("Field not found: " + fieldName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void struct() {
assertThat(t.getStructFields().get(2).getType()).isEqualTo(Type.pgNumeric());
assertThat(t.toString()).isEqualTo("STRUCT<f1 INT64, f2 STRING, f3 NUMERIC<PG_NUMERIC>>");
assertThat(t.getFieldIndex("f1")).isEqualTo(0);
assertThat(t.getFieldIndex("f2")).isEqualTo(1);
assertThat(t.getFieldIndex("F2")).isEqualTo(1);
assertThat(t.getFieldIndex("f3")).isEqualTo(2);

assertProtoEquals(
Expand Down