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

feat(datestrings): Allow string dates, closes #1765 #1916

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.1.5')
implementation platform('com.google.cloud:libraries-bom:26.2.0')

implementation 'com.google.cloud:google-cloud-bigquerystorage'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ private static void fillField(
}
break;
case STRING:
if (fieldSchema != null && fieldSchema.getType() == TableFieldSchema.Type.DATE) {
if (val instanceof String) {
protoMsg.setField(fieldDescriptor, (String) val);
return;
}
}
if (val instanceof String) {
protoMsg.setField(fieldDescriptor, (String) val);
return;
Expand Down Expand Up @@ -710,6 +716,12 @@ private static void fillRepeatedField(
}
break;
case STRING:
if (fieldSchema != null && fieldSchema.getType() == TableFieldSchema.Type.DATE) {
if (val instanceof String) {
protoMsg.setField(fieldDescriptor, (String) val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be repeated field?

return;
}
}
if (val instanceof String) {
protoMsg.addRepeatedField(fieldDescriptor, (String) val);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,18 @@ public void testDate() throws Exception {
TableSchema.newBuilder()
.addFields(TableFieldSchema.newBuilder(TEST_DATE).setName("test_string").build())
.addFields(TableFieldSchema.newBuilder(TEST_DATE).setName("test_long").build())
.addFields(TableFieldSchema.newBuilder(TEST_DATE).setName("test_iso_string").build())
.build();
TestDate expectedProto =
TestDate.newBuilder()
.setTestString(18935)
.setTestLong(18935)
.setTestIsoString("1999-01-01")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for repeated field.

.build();
TestDate expectedProto = TestDate.newBuilder().setTestString(18935).setTestLong(18935).build();
JSONObject json = new JSONObject();
json.put("test_string", "2021-11-04");
json.put("test_long", 18935L);
json.put("test_iso_string", "1999-01-01");
DynamicMessage protoMsg =
JsonToProtoMessage.convertJsonToProtoMessage(TestDate.getDescriptor(), tableSchema, json);
assertEquals(expectedProto, protoMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ message TestTimestamp {
message TestDate {
optional int32 test_string = 1;
optional int32 test_long = 2;
optional string test_iso_string = 3;
}

message NestedRepeated {
Expand Down