Skip to content

Commit

Permalink
fix: add a DATE type e2e test (#1511)
Browse files Browse the repository at this point in the history
* fix:Add a DATE type test

* fix:Add a DATE type test

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
yirutang and gcf-owl-bot[bot] authored Feb 7, 2022
1 parent 4c532b0 commit 5eaf38e
Showing 1 changed file with 31 additions and 0 deletions.
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

0 comments on commit 5eaf38e

Please sign in to comment.