Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a778192

Browse files
committed
Always create hive target directory if not present
#16456 broke creation of empty unpartitioned bucketed tables if they weren't using a temporary staging directory, as the target directory would not get created.
1 parent 0138bb4 commit a778192

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -1148,22 +1148,18 @@ private void prepareAddTable(MetastoreContext metastoreContext, HdfsContext cont
11481148
checkArgument(!targetLocation.isEmpty(), "target location is empty");
11491149
Optional<Path> currentPath = tableAndMore.getCurrentLocation();
11501150
Path targetPath = new Path(targetLocation);
1151-
if (table.getPartitionColumns().isEmpty() && currentPath.isPresent()) {
1152-
// CREATE TABLE AS SELECT unpartitioned table
1153-
if (targetPath.equals(currentPath.get())) {
1154-
// Target path and current path are the same. Therefore, directory move is not needed.
1155-
}
1156-
else {
1157-
renameDirectory(
1158-
context,
1159-
hdfsEnvironment,
1160-
currentPath.get(),
1161-
targetPath,
1162-
() -> cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true)));
1163-
}
1151+
if (table.getPartitionColumns().isEmpty() && currentPath.isPresent() && !targetPath.equals(currentPath.get())) {
1152+
// CREATE TABLE AS SELECT unpartitioned table with staging directory
1153+
renameDirectory(
1154+
context,
1155+
hdfsEnvironment,
1156+
currentPath.get(),
1157+
targetPath,
1158+
() -> cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true)));
11641159
}
11651160
else {
11661161
// CREATE TABLE AS SELECT partitioned table, or
1162+
// CREATE TABLE AS SELECT unpartitioned table without temporary staging directory
11671163
// CREATE TABLE partitioned/unpartitioned table (without data)
11681164
if (pathExists(context, hdfsEnvironment, targetPath)) {
11691165
if (currentPath.isPresent() && currentPath.get().equals(targetPath)) {

presto-hive/src/main/java/com/facebook/presto/hive/HiveSessionProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public final class HiveSessionProperties
9292
private static final String OPTIMIZE_MISMATCHED_BUCKET_COUNT = "optimize_mismatched_bucket_count";
9393
private static final String S3_SELECT_PUSHDOWN_ENABLED = "s3_select_pushdown_enabled";
9494
public static final String SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE = "shuffle_partitioned_columns_for_table_write";
95-
private static final String TEMPORARY_STAGING_DIRECTORY_ENABLED = "temporary_staging_directory_enabled";
95+
public static final String TEMPORARY_STAGING_DIRECTORY_ENABLED = "temporary_staging_directory_enabled";
9696
private static final String TEMPORARY_STAGING_DIRECTORY_PATH = "temporary_staging_directory_path";
9797
private static final String TEMPORARY_TABLE_SCHEMA = "temporary_table_schema";
9898
private static final String TEMPORARY_TABLE_STORAGE_FORMAT = "temporary_table_storage_format";

presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import static com.facebook.presto.hive.HiveSessionProperties.RCFILE_OPTIMIZED_WRITER_ENABLED;
108108
import static com.facebook.presto.hive.HiveSessionProperties.SORTED_WRITE_TEMP_PATH_SUBDIRECTORY_COUNT;
109109
import static com.facebook.presto.hive.HiveSessionProperties.SORTED_WRITE_TO_TEMP_PATH_ENABLED;
110+
import static com.facebook.presto.hive.HiveSessionProperties.TEMPORARY_STAGING_DIRECTORY_ENABLED;
110111
import static com.facebook.presto.hive.HiveSessionProperties.getInsertExistingPartitionsBehavior;
111112
import static com.facebook.presto.hive.HiveStorageFormat.PAGEFILE;
112113
import static com.facebook.presto.hive.HiveTableProperties.BUCKETED_BY_PROPERTY;
@@ -1144,6 +1145,28 @@ public void testCreateEmptyUnpartitionedBucketedTable()
11441145
assertUpdate("DROP TABLE " + tableName);
11451146
}
11461147

1148+
@Test
1149+
public void testCreateEmptyUnpartitionedBucketedTableNoStaging()
1150+
{
1151+
String tableName = "test_create_empty_bucketed_table_no_staging";
1152+
assertUpdate(
1153+
Session.builder(getSession())
1154+
.setCatalogSessionProperty(catalog, TEMPORARY_STAGING_DIRECTORY_ENABLED, "false")
1155+
.build(),
1156+
"" +
1157+
"CREATE TABLE " + tableName + " " +
1158+
"WITH (" +
1159+
" bucketed_by = ARRAY[ 'custkey' ], " +
1160+
" bucket_count = 11 " +
1161+
") " +
1162+
"AS " +
1163+
"SELECT custkey, comment " +
1164+
"FROM customer " +
1165+
"WHERE custkey < 0", 0);
1166+
assertQuery("SELECT count(*) FROM " + tableName, "SELECT 0");
1167+
assertUpdate("DROP TABLE " + tableName);
1168+
}
1169+
11471170
@Test
11481171
public void testCreateEmptyBucketedPartition()
11491172
{

0 commit comments

Comments
 (0)