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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,12 @@ private 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, val);
return;
Expand Down Expand Up @@ -908,6 +914,12 @@ private 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, val);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,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.INSTANCE.convertToProtoMessage(
TestDate.getDescriptor(), tableSchema, json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ message TestRepeatedTimestamp {
message TestDate {
optional int32 test_string = 1;
optional int32 test_long = 2;
optional string test_iso_string = 3;
}

message NestedRepeated {
Expand Down
Loading