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

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
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
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
Expand Up @@ -574,6 +574,24 @@ public void testBigNumericMismatch() throws Exception {
}
}

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

JSONObject json = new JSONObject();
json.put("fooBar", "hello");

DynamicMessage protoMsg = com.google.cloud.bigquery.storage.v1.JsonToProtoMessage.convertJsonToProtoMessage(
TestMixedCaseFieldNames.getDescriptor(), tableSchema, json
);

}

@Test
public void testDouble() throws Exception {
TestDouble expectedProto = TestDouble.newBuilder().setDouble(1.2).setFloat(3.4f).build();
Expand Down
4 changes: 4 additions & 0 deletions google-cloud-bigquerystorage/src/test/proto/jsonTest.proto
Expand Up @@ -156,3 +156,7 @@ message TestNumeric {
message TestBignumeric {
repeated bytes bignumeric = 1;
}

message TestMixedCaseFieldNames {
required string foobar = 1;
}