Skip to content

Commit 72940b3

Browse files
committed
[SPARK-37924][SQL] Sort table properties by key in SHOW CREATE TABLE on VIEW (v1)
### What changes were proposed in this pull request? This PR is a sort of a followup of #34719. It added a test but it is flaky due to the order of `TABLPROPERTIES` in `SHOW CREATE TALBE` on `VIEW` in v1 code path. This PR proposes to have a deterministic order by sorting the table properties in the show command. This is already being sorted in v2 (see `ShowCreateTableExec`). ### Why are the changes needed? To have the deterministic order, and fix the flaky test. ### Does this PR introduce _any_ user-facing change? Virtually no. It might affect the order of TABLEPROPERTIES in `SHOW TABLE`'s output on `VIEW` when users are rely on ### How was this patch tested? Fixed the flaky unittest to explicitly test the order. Closes #35222 from HyukjinKwon/SPARK-37924. Authored-by: Hyukjin Kwon <gurwls223@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent 0841579 commit 72940b3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ trait ShowCreateTableCommandBase {
10431043
private def showViewProperties(metadata: CatalogTable, builder: StringBuilder): Unit = {
10441044
val viewProps = metadata.properties.filterKeys(!_.startsWith(CatalogTable.VIEW_PREFIX))
10451045
if (viewProps.nonEmpty) {
1046-
val props = viewProps.map { case (key, value) =>
1046+
val props = viewProps.toSeq.sortBy(_._1).map { case (key, value) =>
10471047
s"'${escapeSingleQuotedString(key)}' = '${escapeSingleQuotedString(value)}'"
10481048
}
10491049

sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewTestSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ class PersistedViewTestSuite extends SQLViewTestSuite with SharedSparkSession {
634634
Seq(true, false).foreach { serde =>
635635
withView(viewName) {
636636
createView(viewName, "SELECT 1 AS c1, '2' AS c2", Seq("c1 COMMENT 'bla'", "c2"),
637-
Seq("COMMENT 'table comment'", "TBLPROPERTIES ( 'prop1' = 'value1', 'prop2' = 'value2')"))
637+
Seq("COMMENT 'table comment'", "TBLPROPERTIES ( 'prop2' = 'value2', 'prop1' = 'value1')"))
638638

639639
val expected = "CREATE VIEW `default`.`v1` ( `c1` COMMENT 'bla', `c2`)" +
640640
" COMMENT 'table comment'" +

0 commit comments

Comments
 (0)