Skip to content

Commit 0913a45

Browse files
committed
create local dir explicitly.
1 parent fd4dc69 commit 0913a45

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveDirCommand.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ case class InsertIntoHiveDirCommand(
8787

8888
val targetPath = new Path(storage.locationUri.get)
8989
val qualifiedPath = FileUtils.makeQualified(targetPath, hadoopConf)
90-
val writeToPath =
90+
val (writeToPath: Path, fs: FileSystem) =
9191
if (isLocal) {
9292
val localFileSystem = FileSystem.getLocal(jobConf)
93-
localFileSystem.makeQualified(targetPath)
93+
(localFileSystem.makeQualified(targetPath), localFileSystem)
9494
} else {
95-
val dfs = qualifiedPath.getFileSystem(jobConf)
96-
if (!dfs.exists(qualifiedPath)) {
97-
dfs.mkdirs(qualifiedPath.getParent)
98-
}
99-
qualifiedPath
95+
val dfs = qualifiedPath.getFileSystem(hadoopConf)
96+
(qualifiedPath, dfs)
10097
}
98+
if (!fs.exists(writeToPath)) {
99+
fs.mkdirs(writeToPath)
100+
}
101101

102102
// The temporary path must be a HDFS path, not a local path.
103103
val tmpPath = getExternalTmpPath(sparkSession, hadoopConf, qualifiedPath)
@@ -112,19 +112,19 @@ case class InsertIntoHiveDirCommand(
112112
fileSinkConf = fileSinkConf,
113113
outputLocation = tmpPath.toString)
114114

115-
val fs = writeToPath.getFileSystem(hadoopConf)
116115
if (overwrite && fs.exists(writeToPath)) {
117116
fs.listStatus(writeToPath).foreach { existFile =>
118117
if (Option(existFile.getPath) != createdTempDir) fs.delete(existFile.getPath, true)
119118
}
120119
}
121120

122-
fs.listStatus(tmpPath).foreach {
121+
val dfs = tmpPath.getFileSystem(hadoopConf)
122+
dfs.listStatus(tmpPath).foreach {
123123
tmpFile =>
124124
if (isLocal) {
125-
fs.copyToLocalFile(tmpFile.getPath, writeToPath)
125+
dfs.copyToLocalFile(tmpFile.getPath, writeToPath)
126126
} else {
127-
fs.rename(tmpFile.getPath, writeToPath)
127+
dfs.rename(tmpFile.getPath, writeToPath)
128128
}
129129
}
130130
} catch {

0 commit comments

Comments
 (0)