Skip to content

Commit dc3c38b

Browse files
author
Praful Makani
committed
Fix integration test
1 parent 4a43b67 commit dc3c38b

File tree

1 file changed

+11
-12
lines changed
  • google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it

1 file changed

+11
-12
lines changed

google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -644,21 +644,20 @@ public void testListTablesWithPartitioning() {
644644
}
645645

646646
@Test
647-
public void testListPartitions() {
647+
public void testListPartitions() throws InterruptedException {
648648
String tableName = "test_table_partitions";
649649
Date date = Date.fromJavaUtilDate(new java.util.Date());
650650
String partitionDate = date.toString().replaceAll("-", "");
651651
TableId tableId = TableId.of(DATASET, tableName + "$" + partitionDate);
652-
TimePartitioning timePartitioning = TimePartitioning.of(Type.DAY, EXPIRATION_MS);
653-
Schema schema = Schema.of(Field.of("StringField", LegacySQLTypeName.STRING));
654-
StandardTableDefinition tableDefinition =
655-
StandardTableDefinition.newBuilder()
656-
.setSchema(schema)
657-
.setTimePartitioning(timePartitioning)
658-
.build();
659-
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
660-
Table partitionedTable = bigquery.create(tableInfo);
661-
assertNotNull(partitionedTable);
652+
String query =
653+
String.format(
654+
"CREATE OR REPLACE TABLE %s.%s ( StringField STRING )"
655+
+ " PARTITION BY DATE(_PARTITIONTIME) "
656+
+ "OPTIONS( partition_expiration_days=1)",
657+
DATASET, tableName);
658+
Job job = bigquery.create(JobInfo.of(QueryJobConfiguration.newBuilder(query).build()));
659+
job.waitFor();
660+
assertTrue(job.isDone());
662661
try {
663662
Map<String, Object> row = new HashMap<String, Object>();
664663
row.put("StringField", "StringValue");
@@ -669,7 +668,7 @@ public void testListPartitions() {
669668
List<String> partitions = bigquery.listPartitions(TableId.of(DATASET, tableName));
670669
assertEquals(1, partitions.size());
671670
} finally {
672-
partitionedTable.delete();
671+
bigquery.delete(DATASET, tableName);
673672
}
674673
}
675674

0 commit comments

Comments
 (0)