Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: BQ/proto schema names should be compared lowercase #1369

Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static DynamicMessage convertJsonToProtoMessageImpl(
if (tableSchema != null) {
// protoSchema is generated from tableSchema so their field ordering should match.
fieldSchema = tableSchema.get(field.getIndex());
if (!fieldSchema.getName().equals(field.getName())) {
if (!fieldSchema.getName().toLowerCase().equals(field.getName())) {
throw new ValidationException(
"Field at index "
+ field.getIndex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static DynamicMessage convertJsonToProtoMessageImpl(
if (tableSchema != null) {
// protoSchema is generated from tableSchema so their field ordering should match.
fieldSchema = tableSchema.get(field.getIndex());
if (!fieldSchema.getName().equals(field.getName())) {
if (!fieldSchema.getName().toLowerCase().equals(field.getName())) {
throw new ValidationException(
"Field at index "
+ field.getIndex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,24 @@ public void testNumericMismatch() throws Exception {
}
}

@Test public void testMixedCasedFieldNames() throws Exception {
TableFieldSchema field = TableFieldSchema
.newBuilder()
.setName("fooBar")
.setType(TableFieldSchema.Type.STRING)
.setMode(TableFieldSchema.Mode.NULLABLE)
.build();
TableSchema tableSchema = TableSchema.newBuilder().addFields(field).build();

JSONObject json = new JSONObject();
json.put("fooBar", "hello");
stephaniewang526 marked this conversation as resolved.
Show resolved Hide resolved

DynamicMessage protoMsg = JsonToProtoMessage.convertJsonToProtoMessage(
TestMixedCaseFieldNames.getDescriptor(), tableSchema, json
);

}

@Test
public void testBigNumericMismatch() throws Exception {
TableFieldSchema field =
Expand Down
4 changes: 4 additions & 0 deletions google-cloud-bigquerystorage/src/test/proto/jsonTest.proto
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ message TestNumeric {
message TestBignumeric {
repeated bytes bignumeric = 1;
}

message TestMixedCaseFieldNames {
required string foobar = 1;
}