Skip to content
Closed
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 @@ -1005,7 +1005,7 @@ trait ShowCreateTableCommandBase {

protected def showTableProperties(metadata: CatalogTable, builder: StringBuilder): Unit = {
if (metadata.properties.nonEmpty) {
val props = metadata.properties.map { case (key, value) =>
val props = metadata.properties.toSeq.sortBy(_._1).map { case (key, value) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably has nothing to do with this PR.

s"'${escapeSingleQuotedString(key)}' = '${escapeSingleQuotedString(value)}'"
}

Expand Down Expand Up @@ -1158,8 +1158,9 @@ case class ShowCreateTableCommand(
// If it is a Hive table, we already convert its metadata and fill in a provider.
builder ++= s"USING ${metadata.provider.get}\n"

val dataSourceOptions = conf.redactOptions(metadata.storage.properties).map {
case (key, value) => s"${quoteIdentifier(key)} '${escapeSingleQuotedString(value)}'"
val dataSourceOptions = conf.redactOptions(metadata.storage.properties).toSeq.sortBy(_._1).map {
case (key, value) =>
s"'${escapeSingleQuotedString(key)}' = '${escapeSingleQuotedString(value)}'"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep consistent with v2. also sort it.

}

if (dataSourceOptions.nonEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CREATE TABLE `default`.`tbl` (
`c` INT)
USING parquet
OPTIONS (
`a` '1')
'a' = '1')


-- !query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ abstract class ShowCreateTableSuite extends QueryTest with SQLTestUtils {
}
}

test("SPARK-37494: Unify v1 and v2 option output") {
withTable("ddl_test") {
sql(
s"""CREATE TABLE ddl_test (
| a STRING
|)
|USING json
|TBLPROPERTIES (
| 'b' = '1',
| 'a' = '2')
|OPTIONS (
| k4 'v4',
| `k3` 'v3',
| 'k5' 'v5',
| 'k1' = 'v1',
| k2 = 'v2'
|)
""".stripMargin
)
val expected = "CREATE TABLE `default`.`ddl_test` ( `a` STRING) USING json" +
" OPTIONS ( 'k1' = 'v1', 'k2' = 'v2', 'k3' = 'v3', 'k4' = 'v4', 'k5' = 'v5')" +
" TBLPROPERTIES ( 'a' = '2', 'b' = '1')"
assert(getShowDDL("SHOW CREATE TABLE ddl_test") == expected)
}
}

protected def getShowDDL(showCreateTableSql: String): String = {
sql(showCreateTableSql).head().getString(0).split("\n").map(_.trim).mkString(" ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,8 @@ class JDBCSuite extends QueryTest
.select("createtab_stmt").collect()
assert(createTabStmt.length === 1)
createTabStmt.foreach { r =>
assert(r.getString(0).contains(s"`url` '${Utils.REDACTION_REPLACEMENT_TEXT}'"))
assert(r.getString(0).contains(s"`password` '${Utils.REDACTION_REPLACEMENT_TEXT}'"))
assert(r.getString(0).contains(s"'url' = '${Utils.REDACTION_REPLACEMENT_TEXT}'"))
assert(r.getString(0).contains(s"'password' = '${Utils.REDACTION_REPLACEMENT_TEXT}'"))
}
}
}
Expand Down