Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,9 @@ object ViewHelper extends SQLConfHelper with Logging with CapturesConfig {
plan.children.foreach(child => checkCyclicViewReference(child, path, viewIdent))
}

// Detect cyclic references from subqueries.
// Detect cyclic references from subqueries nested in expressions.
plan.expressions.foreach { expr =>
expr match {
expr.foreach {
case s: SubqueryExpression =>
checkCyclicViewReference(s.plan, path, viewIdent)
case _ => // Do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,19 @@ abstract class SQLViewSuite extends QueryTest {
s"`$SESSION_CATALOG_NAME`.`default`.`view2` -> " +
s"`$SESSION_CATALOG_NAME`.`default`.`view1`"))
)

// Detect cyclic view references from subqueries nested in larger expressions.
checkError(
exception = intercept[AnalysisException] {
sql("ALTER VIEW view1 AS SELECT * FROM jt WHERE id = (SELECT id FROM view2)")
},
condition = "RECURSIVE_VIEW",
parameters = Map(
"viewIdent" -> s"`$SESSION_CATALOG_NAME`.`default`.`view1`",
"newPath" -> (s"`$SESSION_CATALOG_NAME`.`default`.`view1` -> " +
s"`$SESSION_CATALOG_NAME`.`default`.`view2` -> " +
s"`$SESSION_CATALOG_NAME`.`default`.`view1`"))
)
}
}

Expand Down