Github user OopsOutOfMemory commented on a diff in the pull request:
https://github.com/apache/spark/pull/4127#discussion_r23359955
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/commands.scala ---
@@ -178,3 +180,34 @@ case class DescribeCommand(
child.output.map(field => Row(field.name, field.dataType.toString,
null))
}
}
+
+/**
+ * :: DeveloperApi ::
+ */
+@DeveloperApi
+case class DDLDescribeCommand(
+ dbName: Option[String],
+ tableName: String, isExtended: Boolean) extends RunnableCommand {
+
+ override def run(sqlContext: SQLContext) = {
+ val tblRelation = dbName match {
+ case Some(db) => UnresolvedRelation(Seq(db, tableName))
+ case None => UnresolvedRelation(Seq(tableName))
+ }
+ val logicalRelation = sqlContext.executePlan(tblRelation).analyzed
+ val rows = new ArrayBuffer[Row]()
+ rows ++= logicalRelation.schema.fields.map{field =>
+ Row(field.name, field.dataType.toSimpleString, null)}
+
+ /*
+ * TODO if future support partition table, add header below:
+ * # Partition Information
+ * # col_name data_type comment
--- End diff --
after finish SPARK-5182. we can do it like this:
```
val logicalRelation = sqlContext.executePlan(tblRelation).analyzed
val rows = new ArrayBuffer[Row]()
rows ++= logicalRelation.schema.fields.map{field =>
Row(field.name, field.dataType.toSimpleString, null)}
val partitionFields = logicalRelation.schema.getPartitionedCols()
if (partitionFields.nonEmpty) {
val partColumnRows =
partitionFields.map(field => Row(field.getName,
field.getType.toSimpleString, null))
rows ++=
Seq(("# Partition Information", "", "")) ++
("col_name","data_type","comment") ++
partColumnRows
}
```
For `extended` we can do it later and discuss to show detail information.
```
if (isExtended) {
rows ++= Seq(("Detailed Table Information", //get some detail info
from table, ""))
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]