dilipbiswal 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_r260811700
 
 

 ##########
 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:
   @cloud-fan the only thing is we may leave out a few statements if we 
restrict it to querySpecification like VALUES (...), WITH..  etc .. Is it okay 
if we create a parserRule like following ?
   
   queryDescribe
          : stmtType1
          | stmtType2
          ;
   

----------------------------------------------------------------
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]

Reply via email to