From e4712a3bef2436d416ba7a3f11b45c2d21b0324f Mon Sep 17 00:00:00 2001 From: Alexey Avramenko Date: Tue, 8 Jan 2019 22:31:24 +0700 Subject: [PATCH 1/3] Add missing fields to properly list partitioned tables --- .../com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java index 21df417ecc41..70ade809b8ee 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java @@ -276,7 +276,9 @@ public Table apply(TableList.Tables tablePb) { .setId(tablePb.getId()) .setKind(tablePb.getKind()) .setTableReference(tablePb.getTableReference()) - .setType(tablePb.getType()); + .setType(tablePb.getType()) + .setCreationTime(tablePb.getCreationTime()) + .setTimePartitioning(tablePb.getTimePartitioning()); } })); } catch (IOException ex) { From 9189f499a89cba8676e668bad35fe7ed3a874a03 Mon Sep 17 00:00:00 2001 From: Alexey Avramenko Date: Thu, 10 Jan 2019 19:44:09 +0700 Subject: [PATCH 2/3] Add unit test for partitioning info --- .../cloud/bigquery/BigQueryImplTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java index 9b67445acd13..476a6e0cf72c 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java @@ -110,12 +110,24 @@ public class BigQueryImplTest { StandardTableDefinition.of(TABLE_SCHEMA); private static final ModelTableDefinition MODEL_TABLE_DEFINITION = ModelTableDefinition.newBuilder().build(); + private static final Long EXPIRATION_MS = 86400000L; + private static final Long TABLE_CREATION_TIME = 1546275600000L; + private static final TimePartitioning TIME_PARTITIONING = TimePartitioning.of(TimePartitioning.Type.DAY, EXPIRATION_MS); + private static final StandardTableDefinition TABLE_DEFINITION_WITH_PARTITIONING = + StandardTableDefinition.newBuilder() + .setSchema(TABLE_SCHEMA) + .setTimePartitioning(TIME_PARTITIONING) + .build(); private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_DEFINITION); private static final TableInfo OTHER_TABLE_INFO = TableInfo.of(OTHER_TABLE_ID, TABLE_DEFINITION); private static final TableInfo TABLE_INFO_WITH_PROJECT = TableInfo.of(TABLE_ID_WITH_PROJECT, TABLE_DEFINITION); private static final TableInfo MODEL_TABLE_INFO_WITH_PROJECT = TableInfo.of(TABLE_ID_WITH_PROJECT, MODEL_TABLE_DEFINITION); + private static final TableInfo TABLE_INFO_WITH_PARTITIONS = + TableInfo.newBuilder(TABLE_ID, TABLE_DEFINITION_WITH_PARTITIONING) + .setCreationTime(TABLE_CREATION_TIME) + .build(); private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION = LoadJobConfiguration.of(TABLE_ID, "URI"); private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION_WITH_PROJECT = @@ -714,6 +726,21 @@ public void testListTablesWithOptions() { assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); } + @Test + public void testListTablesReturnedParameters() { + bigquery = options.getService(); + ImmutableList tableList = + ImmutableList.of(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS))); + Tuple> result = + Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); + EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) + .andReturn(result); + EasyMock.replay(bigqueryRpcMock); + Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); + assertEquals(CURSOR, page.getNextPageToken()); + assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + } + @Test public void testDeleteTable() { EasyMock.expect(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).andReturn(true); From c339196427ccd0c0bb702eb11a768cfafa84316d Mon Sep 17 00:00:00 2001 From: Alexey Avramenko Date: Thu, 14 Feb 2019 10:18:45 +0800 Subject: [PATCH 3/3] Fix formatting --- .../cloud/bigquery/BigQueryImplTest.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java index 476a6e0cf72c..9aa788ec6761 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java @@ -112,7 +112,8 @@ public class BigQueryImplTest { ModelTableDefinition.newBuilder().build(); private static final Long EXPIRATION_MS = 86400000L; private static final Long TABLE_CREATION_TIME = 1546275600000L; - private static final TimePartitioning TIME_PARTITIONING = TimePartitioning.of(TimePartitioning.Type.DAY, EXPIRATION_MS); + private static final TimePartitioning TIME_PARTITIONING = + TimePartitioning.of(TimePartitioning.Type.DAY, EXPIRATION_MS); private static final StandardTableDefinition TABLE_DEFINITION_WITH_PARTITIONING = StandardTableDefinition.newBuilder() .setSchema(TABLE_SCHEMA) @@ -726,20 +727,21 @@ public void testListTablesWithOptions() { assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); } - @Test - public void testListTablesReturnedParameters() { - bigquery = options.getService(); - ImmutableList
tableList = - ImmutableList.of(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS))); - Tuple> result = - Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); - Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); - assertEquals(CURSOR, page.getNextPageToken()); - assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); - } + @Test + public void testListTablesReturnedParameters() { + bigquery = options.getService(); + ImmutableList
tableList = + ImmutableList.of( + new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS))); + Tuple> result = + Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); + EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) + .andReturn(result); + EasyMock.replay(bigqueryRpcMock); + Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); + assertEquals(CURSOR, page.getNextPageToken()); + assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + } @Test public void testDeleteTable() {