Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/4617#discussion_r24776531
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/sources/rules.scala
---
@@ -74,3 +74,68 @@ private[sql] object PreInsertCastAndRename extends
Rule[LogicalPlan] {
}
}
}
+
+/**
+ * A rule to do various checks before inserting into or writing to a data
source table.
+ */
+private[sql] case class PreWriteCheck(catalog: Catalog) extends
Rule[LogicalPlan] {
+ def failAnalysis(msg: String) = { throw new AnalysisException(msg) }
+
+ def apply(plan: LogicalPlan): LogicalPlan = {
+ plan.foreach {
+ case i @ logical.InsertIntoTable(
+ l @ LogicalRelation(t: InsertableRelation), partition, query,
overwrite) =>
+ // Right now, we do not support insert into a data source table
with partition specs.
+ if (partition.nonEmpty) {
+ failAnalysis(s"Insert into a partition is not allowed because $l
is not partitioned.")
+ } else {
+ // Get all input data source relations of the query.
+ val srcRelations = query.collect {
+ case LogicalRelation(src: BaseRelation) => src
+ }
+ if (srcRelations.exists(src => src == t)) {
+ failAnalysis(
+ s"It is not allowed to insert overwrite the table because it
is used as " +
+ s"an input table.")
--- End diff --
`Cannot insert overwrite into table that is also being read from`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]