cloud-fan commented on a change in pull request #23883: [SPARK-26982][SQL]
Enhance describe framework to describe the output of a query.
URL: https://github.com/apache/spark/pull/23883#discussion_r260712769
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
##########
@@ -617,10 +617,55 @@ case class DescribeTableCommand(
}
private def append(
- buffer: ArrayBuffer[Row], column: String, dataType: String, comment:
String): Unit = {
+ buffer: ArrayBuffer[Row], column: String, dataType: String, comment:
String): Unit = {
buffer += Row(column, dataType, comment)
}
}
+/**
+ * Command can of the following form.
+ * {{{
+ * DESCRIBE [EXTENDED|FORMATTED] table_name partitionSpec?;
+ * }}}
+ */
+case class DescribeTableCommand(
+ tableIdent: TableIdentifier,
+ partitionSpec: TablePartitionSpec,
+ isExtended: Boolean)
+ extends DescribeTableCommandBase {
+
+ override def run(sparkSession: SparkSession): Seq[Row] = {
+ val result = new ArrayBuffer[Row]
+ describeTable(sparkSession, tableIdent, partitionSpec, isExtended, result)
+ result
+ }
+}
+
+/**
+ * Command can of the following form.
+ * {{{
+ * DESCRIBE [QUERY] query_statement
+ * }}}
+ */
+case class DescribeQueryCommand(query: LogicalPlan)
+ extends DescribeTableCommandBase {
+
+ override def run(sparkSession: SparkSession): Seq[Row] = {
+ val result = new ArrayBuffer[Row]
+ query match {
+ case p if p.collectFirst { case _: InsertIntoTable | _: InsertIntoDir =>
true }.isDefined =>
+ throw new AnalysisException("Describe command is not supported for
insert statements.")
Review comment:
I don't have a strong preference here, but the DB2 does this in the parser,
I'm wondering if we should do this in the parser as well.
instead of `(DESC | DESCRIBE) QUERY? query`, how about `(DESC | DESCRIBE)
QUERY? querySpecification`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]