spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hvanhovell <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-14127][SQL] Native "DESC [EXTENDED | FO...
Date Tue, 03 May 2016 21:08:51 GMT
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12844#discussion_r61956502
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
---
    @@ -290,29 +291,88 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended:
Boolean)
         val result = new ArrayBuffer[Row]
         sparkSession.sessionState.catalog.lookupRelation(table) match {
           case catalogRelation: CatalogRelation =>
    -        catalogRelation.catalogTable.schema.foreach { column =>
    -          result += Row(column.name, column.dataType, column.comment.orNull)
    -        }
    -
    -        if (catalogRelation.catalogTable.partitionColumns.nonEmpty) {
    -          result += Row("# Partition Information", "", "")
    -          result += Row(s"# ${output(0).name}", output(1).name, output(2).name)
    -
    -          catalogRelation.catalogTable.partitionColumns.foreach { col =>
    -            result += Row(col.name, col.dataType, col.comment.orNull)
    -          }
    +        if (isExtended) {
    +          describeExtended(catalogRelation, result)
    +        } else if (isFormatted) {
    +          describeFormatted(catalogRelation, result)
    +        } else {
    +          describe(catalogRelation, result)
             }
     
           case relation =>
    -        relation.schema.fields.foreach { field =>
    -          val comment =
    -            if (field.metadata.contains("comment")) field.metadata.getString("comment")
else ""
    -          result += Row(field.name, field.dataType.simpleString, comment)
    -        }
    +        describeSchema(relation.schema, result)
         }
     
         result
       }
    +
    +  // Shows data columns and partitioned columns (if any)
    +  private def describe(relation: CatalogRelation, buffer: ArrayBuffer[Row]): Unit = {
    +    describeSchema(relation.catalogTable.schema, buffer)
    +
    +    if (relation.catalogTable.partitionColumns.nonEmpty) {
    +      buffer += Row("# Partition Information", "", "")
    +      buffer += Row(s"# ${output(0).name}", output(1).name, output(2).name)
    +
    +      describeSchema(relation.catalogTable.partitionColumns, buffer)
    +    }
    +  }
    +
    +  private def describeExtended(relation: CatalogRelation, buffer: ArrayBuffer[Row]):
Unit = {
    +    describe(relation, buffer)
    +
    +    buffer += Row("", "", "")
    +    buffer += Row("# Detailed Table Information", relation.catalogTable.toString, "")
    +  }
    +
    +  private def describeFormatted(relation: CatalogRelation, buffer: ArrayBuffer[Row]):
Unit = {
    +    describe(relation, buffer)
    +
    +    val table = relation.catalogTable
    +
    +    buffer += Row("", "", "")
    +    buffer += Row("# Detailed Table Information", "", "")
    +    buffer += Row("Database:", table.database, "")
    +    buffer += Row("Owner:", table.owner, "")
    +    buffer += Row("Create Time:", new Date(table.createTime).toString, "")
    +    buffer += Row("Last Access Time:", new Date(table.lastAccessTime).toString, "")
    +    buffer += Row("Location:", table.storage.locationUri.getOrElse(""), "")
    +    buffer += Row("Table Type:", table.tableType.name, "")
    +
    +    buffer += Row("Table Parameters:", "", "")
    +    table.properties.foreach { case (key, value) =>
    +      buffer += Row(s"  $key", value, "")
    +    }
    +
    +    buffer += Row("", "", "")
    +    buffer += Row("# Storage Information", "", "")
    +    table.storage.serde.foreach(serdeLib => buffer += Row("SerDe Library:", serdeLib,
""))
    +    table.storage.inputFormat.foreach(format => buffer += Row("InputFormat:", format,
""))
    +    table.storage.outputFormat.foreach(format => buffer += Row("OutputFormat:", format,
""))
    +    buffer += Row("Compressed:", if (table.storage.compressed) "Yes" else "No", "")
    +    buffer += Row("Num Buckets:", table.numBuckets.toString, "")
    +    buffer += Row("Bucket Columns:", table.bucketColumnNames.mkString("[", ", ", "]"),
"")
    +    buffer += Row("Sort Columns:", table.sortColumnNames.mkString("[", ", ", "]"), "")
    +
    +    buffer += Row("Storage Desc Parameters:", "", "")
    +    table.storage.serdeProperties.foreach { case (key, value) =>
    +      buffer += Row(s"  $key", value, "")
    +    }
    +  }
    +
    +  private def describeSchema(schema: StructType, buffer: ArrayBuffer[Row]): Unit = {
    +    schema.foreach { column =>
    +      val comment =
    +        if (column.metadata.contains("comment")) column.metadata.getString("comment")
else ""
    --- End diff --
    
    Just an idea: So 9/10 times I use `column.metadata` it is to get the comment. Shouldn't
we just add this to the StructField...?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message