imback82 commented on a change in pull request #30881:
URL: https://github.com/apache/spark/pull/30881#discussion_r549528750
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala
##########
@@ -235,8 +236,17 @@ class ResolveSessionCatalog(
case DescribeRelation(ResolvedV1TableOrViewIdentifier(ident),
partitionSpec, isExtended) =>
DescribeTableCommand(ident.asTableIdentifier, partitionSpec, isExtended)
- case DescribeColumn(ResolvedV1TableOrViewIdentifier(ident), colNameParts,
isExtended) =>
- DescribeColumnCommand(ident.asTableIdentifier, colNameParts, isExtended)
+ case DescribeColumn(ResolvedV1TableOrViewIdentifier(ident), column,
isExtended) =>
+ column match {
+ case u: UnresolvedAttribute =>
+ // For views, the column will not be resolved by `ResolveReferences`
because
+ // `ResolvedView` stores only the identifier.
+ DescribeColumnCommand(ident.asTableIdentifier, u.nameParts,
isExtended)
+ case a: Attribute =>
+ DescribeColumnCommand(ident.asTableIdentifier, a.qualifier :+
a.name, isExtended)
+ case nested =>
+ throw
QueryCompilationErrors.commandNotSupportNestedColumnError("DESC TABLE COLUMN")
Review comment:
One disadvantage of this approach is that the exception message for view
will be different when nested column is specified; it will have the original
name parts:
https://github.com/apache/spark/blob/0617dfce7beb34662ab30a607721e9b46e65c21e/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala#L773
We can do one of the following:
* Make the exception message the same even for views by dropping column name
in `DescribeColumnCommand`
* Store the original column name in `DescribeColumn` (and there will be no
matching logic for column in `ResolveSessionCatalog`, but seems duplicated
because we have `UnresolvedAttribute` to store the original column name.)
* Construct the original name from `GetStructField`, `GetArrayStructFields`,
etc.
WDYT, @cloud-fan ?
----------------------------------------------------------------
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]