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) { 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 8ee3bac25e55..c69eb2532506 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 @@ -111,12 +111,25 @@ 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 = @@ -721,6 +734,22 @@ public void testListTables() { 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 testListTablesFromDatasetId() { bigquery = options.getService(); diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index c7fe1ee35c75..e852cfc8a276 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -111,6 +111,7 @@ public class ITBigQueryTest { private static final byte[] BYTES = {0xD, 0xE, 0xA, 0xD}; private static final String BYTES_BASE64 = BaseEncoding.base64().encode(BYTES); + private static final Long EXPIRATION_MS = 86400000L; private static final Logger LOG = Logger.getLogger(ITBigQueryTest.class.getName()); private static final String DATASET = RemoteBigQueryHelper.generateDatasetName(); private static final String DESCRIPTION = "Test dataset"; @@ -607,6 +608,39 @@ public void testListTables() { assertTrue(createdTable.delete()); } + @Test + public void testListTablesWithPartitioning() { + String tableName = "test_list_tables_partitioning"; + TimePartitioning timePartitioning = TimePartitioning.of(Type.DAY, EXPIRATION_MS); + StandardTableDefinition tableDefinition = + StandardTableDefinition.newBuilder() + .setSchema(TABLE_SCHEMA) + .setTimePartitioning(timePartitioning) + .build(); + TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); + Table createdPartitioningTable = bigquery.create(tableInfo); + assertNotNull(createdPartitioningTable); + try { + Page
tables = bigquery.listTables(DATASET); + boolean found = false; + Iterator
tableIterator = tables.getValues().iterator(); + while (tableIterator.hasNext() && !found) { + StandardTableDefinition standardTableDefinition = tableIterator.next().getDefinition(); + if (standardTableDefinition.getTimePartitioning() != null + && standardTableDefinition.getTimePartitioning().getType().equals(Type.DAY) + && standardTableDefinition + .getTimePartitioning() + .getExpirationMs() + .equals(EXPIRATION_MS)) { + found = true; + } + } + assertTrue(found); + } finally { + createdPartitioningTable.delete(); + } + } + @Test public void testUpdateTable() { String tableName = "test_update_table";