diff options
author | bomeng <bmeng@us.ibm.com> | 2016-06-14 18:35:29 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2016-06-14 18:35:29 -0700 |
commit | 42a28caf1001244d617b9256de196129348f2fef (patch) | |
tree | 17bf44ac8aca8881b69c855f801fa63abad099c1 | |
parent | 0bd86c0fe4ebf05d817632a8665a02b379fa3cae (diff) | |
download | spark-42a28caf1001244d617b9256de196129348f2fef.tar.gz spark-42a28caf1001244d617b9256de196129348f2fef.tar.bz2 spark-42a28caf1001244d617b9256de196129348f2fef.zip |
[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.
3 files changed, 6 insertions, 6 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala index 60525794ed..14da30a36f 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala @@ -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 { diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/databases.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/databases.scala index cefe0f6e62..597ec27ce6 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/databases.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/databases.scala @@ -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] = { diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index a7e6893caa..e15fcf4326 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -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'"), |