Skip to content

Commit

Permalink
Fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Praful Makani committed Apr 9, 2019
1 parent 4a43b67 commit dc3c38b
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -644,21 +644,20 @@ public void testListTablesWithPartitioning() {
}

@Test
public void testListPartitions() {
public void testListPartitions() throws InterruptedException {
String tableName = "test_table_partitions";
Date date = Date.fromJavaUtilDate(new java.util.Date());
String partitionDate = date.toString().replaceAll("-", "");
TableId tableId = TableId.of(DATASET, tableName + "$" + partitionDate);
TimePartitioning timePartitioning = TimePartitioning.of(Type.DAY, EXPIRATION_MS);
Schema schema = Schema.of(Field.of("StringField", LegacySQLTypeName.STRING));
StandardTableDefinition tableDefinition =
StandardTableDefinition.newBuilder()
.setSchema(schema)
.setTimePartitioning(timePartitioning)
.build();
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
Table partitionedTable = bigquery.create(tableInfo);
assertNotNull(partitionedTable);
String query =
String.format(
"CREATE OR REPLACE TABLE %s.%s ( StringField STRING )"
+ " PARTITION BY DATE(_PARTITIONTIME) "
+ "OPTIONS( partition_expiration_days=1)",
DATASET, tableName);
Job job = bigquery.create(JobInfo.of(QueryJobConfiguration.newBuilder(query).build()));
job.waitFor();
assertTrue(job.isDone());
try {
Map<String, Object> row = new HashMap<String, Object>();
row.put("StringField", "StringValue");
Expand All @@ -669,7 +668,7 @@ public void testListPartitions() {
List<String> partitions = bigquery.listPartitions(TableId.of(DATASET, tableName));
assertEquals(1, partitions.size());
} finally {
partitionedTable.delete();
bigquery.delete(DATASET, tableName);
}
}

Expand Down

0 comments on commit dc3c38b

Please sign in to comment.