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

feat: add range partitioning field to tableslist #114

Merged
merged 1 commit into from Jan 17, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -299,7 +299,8 @@ public Table apply(TableList.Tables tablePb) {
.setTableReference(tablePb.getTableReference())
.setType(tablePb.getType())
.setCreationTime(tablePb.getCreationTime())
.setTimePartitioning(tablePb.getTimePartitioning());
.setTimePartitioning(tablePb.getTimePartitioning())
.setRangePartitioning(tablePb.getRangePartitioning());
}
}));
} catch (IOException ex) {
Expand Down
Expand Up @@ -121,6 +121,17 @@ public class BigQueryImplTest {
.setSchema(TABLE_SCHEMA)
.setTimePartitioning(TIME_PARTITIONING)
.build();
private static final RangePartitioning.Range RANGE =
RangePartitioning.Range.newBuilder().setStart(1L).setInterval(2L).setEnd(10L).build();
private static final RangePartitioning RANGE_PARTITIONING =
RangePartitioning.newBuilder().setField("IntegerField").setRange(RANGE).build();
private static final StandardTableDefinition TABLE_DEFINITION_WITH_RANGE_PARTITIONING =
StandardTableDefinition.newBuilder()
.setSchema(TABLE_SCHEMA)
.setRangePartitioning(RANGE_PARTITIONING)
.build();
private static final TableInfo TABLE_INFO_RANGE_PARTITIONING =
TableInfo.of(TABLE_ID, TABLE_DEFINITION_WITH_RANGE_PARTITIONING);
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 =
Expand Down Expand Up @@ -901,6 +912,22 @@ public void testListTablesReturnedParameters() {
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

@Test
public void testListTablesWithRangePartitioning() {
bigquery = options.getService();
ImmutableList<Table> tableList =
ImmutableList.of(
new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_RANGE_PARTITIONING)));
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
Expand Up @@ -712,6 +712,36 @@ public void testListTablesWithPartitioning() {
}
}

@Test
public void testListTablesWithRangePartitioning() {
String tableName = "test_list_tables_range_partitioning";
StandardTableDefinition tableDefinition =
StandardTableDefinition.newBuilder()
.setSchema(TABLE_SCHEMA)
.setRangePartitioning(RANGE_PARTITIONING)
.build();
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
Table createdRangePartitioningTable = bigquery.create(tableInfo);
assertNotNull(createdRangePartitioningTable);
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.getRangePartitioning() != null) {
assertEquals(RANGE_PARTITIONING, standardTableDefinition.getRangePartitioning());
assertEquals(RANGE, standardTableDefinition.getRangePartitioning().getRange());
assertEquals("IntegerField", standardTableDefinition.getRangePartitioning().getField());
found = true;
}
}
assertTrue(found);
} finally {
createdRangePartitioningTable.delete();
}
}

@Test
public void testListPartitions() throws InterruptedException {
String tableName = "test_table_partitions";
Expand Down