Skip to content
Closed
Changes from 1 commit
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 @@ -87,17 +87,17 @@ case class InsertIntoHiveDirCommand(

val targetPath = new Path(storage.locationUri.get)
val qualifiedPath = FileUtils.makeQualified(targetPath, hadoopConf)
val writeToPath =
val (writeToPath: Path, fs: FileSystem) =
if (isLocal) {
val localFileSystem = FileSystem.getLocal(jobConf)
localFileSystem.makeQualified(targetPath)
(localFileSystem.makeQualified(targetPath), localFileSystem)
} else {
val dfs = qualifiedPath.getFileSystem(jobConf)
if (!dfs.exists(qualifiedPath)) {
dfs.mkdirs(qualifiedPath.getParent)
}
qualifiedPath
val dfs = qualifiedPath.getFileSystem(hadoopConf)
(qualifiedPath, dfs)
}
if (!fs.exists(writeToPath)) {
fs.mkdirs(writeToPath)
}

// The temporary path must be a HDFS path, not a local path.
val tmpPath = getExternalTmpPath(sparkSession, hadoopConf, qualifiedPath)
Copy link
Member

Choose a reason for hiding this comment

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

In case of inserts from non-hive tables, we still need to use a non-local path?

Copy link
Contributor Author

@beliefer beliefer Feb 26, 2019

Choose a reason for hiding this comment

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

If target path is local, we still need to use a non-local path.

Expand All @@ -112,19 +112,19 @@ case class InsertIntoHiveDirCommand(
fileSinkConf = fileSinkConf,
outputLocation = tmpPath.toString)

val fs = writeToPath.getFileSystem(hadoopConf)
if (overwrite && fs.exists(writeToPath)) {
fs.listStatus(writeToPath).foreach { existFile =>
if (Option(existFile.getPath) != createdTempDir) fs.delete(existFile.getPath, true)
}
}

fs.listStatus(tmpPath).foreach {
val dfs = tmpPath.getFileSystem(hadoopConf)
dfs.listStatus(tmpPath).foreach {
tmpFile =>
if (isLocal) {
fs.copyToLocalFile(tmpFile.getPath, writeToPath)
dfs.copyToLocalFile(tmpFile.getPath, writeToPath)
} else {
fs.rename(tmpFile.getPath, writeToPath)
dfs.rename(tmpFile.getPath, writeToPath)
}
}
} catch {
Expand Down