Skip to content

Commit

Permalink
Fix creating empty non-bucketed Hive partition
Browse files Browse the repository at this point in the history
Previously, creating empty non-bucketed Hive partition procedure call
does not work when the WriteMode is STAGE_AND_MOVE_TO_TARGET_DIRECTORY,
since no file is created and the stage directory will not exist.
  • Loading branch information
wenleix committed Jan 31, 2019
1 parent 2eafd86 commit e81d1d6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1173,13 +1173,19 @@ private void prepareAddPartition(HdfsContext context, PartitionAndMore partition
schemaTableName,
ignored -> new PartitionAdder(partition.getDatabaseName(), partition.getTableName(), delegate, PARTITION_COMMIT_BATCH_SIZE));

if (!targetPath.equals(currentPath)) {
renameDirectory(
context,
hdfsEnvironment,
currentPath,
targetPath,
() -> cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true)));
if (pathExists(context, hdfsEnvironment, currentPath)) {
if (!targetPath.equals(currentPath)) {
renameDirectory(
context,
hdfsEnvironment,
currentPath,
targetPath,
() -> cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true)));
}
}
else {
cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true));
createDirectory(context, hdfsEnvironment, targetPath);
}
String partitionName = getPartitionName(partition.getDatabaseName(), partition.getTableName(), partition.getValues());
partitionAdder.addPartition(new PartitionWithStatistics(partition, partitionName, partitionAndMore.getStatisticsUpdate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,26 @@ public void testCastNullToColumnTypes()
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testCreateEmptyNonBucketedPartition()
{
String tableName = "test_insert_empty_partitioned_unbucketed_table";
assertUpdate("" +
"CREATE TABLE " + tableName + " (" +
" dummy_col bigint," +
" part varchar)" +
"WITH (" +
" format = 'ORC', " +
" partitioned_by = ARRAY[ 'part' ] " +
")");
assertQuery(format("SELECT count(*) FROM \"%s$partitions\"", tableName), "SELECT 0");

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

@Test
public void testCreateEmptyBucketedPartition()
{
Expand Down

0 comments on commit e81d1d6

Please sign in to comment.