imback82 commented on a change in pull request #31273:
URL: https://github.com/apache/spark/pull/31273#discussion_r561604269
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala
##########
@@ -2029,7 +2029,7 @@ class DataSourceV2SQLSuite
test("CREATE VIEW") {
val v = "testcat.ns1.ns2.v"
val e = intercept[AnalysisException] {
- sql(s"CREATE VIEW $v AS SELECT * FROM tab1")
+ sql(s"CREATE VIEW $v AS SELECT 1")
Review comment:
This needs to be updated now that `ResolveSessionCatalog` handles
`CreateViewStatement` only if its `child` is resolved.
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
##########
@@ -558,20 +560,27 @@ object ViewHelper {
catalog: SessionCatalog, child: LogicalPlan): (Seq[Seq[String]],
Seq[String]) = {
def collectTempViews(child: LogicalPlan): Seq[Seq[String]] = {
child.collect {
- case UnresolvedRelation(nameParts, _, _) if
catalog.isTempView(nameParts) =>
- Seq(nameParts)
- case plan if !plan.resolved => plan.expressions.flatMap(_.collect {
+ case s @ SubqueryAlias(_, view: View) if view.isTempView =>
+ Seq(s.identifier.qualifier :+ s.identifier.name)
+ case s: SubqueryAlias if s.getTagValue(SUBQUERY_TYPE_TAG).exists(_ ==
"tempView") =>
Review comment:
This seems a bit hacky, but `SubqueryAlias(_, view: View)` couldn't
handle all the cases. For example,
```scala
spark.range(10).createTempView("t")
sql("CREATE VIEW v AS SELECT * FROM t")
```
The `child` is:
```
Project [id#16L]
+- SubqueryAlias t
+- Range (0, 10, step=1, splits=Some(2))
```
@cloud-fan, @viirya Any suggestion to capture the view properly? Does it
make sense to add an `isView` field to `SubqueryAlias`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]