Skip to content

Commit bc374c1

Browse files
fix: Fix case sensitivity in finding struct column
1 parent 5f48191 commit bc374c1

File tree

2 files changed

+7
-4
lines changed
  • google-cloud-spanner/src

2 files changed

+7
-4
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Type.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ public int getFieldIndex(String fieldName) {
472472
Map<String, Integer> tmp = new TreeMap<>();
473473
for (int i = 0; i < getStructFields().size(); ++i) {
474474
Type.StructField field = getStructFields().get(i);
475-
if (tmp.put(field.getName(), i) != null) {
475+
if (tmp.put(field.getName().toLowerCase(), i) != null) {
476476
// Column name appears more than once: mark as ambiguous.
477-
tmp.put(field.getName(), AMBIGUOUS_FIELD);
477+
tmp.put(field.getName().toLowerCase(), AMBIGUOUS_FIELD);
478478
}
479479
}
480480
// Benign race: Java's final field semantics mean that if we see a non-null "fieldsByName",
@@ -485,7 +485,10 @@ public int getFieldIndex(String fieldName) {
485485
fieldsByName = ImmutableMap.copyOf(tmp);
486486
}
487487

488-
Integer index = fieldsByName.get(fieldName);
488+
if (fieldName == null) {
489+
throw new IllegalArgumentException("Field name cannot be null");
490+
}
491+
Integer index = fieldsByName.get(fieldName.toLowerCase());
489492
if (index == null) {
490493
throw new IllegalArgumentException("Field not found: " + fieldName);
491494
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/TypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public void struct() {
522522
assertThat(t.getStructFields().get(2).getType()).isEqualTo(Type.pgNumeric());
523523
assertThat(t.toString()).isEqualTo("STRUCT<f1 INT64, f2 STRING, f3 NUMERIC<PG_NUMERIC>>");
524524
assertThat(t.getFieldIndex("f1")).isEqualTo(0);
525-
assertThat(t.getFieldIndex("f2")).isEqualTo(1);
525+
assertThat(t.getFieldIndex("F2")).isEqualTo(1);
526526
assertThat(t.getFieldIndex("f3")).isEqualTo(2);
527527

528528
assertProtoEquals(

0 commit comments

Comments
 (0)