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
[SPARK-37150][SQL] Migrate DESCRIBE NAMESPACE to use V2 command by default #34429
Changes from 4 commits
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 |
---|---|---|
|
@@ -44,10 +44,13 @@ case class DescribeNamespaceExec( | |
} | ||
|
||
if (isExtended) { | ||
val properties = metadata.asScala -- CatalogV2Util.NAMESPACE_RESERVED_PROPERTIES | ||
if (properties.nonEmpty) { | ||
rows += toCatalystRow("Properties", properties.toSeq.mkString("(", ",", ")")) | ||
val properties = metadata.asScala.toMap -- CatalogV2Util.NAMESPACE_RESERVED_PROPERTIES | ||
val propertiesStr = if (properties.isEmpty) { | ||
"" | ||
} else { | ||
properties.toSeq.mkString("(", ", ", ")") | ||
} | ||
rows += toCatalystRow("Properties", propertiesStr) | ||
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. @cloud-fan These are the differences between v1 and v2 command:
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. I think it's OK to make this behavior change (database -> namespace). People can still fallback to v1 command if needed. The tests need to be a bit more complicated though, to allow different results between v1 and v2 commands. |
||
} | ||
rows.toSeq | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package org.apache.spark.sql.execution.command | ||
|
||
import org.apache.spark.sql.{AnalysisException, QueryTest} | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
/** | ||
* This base suite contains unified tests for the `DESCRIBE NAMESPACE` command that check V1 and V2 | ||
|
@@ -47,4 +48,21 @@ trait DescribeNamespaceSuiteBase extends QueryTest with DDLCommandTestUtils { | |
// TODO: Move this to DropNamespaceSuite when the test suite is introduced. | ||
sql(s"DROP NAMESPACE IF EXISTS $catalog.$ns") | ||
} | ||
|
||
test("Keep the legacy output schema") { | ||
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 is now run for both v1/v2 catalogs. |
||
Seq(true, false).foreach { keepLegacySchema => | ||
withSQLConf(SQLConf.LEGACY_KEEP_COMMAND_OUTPUT_SCHEMA.key -> keepLegacySchema.toString) { | ||
val ns = "db1" | ||
withNamespace(ns) { | ||
sql(s"CREATE NAMESPACE $ns") | ||
val schema = sql(s"DESCRIBE NAMESPACE $ns").schema.fieldNames.toSeq | ||
if (keepLegacySchema) { | ||
assert(schema === Seq("database_description_item", "database_description_value")) | ||
} else { | ||
assert(schema === Seq("info_name", "info_value")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ package org.apache.spark.sql.execution.command.v1 | |
|
||
import org.apache.spark.sql.Row | ||
import org.apache.spark.sql.execution.command | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
/** | ||
* This base suite contains unified tests for the `DESCRIBE NAMESPACE` command that checks V1 | ||
|
@@ -30,7 +29,8 @@ import org.apache.spark.sql.internal.SQLConf | |
* - V1 Hive External catalog: | ||
* `org.apache.spark.sql.hive.execution.command.DescribeNamespaceSuite` | ||
*/ | ||
trait DescribeNamespaceSuiteBase extends command.DescribeNamespaceSuiteBase { | ||
trait DescribeNamespaceSuiteBase extends command.DescribeNamespaceSuiteBase | ||
with command.TestsV1AndV2Commands { | ||
override def notFoundMsgPrefix: String = "Database" | ||
|
||
test("basic") { | ||
|
@@ -43,35 +43,21 @@ trait DescribeNamespaceSuiteBase extends command.DescribeNamespaceSuiteBase { | |
.where("key not like 'Owner%'") // filter for consistency with in-memory catalog | ||
.collect() | ||
|
||
val namePrefix = if (conf.useV1Command) "Database" else "Namespace" | ||
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 will be the only difference b/w v1 and v2 command. |
||
assert(result.length == 4) | ||
assert(result(0) === Row("Database Name", ns)) | ||
assert(result(0) === Row(s"$namePrefix Name", ns)) | ||
assert(result(1) === Row("Comment", "")) | ||
// Check only the key for "Location" since its value depends on warehouse path, etc. | ||
assert(result(2).getString(0) === "Location") | ||
assert(result(3) === Row("Properties", "")) | ||
} | ||
} | ||
|
||
test("Keep the legacy output schema") { | ||
Seq(true, false).foreach { keepLegacySchema => | ||
withSQLConf(SQLConf.LEGACY_KEEP_COMMAND_OUTPUT_SCHEMA.key -> keepLegacySchema.toString) { | ||
val ns = "db1" | ||
withNamespace(ns) { | ||
sql(s"CREATE NAMESPACE $ns") | ||
val schema = sql(s"DESCRIBE NAMESPACE $ns").schema.fieldNames.toSeq | ||
if (keepLegacySchema) { | ||
assert(schema === Seq("database_description_item", "database_description_value")) | ||
} else { | ||
assert(schema === Seq("info_name", "info_value")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The class contains tests for the `DESCRIBE NAMESPACE` command to check V1 In-Memory | ||
* table catalog. | ||
*/ | ||
class DescribeNamespaceSuite extends DescribeNamespaceSuiteBase with CommandSuiteBase | ||
class DescribeNamespaceSuite extends DescribeNamespaceSuiteBase with CommandSuiteBase { | ||
override def commandVersion: String = super[DescribeNamespaceSuiteBase].commandVersion | ||
} |
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.
Adding
toMap
similar tospark/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala
Line 321 in 8238cdd
The Scala Map implementation uses a list underneath up to 4 elements and maintains it in the order it was inserted. So this make tests such as
spark/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
Line 778 in 8238cdd
Maybe, just make the tests more robust?
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.
I just changed the command to sort the properties by keys (similar to
show tblproperties
).