Skip to content

Commit

Permalink
feat: add range partitioning field to tableslist (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Praful Makani authored and stephaniewang526 committed Jan 17, 2020
1 parent 772516a commit 069240f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
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

0 comments on commit 069240f

Please sign in to comment.