Skip to content
Permalink
Browse files
fix: BQ/proto schema names should be compared lowercase (#1369)
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 committed Oct 25, 2021
1 parent b56bc5c commit a0da90e8de89c5b9ef77183fee86e1e1a7389e00
@@ -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)
@@ -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()
@@ -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()
@@ -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 =
@@ -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();
@@ -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.