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 @@ -856,8 +856,13 @@ class Analyzer(
u.failAnalysis(s"${ident.quoted} is a temp view not table.")
}
u
case u @ UnresolvedTableOrView(ident) =>
lookupTempView(ident).map(_ => ResolvedView(ident.asIdentifier)).getOrElse(u)
case u @ UnresolvedTableOrView(ident, acceptTempView) =>
lookupTempView(ident).map { _ =>
if (!acceptTempView) {
u.failAnalysis(s"${ident.quoted} is a temp view, not a table or permanent view.")
}
ResolvedView(ident.asIdentifier)
}.getOrElse(u)
}

def lookupTempView(identifier: Seq[String]): Option[LogicalPlan] = {
Expand Down Expand Up @@ -905,7 +910,7 @@ class Analyzer(
.map(ResolvedTable(catalog.asTableCatalog, ident, _))
.getOrElse(u)

case u @ UnresolvedTableOrView(NonSessionCatalogAndIdentifier(catalog, ident)) =>
case u @ UnresolvedTableOrView(NonSessionCatalogAndIdentifier(catalog, ident), _) =>
CatalogV2Util.loadTable(catalog, ident)
.map(ResolvedTable(catalog.asTableCatalog, ident, _))
.getOrElse(u)
Expand Down Expand Up @@ -994,7 +999,7 @@ class Analyzer(
case table => table
}.getOrElse(u)

case u @ UnresolvedTableOrView(identifier) =>
case u @ UnresolvedTableOrView(identifier, _) =>
lookupTableOrView(identifier).getOrElse(u)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ trait CheckAnalysis extends PredicateHelper {
case u: UnresolvedTable =>
u.failAnalysis(s"Table not found: ${u.multipartIdentifier.quoted}")

case u: UnresolvedTableOrView =>
case u: UnresolvedTableOrView if u.acceptTempView =>
u.failAnalysis(s"Table or view not found: ${u.multipartIdentifier.quoted}")

case u: UnresolvedTableOrView if !u.acceptTempView =>
u.failAnalysis(s"Table or permanent view not found: ${u.multipartIdentifier.quoted}")

case u: UnresolvedRelation =>
u.failAnalysis(s"Table or view not found: ${u.multipartIdentifier.quoted}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ case class UnresolvedTable(multipartIdentifier: Seq[String]) extends LeafNode {
* Holds the name of a table or view that has yet to be looked up in a catalog. It will
* be resolved to [[ResolvedTable]] or [[ResolvedView]] during analysis.
*/
case class UnresolvedTableOrView(multipartIdentifier: Seq[String]) extends LeafNode {
case class UnresolvedTableOrView(multipartIdentifier: Seq[String], acceptTempView: Boolean = true)
extends LeafNode {
override lazy val resolved: Boolean = false
override def output: Seq[Attribute] = Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
override def visitShowTblProperties(
ctx: ShowTblPropertiesContext): LogicalPlan = withOrigin(ctx) {
ShowTableProperties(
UnresolvedTableOrView(visitMultipartIdentifier(ctx.table)),
UnresolvedTableOrView(visitMultipartIdentifier(ctx.table), acceptTempView = false),
Option(ctx.key).map(visitTablePropertyKey))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2016,11 +2016,11 @@ class DDLParserSuite extends AnalysisTest {
test("SHOW TBLPROPERTIES table") {
comparePlans(
parsePlan("SHOW TBLPROPERTIES a.b.c"),
ShowTableProperties(UnresolvedTableOrView(Seq("a", "b", "c")), None))
ShowTableProperties(UnresolvedTableOrView(Seq("a", "b", "c"), false), None))

comparePlans(
parsePlan("SHOW TBLPROPERTIES a.b.c('propKey1')"),
ShowTableProperties(UnresolvedTableOrView(Seq("a", "b", "c")), Some("propKey1")))
ShowTableProperties(UnresolvedTableOrView(Seq("a", "b", "c"), false), Some("propKey1")))
}

test("DESCRIBE FUNCTION") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ case class ShowTablePropertiesCommand(table: TableIdentifier, propertyKey: Optio
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
if (catalog.isTemporaryTable(table)) {
Seq.empty[Row]
throw new AnalysisException(s"SHOW TBLPROPERTIES is not allowed on a temporary view: $table")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will not be hit if you go thru SHOW TBLPROPERTIES command.

} else {
val catalogTable = catalog.getTableMetadata(table)
propertyKey match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ struct<>
-- !query
SHOW TBLPROPERTIES tv
-- !query schema
struct<key:string,value:string>
struct<>
-- !query output

org.apache.spark.sql.AnalysisException
tv is a temp view, not a table or permanent view.; line 1 pos 0


-- !query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto
val message = intercept[AnalysisException] {
sql("SHOW TBLPROPERTIES badtable")
}.getMessage
assert(message.contains("Table or view not found: badtable"))
assert(message.contains("Table or permanent view not found: badtable"))

// When key is not found, a row containing the error is returned.
checkAnswer(
Expand Down