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 @@ -895,7 +895,8 @@ class Analyzer(override val catalogManager: CatalogManager)
}
case u @ UnresolvedTable(ident, cmd, _) =>
lookupTempView(ident).foreach { _ =>
throw QueryCompilationErrors.expectTableNotTempViewError(ident.quoted, cmd, u)
throw QueryCompilationErrors.expectTableNotViewError(
ResolvedView(ident.asIdentifier, isTemp = true), cmd, u.relationTypeMismatchHint, u)
}
u
case u @ UnresolvedView(ident, cmd, allowTemp, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ private[spark] object QueryCompilationErrors {
s"$quoted as it's not a data source v2 relation.")
}

def expectTableNotTempViewError(quoted: String, cmd: String, t: TreeNode[_]): Throwable = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just reuse expectTableNotViewError if we pass ResolvedView.

new AnalysisException(s"$quoted is a temp view. '$cmd' expects a table",
t.origin.line, t.origin.startPosition)
}

def expectTableOrPermanentViewNotTempViewError(
quoted: String, cmd: String, t: TreeNode[_]): Throwable = {
new AnalysisException(s"$quoted is a temp view. '$cmd' expects a table or permanent view.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,39 +140,50 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
val viewName = "testView"
withTempView(viewName) {
spark.range(10).createTempView(viewName)
assertAnalysisError(
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName SET SERDE 'whatever'",
s"$viewName is a temp view. 'ALTER TABLE ... SET [SERDE|SERDEPROPERTIES]' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... SET [SERDE|SERDEPROPERTIES]")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName PARTITION (a=1, b=2) SET SERDE 'whatever'",
s"$viewName is a temp view. 'ALTER TABLE ... SET [SERDE|SERDEPROPERTIES]' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... SET [SERDE|SERDEPROPERTIES]")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName SET SERDEPROPERTIES ('p' = 'an')",
s"$viewName is a temp view. 'ALTER TABLE ... SET [SERDE|SERDEPROPERTIES]' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... SET [SERDE|SERDEPROPERTIES]")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName PARTITION (a='4') RENAME TO PARTITION (a='5')",
s"$viewName is a temp view. 'ALTER TABLE ... RENAME TO PARTITION' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... RENAME TO PARTITION")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName RECOVER PARTITIONS",
s"$viewName is a temp view. 'ALTER TABLE ... RECOVER PARTITIONS' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... RECOVER PARTITIONS")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName SET LOCATION '/path/to/your/lovely/heart'",
s"$viewName is a temp view. 'ALTER TABLE ... SET LOCATION ...' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... SET LOCATION ...")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName PARTITION (a='4') SET LOCATION '/path/to/home'",
"testView is a temp view. 'ALTER TABLE ... SET LOCATION ...' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... SET LOCATION ...")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName ADD IF NOT EXISTS PARTITION (a='4', b='8')",
s"$viewName is a temp view. 'ALTER TABLE ... ADD PARTITION ...' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... ADD PARTITION ...")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName DROP PARTITION (a='4', b='8')",
s"$viewName is a temp view. 'ALTER TABLE ... DROP PARTITION ...' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... DROP PARTITION ...")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName SET TBLPROPERTIES ('p' = 'an')",
s"$viewName is a temp view. 'ALTER TABLE ... SET TBLPROPERTIES' expects a table")
assertAnalysisError(
viewName,
"ALTER TABLE ... SET TBLPROPERTIES")
assertErrorForAlterTableOnTempView(
s"ALTER TABLE $viewName UNSET TBLPROPERTIES ('p')",
s"$viewName is a temp view. 'ALTER TABLE ... UNSET TBLPROPERTIES' expects a table")
viewName,
"ALTER TABLE ... UNSET TBLPROPERTIES")
}
}

Expand Down Expand Up @@ -220,6 +231,13 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
assert(e.message.contains(message))
}

private def assertErrorForAlterTableOnTempView(
sqlText: String, viewName: String, cmdName: String): Unit = {
assertAnalysisError(
sqlText,
s"$viewName is a temp view. '$cmdName' expects a table. Please use ALTER VIEW instead.")
}

test("error handling: insert/load table commands against a view") {
val viewName = "testView"
withView(viewName) {
Expand Down