From 9a83850b1cc30f8d788b2c7b59f1a68bae88e7c3 Mon Sep 17 00:00:00 2001 From: zhexuany Date: Fri, 3 Jan 2020 15:14:59 +0800 Subject: [PATCH] fix parition table isn't showded in show command --- .../spark/sql/execution/command/tables.scala | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala b/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala index 8553ce37ea..9c808942a5 100644 --- a/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala +++ b/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala @@ -34,22 +34,38 @@ case class TiShowTablesCommand(tiContext: TiContext, delegate: ShowTablesCommand extends TiCommand(delegate) { override def run(sparkSession: SparkSession): Seq[Row] = { val db = delegate.databaseName.getOrElse(tiCatalog.getCurrentDatabase) - // Show the information of tables. - val tables = - delegate.tableIdentifierPattern - .map(tiCatalog.listTables(db, _)) - .getOrElse(tiCatalog.listTables(db)) - tables.map { tableIdent => - val database = tableIdent.database.getOrElse("") - val tableName = tableIdent.table - val isTemp = tiCatalog.isTemporaryTable(tableIdent) - if (delegate.isExtended) { - val information = tiCatalog.getTempViewOrPermanentTableMetadata(tableIdent).simpleString - Row(database, tableName, isTemp, s"$information\n") - } else { - Row(database, tableName, isTemp) + if (delegate.partitionSpec.isEmpty) { + // Show the information of tables. + val tables = + delegate.tableIdentifierPattern + .map(tiCatalog.listTables(db, _)) + .getOrElse(tiCatalog.listTables(db)) + tables.map { tableIdent => + val database = tableIdent.database.getOrElse("") + val tableName = tableIdent.table + val isTemp = tiCatalog.isTemporaryTable(tableIdent) + if (delegate.isExtended) { + val information = tiCatalog.getTempViewOrPermanentTableMetadata(tableIdent).simpleString + Row(database, tableName, isTemp, s"$information\n") + } else { + Row(database, tableName, isTemp) + } } + } else { + // Show the information of partitions. + // + // Note: tableIdentifierPattern should be non-empty, otherwise a [[ParseException]] + // should have been thrown by the sql parser. + val tableIdent = TableIdentifier(delegate.tableIdentifierPattern.get, Some(db)) + val table = tiCatalog.getTableMetadata(tableIdent).identifier + val partition = tiCatalog.getPartition(tableIdent, delegate.partitionSpec.get) + val database = table.database.getOrElse("") + val tableName = table.table + val isTemp = tiCatalog.isTemporaryTable(table) + val information = partition.simpleString + Seq(Row(database, tableName, isTemp, s"$information\n")) } + } }