Skip to content

Commit

Permalink
fix: BQ/proto schema names should be compared lowercase (#1369)
Browse files Browse the repository at this point in the history
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-bigquerystorage/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #1366☕️
  • Loading branch information
stephenjudkins authored Oct 25, 2021
1 parent b56bc5c commit a0da90e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
10 changes: 4 additions & 6 deletions .kokoro/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ function determineMavenOpts() {
| sed -E 's/^(1\.[0-9]\.0).*$/\1/g'
)

case $javaVersion in
"17")
if [[ $javaVersion == 17* ]]
then
# MaxPermSize is no longer supported as of jdk 17
echo -n "-Xmx1024m"
;;
*)
else
echo -n "-Xmx1024m -XX:MaxPermSize=128m"
;;
esac
fi
}

export MAVEN_OPTS=$(determineMavenOpts)
Expand Down
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 testMixedCaseFieldNames() 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");

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

@Test
public void testBigNumericMismatch() throws Exception {
TableFieldSchema field =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,25 @@ 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
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;
}

0 comments on commit a0da90e

Please sign in to comment.