-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-20067] [SQL] Unify and Clean Up Desc Commands Using Catalog Interface #17394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ebeac8
8720919
d999147
3859097
1d72079
68bb05c
ac3f351
bef1134
29817ea
6c56041
36b501e
e116018
a6db8a3
43668be
862a4d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,8 +500,7 @@ case class TruncateTableCommand( | |
| case class DescribeTableCommand( | ||
| table: TableIdentifier, | ||
| partitionSpec: TablePartitionSpec, | ||
| isExtended: Boolean, | ||
| isFormatted: Boolean) | ||
| isExtended: Boolean) | ||
| extends RunnableCommand { | ||
|
|
||
| override val output: Seq[Attribute] = Seq( | ||
|
|
@@ -536,14 +535,12 @@ case class DescribeTableCommand( | |
|
|
||
| describePartitionInfo(metadata, result) | ||
|
|
||
| if (partitionSpec.isEmpty) { | ||
| if (isExtended) { | ||
| describeExtendedTableInfo(metadata, result) | ||
| } else if (isFormatted) { | ||
| describeFormattedTableInfo(metadata, result) | ||
| } | ||
| } else { | ||
| if (partitionSpec.nonEmpty) { | ||
| // Outputs the partition-specific info for the DDL command: | ||
| // "DESCRIBE [EXTENDED|FORMATTED] table_name PARTITION (partitionVal*)" | ||
| describeDetailedPartitionInfo(sparkSession, catalog, metadata, result) | ||
| } else if (isExtended) { | ||
| describeFormattedTableInfo(metadata, result) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -553,76 +550,20 @@ case class DescribeTableCommand( | |
| private def describePartitionInfo(table: CatalogTable, buffer: ArrayBuffer[Row]): Unit = { | ||
| if (table.partitionColumnNames.nonEmpty) { | ||
| append(buffer, "# Partition Information", "", "") | ||
| append(buffer, s"# ${output.head.name}", output(1).name, output(2).name) | ||
| describeSchema(table.partitionSchema, buffer) | ||
| } | ||
| } | ||
|
|
||
| private def describeExtendedTableInfo(table: CatalogTable, buffer: ArrayBuffer[Row]): Unit = { | ||
| append(buffer, "", "", "") | ||
| append(buffer, "# Detailed Table Information", table.toString, "") | ||
| } | ||
|
|
||
| private def describeFormattedTableInfo(table: CatalogTable, buffer: ArrayBuffer[Row]): Unit = { | ||
| // The following information has been already shown in the previous outputs | ||
| val excludedTableInfo = Seq( | ||
| "Partition Columns", | ||
| "Schema" | ||
| ) | ||
| append(buffer, "", "", "") | ||
| append(buffer, "# Detailed Table Information", "", "") | ||
| append(buffer, "Database:", table.database, "") | ||
| append(buffer, "Owner:", table.owner, "") | ||
| append(buffer, "Created:", new Date(table.createTime).toString, "") | ||
| append(buffer, "Last Access:", new Date(table.lastAccessTime).toString, "") | ||
| append(buffer, "Location:", table.storage.locationUri.map(CatalogUtils.URIToString(_)) | ||
| .getOrElse(""), "") | ||
| append(buffer, "Table Type:", table.tableType.name, "") | ||
| append(buffer, "Comment:", table.comment.getOrElse(""), "") | ||
| table.stats.foreach(s => append(buffer, "Statistics:", s.simpleString, "")) | ||
|
|
||
| append(buffer, "Table Parameters:", "", "") | ||
| table.properties.foreach { case (key, value) => | ||
| append(buffer, s" $key", value, "") | ||
| } | ||
|
|
||
| describeStorageInfo(table, buffer) | ||
|
|
||
| if (table.tableType == CatalogTableType.VIEW) describeViewInfo(table, buffer) | ||
|
|
||
| if (DDLUtils.isDatasourceTable(table) && table.tracksPartitionsInCatalog) { | ||
| append(buffer, "Partition Provider:", "Catalog", "") | ||
| } | ||
| } | ||
|
|
||
| private def describeStorageInfo(metadata: CatalogTable, buffer: ArrayBuffer[Row]): Unit = { | ||
| append(buffer, "", "", "") | ||
| append(buffer, "# Storage Information", "", "") | ||
| metadata.storage.serde.foreach(serdeLib => append(buffer, "SerDe Library:", serdeLib, "")) | ||
| metadata.storage.inputFormat.foreach(format => append(buffer, "InputFormat:", format, "")) | ||
| metadata.storage.outputFormat.foreach(format => append(buffer, "OutputFormat:", format, "")) | ||
| append(buffer, "Compressed:", if (metadata.storage.compressed) "Yes" else "No", "") | ||
| describeBucketingInfo(metadata, buffer) | ||
|
|
||
| append(buffer, "Storage Desc Parameters:", "", "") | ||
| val maskedProperties = CatalogUtils.maskCredentials(metadata.storage.properties) | ||
| maskedProperties.foreach { case (key, value) => | ||
| append(buffer, s" $key", value, "") | ||
| } | ||
| } | ||
|
|
||
| private def describeViewInfo(metadata: CatalogTable, buffer: ArrayBuffer[Row]): Unit = { | ||
| append(buffer, "", "", "") | ||
| append(buffer, "# View Information", "", "") | ||
| append(buffer, "View Text:", metadata.viewText.getOrElse(""), "") | ||
| append(buffer, "View Default Database:", metadata.viewDefaultDatabase.getOrElse(""), "") | ||
| append(buffer, "View Query Output Columns:", | ||
| metadata.viewQueryColumnNames.mkString("[", ", ", "]"), "") | ||
| } | ||
|
|
||
| private def describeBucketingInfo(metadata: CatalogTable, buffer: ArrayBuffer[Row]): Unit = { | ||
| metadata.bucketSpec match { | ||
| case Some(BucketSpec(numBuckets, bucketColumnNames, sortColumnNames)) => | ||
| append(buffer, "Num Buckets:", numBuckets.toString, "") | ||
| append(buffer, "Bucket Columns:", bucketColumnNames.mkString("[", ", ", "]"), "") | ||
| append(buffer, "Sort Columns:", sortColumnNames.mkString("[", ", ", "]"), "") | ||
|
|
||
| case _ => | ||
| table.toLinkedHashMap.filterKeys(!excludedTableInfo.contains(_)).foreach { | ||
| s => append(buffer, s._1, s._2, "") | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -637,21 +578,7 @@ case class DescribeTableCommand( | |
| } | ||
| DDLUtils.verifyPartitionProviderIsHive(spark, metadata, "DESC PARTITION") | ||
| val partition = catalog.getPartition(table, partitionSpec) | ||
| if (isExtended) { | ||
| describeExtendedDetailedPartitionInfo(table, metadata, partition, result) | ||
| } else if (isFormatted) { | ||
| describeFormattedDetailedPartitionInfo(table, metadata, partition, result) | ||
| describeStorageInfo(metadata, result) | ||
| } | ||
| } | ||
|
|
||
| private def describeExtendedDetailedPartitionInfo( | ||
| tableIdentifier: TableIdentifier, | ||
| table: CatalogTable, | ||
| partition: CatalogTablePartition, | ||
| buffer: ArrayBuffer[Row]): Unit = { | ||
| append(buffer, "", "", "") | ||
| append(buffer, "Detailed Partition Information " + partition.toString, "", "") | ||
| if (isExtended) describeFormattedDetailedPartitionInfo(table, metadata, partition, result) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to this PR, but it looks weird that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function DESCRIBE [EXTENDED|FORMATTED] table_name PARTITION (partitionVal*) |
||
| } | ||
|
|
||
| private def describeFormattedDetailedPartitionInfo( | ||
|
|
@@ -661,18 +588,21 @@ case class DescribeTableCommand( | |
| buffer: ArrayBuffer[Row]): Unit = { | ||
| append(buffer, "", "", "") | ||
| append(buffer, "# Detailed Partition Information", "", "") | ||
| append(buffer, "Partition Value:", s"[${partition.spec.values.mkString(", ")}]", "") | ||
| append(buffer, "Database:", table.database, "") | ||
| append(buffer, "Table:", tableIdentifier.table, "") | ||
| append(buffer, "Location:", partition.storage.locationUri.map(CatalogUtils.URIToString(_)) | ||
| .getOrElse(""), "") | ||
| append(buffer, "Partition Parameters:", "", "") | ||
| partition.parameters.foreach { case (key, value) => | ||
| append(buffer, s" $key", value, "") | ||
| append(buffer, "Database", table.database, "") | ||
| append(buffer, "Table", tableIdentifier.table, "") | ||
| partition.toLinkedHashMap.foreach(s => append(buffer, s._1, s._2, "")) | ||
| append(buffer, "", "", "") | ||
| append(buffer, "# Storage Information", "", "") | ||
| table.bucketSpec match { | ||
| case Some(spec) => | ||
| spec.toLinkedHashMap.foreach(s => append(buffer, s._1, s._2, "")) | ||
| case _ => | ||
| } | ||
| table.storage.toLinkedHashMap.foreach(s => append(buffer, s._1, s._2, "")) | ||
| } | ||
|
|
||
| private def describeSchema(schema: StructType, buffer: ArrayBuffer[Row]): Unit = { | ||
| append(buffer, s"# ${output.head.name}", output(1).name, output(2).name) | ||
| schema.foreach { column => | ||
| append(buffer, column.name, column.dataType.simpleString, column.getComment().orNull) | ||
| } | ||
|
|
@@ -728,7 +658,7 @@ case class ShowTablesCommand( | |
| val tableName = tableIdent.table | ||
| val isTemp = catalog.isTemporaryTable(tableIdent) | ||
| if (isExtended) { | ||
| val information = catalog.getTempViewOrPermanentTableMetadata(tableIdent).toString | ||
| val information = catalog.getTempViewOrPermanentTableMetadata(tableIdent).simpleString | ||
| Row(database, tableName, isTemp, s"$information\n") | ||
| } else { | ||
| Row(database, tableName, isTemp) | ||
|
|
@@ -745,7 +675,7 @@ case class ShowTablesCommand( | |
| val database = table.database.getOrElse("") | ||
| val tableName = table.table | ||
| val isTemp = catalog.isTemporaryTable(table) | ||
| val information = partition.toString | ||
| val information = partition.simpleString | ||
| Seq(Row(database, tableName, isTemp, s"$information\n")) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems
DESC EXTENDEDis better, normalDESC tblis also formatedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me make the change.