Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/16422#discussion_r137918748
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
@@ -626,6 +624,73 @@ case class DescribeTableCommand(
}
}
+/**
+ * A command to list the info for a column, including name, data type,
column stats and comment.
+ * This function creates a [[DescribeColumnCommand]] logical plan.
+ *
+ * The syntax of using this command in SQL is:
+ * {{{
+ * DESCRIBE [EXTENDED|FORMATTED] table_name column_name;
+ * }}}
+ */
+case class DescribeColumnCommand(
+ table: TableIdentifier,
+ colNameParts: Seq[String],
+ isExtended: Boolean)
+ extends RunnableCommand {
+
+ override val output: Seq[Attribute] = {
+ Seq(
+ AttributeReference("info_name", StringType, nullable = false,
+ new MetadataBuilder().putString("comment", "name of the column
info").build())(),
+ AttributeReference("info_value", StringType, nullable = false,
+ new MetadataBuilder().putString("comment", "value of the column
info").build())()
+ )
+ }
+
+ override def run(sparkSession: SparkSession): Seq[Row] = {
+ val catalog = sparkSession.sessionState.catalog
+ val resolver = sparkSession.sessionState.conf.resolver
+ val relation = sparkSession.table(table).queryExecution.analyzed
+ val field = {
+ relation.resolve(colNameParts, resolver).getOrElse {
+ throw new AnalysisException(s"Column
${UnresolvedAttribute(colNameParts).name} does not " +
+ s"exist")
+ }
+ }
+ if (!field.isInstanceOf[Attribute]) {
+ // If the field is not an attribute after `resolve`, then it's a
nested field.
+ throw new AnalysisException(s"DESC TABLE COLUMN command is not
supported for nested column:" +
+ s" ${UnresolvedAttribute(colNameParts).name}")
+ }
--- End diff --
```Scala
val colName = UnresolvedAttribute(colNameParts).name
val field = relation.resolve(colNameParts, resolver).getOrElse {
throw new AnalysisException(s"Column $colName does not exist")
}
if (!field.isInstanceOf[Attribute]) {
// If the field is not an attribute after `resolve`, then it's a
nested field.
throw new AnalysisException(
s"DESC TABLE COLUMN command does not supported nested data types:
$colName")
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]