Skip to content

Commit

Permalink
Refactor testCreateEmptyBucketedPartition
Browse files Browse the repository at this point in the history
Utilize existing test helper for iterating over storage formats.
  • Loading branch information
findepi committed Aug 14, 2023
1 parent 9e02c42 commit b07bbd4
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2960,29 +2960,28 @@ public void testRegisterPartitionWithNullArgument()
@Test
public void testCreateEmptyBucketedPartition()
{
for (TestingHiveStorageFormat storageFormat : getAllTestingHiveStorageFormat()) {
testCreateEmptyBucketedPartition(storageFormat.getFormat());
}
testWithAllStorageFormats(this::testCreateEmptyBucketedPartition);
}

private void testCreateEmptyBucketedPartition(HiveStorageFormat storageFormat)
private void testCreateEmptyBucketedPartition(Session session, HiveStorageFormat storageFormat)
{
String tableName = "test_insert_empty_partitioned_bucketed_table";
createPartitionedBucketedTable(tableName, storageFormat);
createPartitionedBucketedTable(session, tableName, storageFormat);

List<String> orderStatusList = ImmutableList.of("F", "O", "P");
for (int i = 0; i < orderStatusList.size(); i++) {
String sql = format("CALL system.create_empty_partition('%s', '%s', ARRAY['orderstatus'], ARRAY['%s'])", TPCH_SCHEMA, tableName, orderStatusList.get(i));
assertUpdate(sql);
assertUpdate(session, sql);
assertQuery(
session,
format("SELECT count(*) FROM \"%s$partitions\"", tableName),
"SELECT " + (i + 1));

assertQueryFails(sql, "Partition already exists.*");
assertQueryFails(session, sql, "Partition already exists.*");
}

assertUpdate("DROP TABLE " + tableName);
assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertUpdate(session, "DROP TABLE " + tableName);
assertFalse(getQueryRunner().tableExists(session, tableName));
}

@Test
Expand Down Expand Up @@ -3011,7 +3010,7 @@ public void testInsertPartitionedBucketedTable()
private void testInsertPartitionedBucketedTable(HiveStorageFormat storageFormat)
{
String tableName = "test_insert_partitioned_bucketed_table";
createPartitionedBucketedTable(tableName, storageFormat);
createPartitionedBucketedTable(getSession(), tableName, storageFormat);

List<String> orderStatusList = ImmutableList.of("F", "O", "P");
for (int i = 0; i < orderStatusList.size(); i++) {
Expand All @@ -3034,19 +3033,20 @@ private void testInsertPartitionedBucketedTable(HiveStorageFormat storageFormat)
assertFalse(getQueryRunner().tableExists(getSession(), tableName));
}

private void createPartitionedBucketedTable(String tableName, HiveStorageFormat storageFormat)
private void createPartitionedBucketedTable(Session session, String tableName, HiveStorageFormat storageFormat)
{
assertUpdate("" +
assertUpdate(
session,
"CREATE TABLE " + tableName + " (" +
" custkey bigint," +
" custkey2 bigint," +
" comment varchar," +
" orderstatus varchar)" +
"WITH (" +
"format = '" + storageFormat + "', " +
"partitioned_by = ARRAY[ 'orderstatus' ], " +
"bucketed_by = ARRAY[ 'custkey', 'custkey2' ], " +
"bucket_count = 11)");
" custkey bigint," +
" custkey2 bigint," +
" comment varchar," +
" orderstatus varchar)" +
"WITH (" +
"format = '" + storageFormat + "', " +
"partitioned_by = ARRAY[ 'orderstatus' ], " +
"bucketed_by = ARRAY[ 'custkey', 'custkey2' ], " +
"bucket_count = 11)");
}

@Test
Expand Down Expand Up @@ -3100,7 +3100,7 @@ private void testInsertPartitionedBucketedTableWithUnionAll(HiveStorageFormat st
public void testInsertTwiceToSamePartitionedBucket()
{
String tableName = "test_insert_twice_to_same_partitioned_bucket";
createPartitionedBucketedTable(tableName, HiveStorageFormat.RCBINARY);
createPartitionedBucketedTable(getSession(), tableName, HiveStorageFormat.RCBINARY);

String insert = "INSERT INTO " + tableName +
" VALUES (1, 1, 'first_comment', 'F'), (2, 2, 'second_comment', 'G')";
Expand Down

0 comments on commit b07bbd4

Please sign in to comment.