[SPARK-15952][SQL] fix "show databases" ordering issue

## What changes were proposed in this pull request?

Two issues I've found for "show databases" command:

1. The returned database name list was not sorted, it only works when "like" was used together; (HIVE will always return a sorted list)

2. When it is used as sql("show databases").show, it will output a table with column named as "result", but for sql("show tables").show, it will output the column name as "tableName", so I think we should be consistent and use "databaseName" at least.

## How was this patch tested?

Updated existing test case to test its ordering as well.

Author: bomeng <bmeng@us.ibm.com>

Closes #13671 from bomeng/SPARK-15952.
This commit is contained in:
bomeng 2016-06-14 18:35:29 -07:00 committed by Reynold Xin
parent 0bd86c0fe4
commit 42a28caf10
3 changed files with 6 additions and 6 deletions

View file

@ -178,7 +178,7 @@ class InMemoryCatalog(hadoopConfig: Configuration = new Configuration) extends E
}
override def listDatabases(): Seq[String] = synchronized {
catalog.keySet.toSeq
catalog.keySet.toSeq.sorted
}
override def listDatabases(pattern: String): Seq[String] = synchronized {

View file

@ -33,9 +33,9 @@ import org.apache.spark.sql.types.StringType
*/
case class ShowDatabasesCommand(databasePattern: Option[String]) extends RunnableCommand {
// The result of SHOW DATABASES has one column called 'result'
// The result of SHOW DATABASES has one column called 'databaseName'
override val output: Seq[Attribute] = {
AttributeReference("result", StringType, nullable = false)() :: Nil
AttributeReference("databaseName", StringType, nullable = false)() :: Nil
}
override def run(sparkSession: SparkSession): Seq[Row] = {

View file

@ -708,11 +708,11 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
test("show databases") {
sql("CREATE DATABASE showdb1A")
sql("CREATE DATABASE showdb2B")
sql("CREATE DATABASE showdb1A")
assert(
sql("SHOW DATABASES").count() >= 2)
// check the result as well as its order
checkDataset(sql("SHOW DATABASES"), Row("default"), Row("showdb1a"), Row("showdb2b"))
checkAnswer(
sql("SHOW DATABASES LIKE '*db1A'"),