-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-9381][SQL]Migrate JSON data source to the new partitioning data source #7696
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| package org.apache.spark.sql.execution.datasources | ||
|
|
||
| import java.io.IOException | ||
| import java.util.{Date, UUID} | ||
|
|
||
| import scala.collection.JavaConversions.asScalaIterator | ||
|
|
@@ -36,7 +37,7 @@ import org.apache.spark.sql.catalyst.{CatalystTypeConverters, InternalRow} | |
| import org.apache.spark.sql.execution.RunnableCommand | ||
| import org.apache.spark.sql.sources._ | ||
| import org.apache.spark.sql.types.StringType | ||
| import org.apache.spark.util.SerializableConfiguration | ||
| import org.apache.spark.util.{Utils, SerializableConfiguration} | ||
|
|
||
|
|
||
| private[sql] case class InsertIntoDataSource( | ||
|
|
@@ -102,7 +103,12 @@ private[sql] case class InsertIntoHadoopFsRelation( | |
| case (SaveMode.ErrorIfExists, true) => | ||
| throw new AnalysisException(s"path $qualifiedOutputPath already exists.") | ||
| case (SaveMode.Overwrite, true) => | ||
| fs.delete(qualifiedOutputPath, true) | ||
| Utils.tryOrIOException { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throw exception if failed to delete the files, otherwise it will case failure in the unit test, which expect exception raised. |
||
| if (!fs.delete(qualifiedOutputPath, true /* recursively */)) { | ||
| throw new IOException(s"Unable to clear output " + | ||
| s"directory $qualifiedOutputPath prior to writing to it") | ||
| } | ||
| } | ||
| true | ||
| case (SaveMode.Append, _) | (SaveMode.Overwrite, _) | (SaveMode.ErrorIfExists, false) => | ||
| true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,7 +101,8 @@ private[sql] case class PreWriteCheck(catalog: Catalog) extends (LogicalPlan => | |
| } | ||
| } | ||
|
|
||
| case logical.InsertIntoTable(LogicalRelation(r: HadoopFsRelation), part, _, _, _) => | ||
| case logical.InsertIntoTable( | ||
| LogicalRelation(r: HadoopFsRelation), part, query, overwrite, _) => | ||
| // We need to make sure the partition columns specified by users do match partition | ||
| // columns of the relation. | ||
| val existingPartitionColumns = r.partitionColumns.fieldNames.toSet | ||
|
|
@@ -115,6 +116,17 @@ private[sql] case class PreWriteCheck(catalog: Catalog) extends (LogicalPlan => | |
| // OK | ||
| } | ||
|
|
||
| // Get all input data source relations of the query. | ||
| val srcRelations = query.collect { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we can do that in another PR, as will check if the the overwritten table is the same as the source table for the This actually will break the json unit test if we don't change the code in this PR. |
||
| case LogicalRelation(src: BaseRelation) => src | ||
| } | ||
| if (srcRelations.contains(r)) { | ||
| failAnalysis( | ||
| "Cannot insert overwrite into table that is also being read from.") | ||
| } else { | ||
| // OK | ||
| } | ||
|
|
||
| case logical.InsertIntoTable(l: LogicalRelation, _, _, _, _) => | ||
| // The relation in l is not an InsertableRelation. | ||
| failAnalysis(s"$l does not allow insertion.") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the last chance that to refresh the file status, otherwise, we may not able to reflect the latest files under the specified path, as we will pass the
t.pathsto create the rdd later on.