Skip to content
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

fix parition table isn't shown in show command #1354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,36 @@ 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"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ class CatalogTestSuite extends BaseTiSparkTest {
spark.sql("drop table if exists t")
}

test("test show hive partition table") {
refreshConnections(true)
setCurrentDatabase("default")
spark.sql("drop table if exists salesdata")
spark.sql(
"create table salesdata (salesperson_id int, product_id int) partitioned by (date_of_sale string)"
)
spark.conf.set("hive.exec.dynamic.partition.mode", "nonstrict")
spark.sql("insert into table salesdata values(0, 1, '10-27-2017')")
spark.sql("insert into table salesdata values(0, 1, '10-28-2017')")
spark.sql("insert into table salesdata values(0, 1, '10-29-2017')")
val partitionsRes =
List(
List("date_of_sale=10-27-2017"),
List("date_of_sale=10-28-2017"),
List("date_of_sale=10-29-2017")
)
runTest("show partitions salesdata", skipJDBC = true, rTiDB = partitionsRes)
spark.sql("drop table if exists salesdata")
}

test("test support show columns") {
val columnNames = List(
List("id_dt"),
Expand Down