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

BigQuery: Added missing partitioned fields to listTables. #4701

Merged
merged 3 commits into from
Mar 20, 2019
Merged
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 @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -721,6 +734,22 @@ public void testListTables() {
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

@Test
public void testListTablesReturnedParameters() {
bigquery = options.getService();
ImmutableList<Table> tableList =
ImmutableList.of(
new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS)));
Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> 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<Table> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<Table> tables = bigquery.listTables(DATASET);
boolean found = false;
Iterator<Table> 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";
Expand Down