Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creating empty non-bucketed Hive partition #12204

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -937,6 +937,26 @@ public void testCastNullToColumnTypes()
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testCreateEmptyNonBucketedPartition()
{
String tableName = "test_insert_empty_partitioned_unbucketed_table";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test the scenario of STAGE_AND_MOVE_TO_TARGET_DIRECTORY? This might sound noob but I didn't see where the write mode is set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't matter. For empty partition, we just need to create an empty directory and we can directly create it as the target path.

Copy link
Contributor Author

@wenleix wenleix Jan 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shixuan-fan : STAGE_AND_MOVE_TO_TARGET_DIRECTORY is used in open source Hive Connector, unless underlying file system is S3 in which rename is expensive . See

if (shouldUseTemporaryDirectory(session, context, targetPath)) {
Path writePath = createTemporaryPath(session, context, hdfsEnvironment, targetPath);
return new LocationHandle(targetPath, writePath, false, STAGE_AND_MOVE_TO_TARGET_DIRECTORY);
}

and

private boolean shouldUseTemporaryDirectory(ConnectorSession session, HdfsContext context, Path path)
{
return isTemporaryStagingDirectoryEnabled(session)
// skip using temporary directory for S3
&& !isS3FileSystem(context, hdfsEnvironment, path);
}

The session property hive.temporary-staging-directory-enabled was added recently by #12199 for S3 filesystem in disguise.

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