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 @@ -866,11 +866,12 @@ class Analyzer(override val catalogManager: CatalogManager)
u.failAnalysis(s"${ident.quoted} is a temp view. '$cmd' expects a table")
}
u
case u @ UnresolvedTableOrView(ident, allowTempView) =>
case u @ UnresolvedTableOrView(ident, cmd, allowTempView) =>
lookupTempView(ident)
.map { _ =>
if (!allowTempView) {
u.failAnalysis(s"${ident.quoted} is a temp view not table or permanent view.")
u.failAnalysis(
s"${ident.quoted} is a temp view. '$cmd' expects a table or permanent view.")
}
ResolvedView(ident.asIdentifier, isTemp = true)
}
Expand Down Expand Up @@ -955,7 +956,7 @@ class Analyzer(override val catalogManager: CatalogManager)
.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 @@ -1085,7 +1086,7 @@ class Analyzer(override val catalogManager: CatalogManager)
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 @@ -101,7 +101,9 @@ trait CheckAnalysis extends PredicateHelper {
u.failAnalysis(s"Table not found for '${u.commandName}': ${u.multipartIdentifier.quoted}")

case u: UnresolvedTableOrView =>
u.failAnalysis(s"Table or view not found: ${u.multipartIdentifier.quoted}")
val viewStr = if (u.allowTempView) "view" else "permanent view"
u.failAnalysis(
s"Table or $viewStr not found for '${u.commandName}': ${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 @@ -51,6 +51,7 @@ case class UnresolvedTable(
*/
case class UnresolvedTableOrView(
multipartIdentifier: Seq[String],
commandName: String,
allowTempView: 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 @@ -3148,7 +3148,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
override def visitDropTable(ctx: DropTableContext): LogicalPlan = withOrigin(ctx) {
// DROP TABLE works with either a table or a temporary view.
DropTable(
UnresolvedTableOrView(visitMultipartIdentifier(ctx.multipartIdentifier())),
UnresolvedTableOrView(visitMultipartIdentifier(ctx.multipartIdentifier()), "DROP TABLE"),
ctx.EXISTS != null,
ctx.PURGE != null)
}
Expand Down Expand Up @@ -3453,12 +3453,15 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
*/
override def visitDescribeRelation(ctx: DescribeRelationContext): LogicalPlan = withOrigin(ctx) {
val isExtended = ctx.EXTENDED != null || ctx.FORMATTED != null
val relation = UnresolvedTableOrView(
visitMultipartIdentifier(ctx.multipartIdentifier()),
"DESCRIBE TABLE")
if (ctx.describeColName != null) {
if (ctx.partitionSpec != null) {
throw new ParseException("DESC TABLE COLUMN for a specific partition is not supported", ctx)
} else {
DescribeColumn(
UnresolvedTableOrView(visitMultipartIdentifier(ctx.multipartIdentifier())),
relation,
ctx.describeColName.nameParts.asScala.map(_.getText).toSeq,
isExtended)
}
Expand All @@ -3473,10 +3476,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
} else {
Map.empty[String, String]
}
DescribeRelation(
UnresolvedTableOrView(visitMultipartIdentifier(ctx.multipartIdentifier())),
partitionSpec,
isExtended)
DescribeRelation(relation, partitionSpec, isExtended)
}
}

Expand Down Expand Up @@ -3514,21 +3514,24 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
val tableName = visitMultipartIdentifier(ctx.multipartIdentifier())
if (ctx.ALL() != null) {
checkPartitionSpec()
AnalyzeColumn(UnresolvedTableOrView(tableName), None, allColumns = true)
AnalyzeColumn(
UnresolvedTableOrView(tableName, "ANALYZE TABLE ... FOR ALL COLUMNS"),
None,
allColumns = true)
} else if (ctx.identifierSeq() == null) {
val partitionSpec = if (ctx.partitionSpec != null) {
visitPartitionSpec(ctx.partitionSpec)
} else {
Map.empty[String, Option[String]]
}
AnalyzeTable(
UnresolvedTableOrView(tableName, allowTempView = false),
UnresolvedTableOrView(tableName, "ANALYZE TABLE", allowTempView = false),
partitionSpec,
noScan = ctx.identifier != null)
} else {
checkPartitionSpec()
AnalyzeColumn(
UnresolvedTableOrView(tableName),
UnresolvedTableOrView(tableName, "ANALYZE TABLE ... FOR COLUMNS ..."),
Option(visitIdentifierSeq(ctx.identifierSeq())),
allColumns = false)
}
Expand Down Expand Up @@ -3572,6 +3575,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
ShowCreateTable(
UnresolvedTableOrView(
visitMultipartIdentifier(ctx.multipartIdentifier()),
"SHOW CREATE TABLE",
allowTempView = false),
ctx.SERDE != null)
}
Expand Down Expand Up @@ -3647,7 +3651,10 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
* }}}
*/
override def visitRefreshTable(ctx: RefreshTableContext): LogicalPlan = withOrigin(ctx) {
RefreshTable(UnresolvedTableOrView(visitMultipartIdentifier(ctx.multipartIdentifier())))
RefreshTable(
UnresolvedTableOrView(
visitMultipartIdentifier(ctx.multipartIdentifier()),
"REFRESH TABLE"))
}

/**
Expand All @@ -3670,7 +3677,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
} else {
nameParts
}
ShowColumns(UnresolvedTableOrView(tableName), namespace)
ShowColumns(UnresolvedTableOrView(tableName, "SHOW COLUMNS"), namespace)
}

/**
Expand Down Expand Up @@ -3881,7 +3888,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
override def visitShowTblProperties(
ctx: ShowTblPropertiesContext): LogicalPlan = withOrigin(ctx) {
ShowTableProperties(
UnresolvedTableOrView(visitMultipartIdentifier(ctx.table)),
UnresolvedTableOrView(visitMultipartIdentifier(ctx.table), "SHOW TBLPROPERTIES"),
Option(ctx.key).map(visitTablePropertyKey))
}

Expand Down
Loading