Skip to content

Commit

Permalink
Update JSONRelation.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
yanboliang committed Mar 18, 2015
1 parent e2df8d5 commit 46f0d9d
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ private[sql] class DefaultSource
sys.error(s"Append mode is not supported by ${this.getClass.getCanonicalName}")
case SaveMode.Overwrite => {
try {
fs.delete(filesystemPath, true)
if (!fs.delete(filesystemPath, true)) {
throw new IOException(
s"Unable to clear output directory ${filesystemPath.toString} prior"
+ s" to INSERT OVERWRITE a JSON table:\n")
}
} catch {
case e: IOException =>
throw new IOException(
Expand All @@ -86,9 +90,6 @@ private[sql] class DefaultSource
}
if (doSave) {
// Only save data when the save mode is not ignore.
if (fs.exists(filesystemPath)) {
sys.error(s"Unable to INSERT OVERWRITE a JSON table, because table path $path exists.")
}
data.toJSON.saveAsTextFile(path)
}

Expand Down Expand Up @@ -121,17 +122,18 @@ private[sql] case class JSONRelation(

if (overwrite) {
try {
fs.delete(filesystemPath, true)
if (fs.exists(filesystemPath) && !fs.delete(filesystemPath, true)) {
throw new IOException(
s"Unable to clear output directory ${filesystemPath.toString} prior"
+ s" to INSERT OVERWRITE a JSON table:\n")
}
} catch {
case e: IOException =>
throw new IOException(
s"Unable to clear output directory ${filesystemPath.toString} prior"
+ s" to INSERT OVERWRITE a JSON table:\n${e.toString}")
}
// Write the data.
if (fs.exists(filesystemPath)) {
sys.error(s"Unable to INSERT OVERWRITE a JSON table, because table path $path exists.")
}
data.toJSON.saveAsTextFile(path)
// Right now, we assume that the schema is not changed. We will not update the schema.
// schema = data.schema
Expand Down

0 comments on commit 46f0d9d

Please sign in to comment.