Skip to content

Commit e8a9d1a

Browse files
committed
Fix write to view on top of DSv2
1 parent 3bbdfc7 commit e8a9d1a

File tree

1 file changed

+17
-4
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis

1 file changed

+17
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,18 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
11851185
}
11861186
}
11871187

1188+
private def resolveAsV2Relation(plan: LogicalPlan): Option[DataSourceV2Relation] = {
1189+
plan match {
1190+
case ref: V2TableReference =>
1191+
EliminateSubqueryAliases(relationResolution.resolveReference(ref)) match {
1192+
case r: DataSourceV2Relation => Some(r)
1193+
case _ => None
1194+
}
1195+
case r: DataSourceV2Relation => Some(r)
1196+
case _ => None
1197+
}
1198+
}
1199+
11881200
def apply(plan: LogicalPlan)
11891201
: LogicalPlan = plan.resolveOperatorsUpWithPruning(AlwaysProcess.fn, ruleId) {
11901202
case i @ InsertIntoStatement(table, _, _, _, _, _, _) =>
@@ -1210,13 +1222,14 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
12101222
resolveRelation(u).map(unwrapRelationPlan).map {
12111223
case v: View => throw QueryCompilationErrors.writeIntoViewNotAllowedError(
12121224
v.desc.identifier, write)
1213-
case r: DataSourceV2Relation => write.withNewTable(r)
12141225
case u: UnresolvedCatalogRelation =>
12151226
throw QueryCompilationErrors.writeIntoV1TableNotAllowedError(
12161227
u.tableMeta.identifier, write)
1217-
case other =>
1218-
throw QueryCompilationErrors.writeIntoTempViewNotAllowedError(
1219-
u.multipartIdentifier.quoted)
1228+
case plan =>
1229+
resolveAsV2Relation(plan).map(write.withNewTable).getOrElse {
1230+
throw QueryCompilationErrors.writeIntoTempViewNotAllowedError(
1231+
u.multipartIdentifier.quoted)
1232+
}
12201233
}.getOrElse(write)
12211234
case _ => write
12221235
}

0 commit comments

Comments
 (0)