Skip to content

Commit

Permalink
Fix creating non-bucketed empty partition
Browse files Browse the repository at this point in the history
Fix a bug where creating empty parition using CALL statement
throws exceptions when using file based metastore implementation.

Extracted-From: prestodb/presto#11376
  • Loading branch information
jessesleeping authored and sopel39 committed Jan 29, 2019
1 parent 120c28f commit 00aa33b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,13 @@ public Optional<ConnectorOutputMetadata> finishInsert(ConnectorSession session,
Map<List<String>, ComputedStatistics> partitionComputedStatistics = createComputedStatisticsToPartitionMap(computedStatistics, partitionedBy, columnTypes);

for (PartitionUpdate partitionUpdate : partitionUpdates) {
if (partitionUpdate.getFileNames().size() == 0) {
HiveWriteUtils.createDirectory(
new HdfsContext(session, table.get().getDatabaseName(), table.get().getTableName()),
hdfsEnvironment,
partitionUpdate.getWritePath());
}

if (partitionUpdate.getName().isEmpty()) {
// insert into unpartitioned table
metastore.finishInsertIntoExistingTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,30 @@ public void testCastNullToColumnTypes()
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testCreateEmptyPartition()
{
String tableName = "empty_partition_table";
assertUpdate(format("" +
"CREATE TABLE %s " +
"WITH ( " +
" FORMAT = 'ORC', " +
" partitioned_by = ARRAY['p_varchar'] " +
") " +
"AS " +
"SELECT c_bigint, p_varchar " +
"FROM ( " +
" VALUES " +
" (BIGINT '7', 'longlonglong')" +
") AS x (c_bigint, p_varchar)", tableName), 1);
assertQuery(format("SELECT count(*) FROM \"%s$partitions\"", tableName), "SELECT 1");

// create an empty partition
assertUpdate(format("CALL system.create_empty_partition('%s', '%s', ARRAY['p_varchar'], ARRAY['%s'])", TPCH_SCHEMA, tableName, "empty"));
assertQuery(format("SELECT count(*) FROM \"%s$partitions\"", tableName), "SELECT 2");
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testCreateEmptyBucketedPartition()
{
Expand Down

0 comments on commit 00aa33b

Please sign in to comment.