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: add a DATE type e2e test #1511

Merged
merged 5 commits into from
Feb 7, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public static void beforeClass() throws IOException {
com.google.cloud.bigquery.Field.newBuilder(
"test_datetime_micros", StandardSQLTypeName.DATETIME)
.setMode(Mode.REPEATED)
.build(),
com.google.cloud.bigquery.Field.newBuilder(
"test_date_repeated", StandardSQLTypeName.DATE)
.setMode(Mode.REPEATED)
.build(),
com.google.cloud.bigquery.Field.newBuilder(
"test_date", StandardSQLTypeName.DATE)
.setMode(Mode.NULLABLE)
.build())))
.build();
bigquery.create(tableInfo);
Expand Down Expand Up @@ -122,11 +130,25 @@ public void TestTimeEncoding()
.setMode(TableFieldSchema.Mode.REPEATED)
.setName("test_datetime_micros")
.build();
TableFieldSchema TEST_DATE_REPEATED =
TableFieldSchema.newBuilder()
.setType(TableFieldSchema.Type.DATE)
.setMode(TableFieldSchema.Mode.REPEATED)
.setName("test_date_repeated")
.build();
TableFieldSchema TEST_DATE =
TableFieldSchema.newBuilder()
.setType(TableFieldSchema.Type.DATE)
.setMode(TableFieldSchema.Mode.NULLABLE)
.setName("test_date")
.build();
TableSchema tableSchema =
TableSchema.newBuilder()
.addFields(0, TEST_STRING)
.addFields(1, TEST_TIME)
.addFields(2, TEST_DATETIME)
.addFields(3, TEST_DATE_REPEATED)
.addFields(4, TEST_DATE)
.build();
try (JsonStreamWriter jsonStreamWriter =
JsonStreamWriter.newBuilder(parent.toString(), tableSchema).build()) {
Expand Down Expand Up @@ -157,6 +179,8 @@ public void TestTimeEncoding()
CivilTimeEncoder.encodePacked64DatetimeMicros(
LocalDateTime.of(2050, 1, 2, 3, 4, 5, 6_000)),
}));
row.put("test_date_repeated", new JSONArray(new int[] {0, 300, 14238}));
row.put("test_date", 300);
JSONArray jsonArr = new JSONArray(new JSONObject[] {row});
ApiFuture<AppendRowsResponse> response = jsonStreamWriter.append(jsonArr, -1);
Assert.assertFalse(response.get().getAppendResult().hasOffset());
Expand All @@ -179,6 +203,13 @@ public void TestTimeEncoding()
"1995-05-19T10:30:45", currentRow.get(2).getRepeatedValue().get(1).getStringValue());
assertEquals(
"2000-01-01T00:00:00", currentRow.get(2).getRepeatedValue().get(2).getStringValue());

assertEquals("1970-01-01", currentRow.get(3).getRepeatedValue().get(0).getStringValue());
assertEquals("1970-10-28", currentRow.get(3).getRepeatedValue().get(1).getStringValue());
assertEquals("2008-12-25", currentRow.get(3).getRepeatedValue().get(2).getStringValue());

assertEquals("1970-10-28", currentRow.get(4).getStringValue());

assertEquals(
"2026-03-11T05:45:12.009000",
currentRow.get(2).getRepeatedValue().get(3).getStringValue());
Expand Down