dtenedor commented on code in PR #39726: URL: https://github.com/apache/spark/pull/39726#discussion_r1086099890
########## sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala: ########## @@ -645,6 +645,17 @@ case class DescribeTableCommand( } else if (isExtended) { describeFormattedTableInfo(metadata, result) } + + // If any columns have default values, append them to the result. + if (metadata.schema.fields.exists(_.metadata.contains( + ResolveDefaultColumns.CURRENT_DEFAULT_COLUMN_METADATA_KEY))) { Review Comment: Done. ########## sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala: ########## @@ -645,6 +645,17 @@ case class DescribeTableCommand( } else if (isExtended) { describeFormattedTableInfo(metadata, result) } + + // If any columns have default values, append them to the result. + if (metadata.schema.fields.exists(_.metadata.contains( + ResolveDefaultColumns.CURRENT_DEFAULT_COLUMN_METADATA_KEY))) { + append(result, "", "", "") + append(result, "# Column Default Information", "", "") Review Comment: Sounds good, done. ########## sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructField.scala: ########## @@ -160,7 +164,7 @@ case class StructField( */ def toDDL: String = { val nullString = if (nullable) "" else " NOT NULL" - s"${quoteIfNeeded(name)} ${dataType.sql}${nullString}$getDDLComment" + s"${quoteIfNeeded(name)} ${dataType.sql}${nullString}$getDDLDefault$getDDLComment" Review Comment: Good Q, I added a test case covering this. ########## sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowCreateTableSuite.scala: ########## @@ -161,6 +161,30 @@ trait ShowCreateTableSuiteBase extends command.ShowCreateTableSuiteBase assert(cause.getMessage.contains("Use `SHOW CREATE TABLE` without `AS SERDE` instead")) } } + + test("show create table with default column values") { + withNamespaceAndTable(ns, table) { t => + sql( + s""" + |CREATE TABLE $t ( + | a bigint NOT NULL, + | b bigint DEFAULT 42, + | c string DEFAULT 'abc' COMMENT 'comment' + |) + |using parquet Review Comment: Done ########## sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructField.scala: ########## @@ -141,6 +141,10 @@ case class StructField( } } + private def getDDLDefault = getCurrentDefaultValue() + .map(" DEFAULT " + _) Review Comment: Good question, I was originally confused about this as well :) the default value is exactly the string that appeared in the CREATE TABLE or ALTER TABLE statement. So, for example, if we had `CREATE TABLE t (a STRING DEFAULT 'str')`, then this column metadata has the value `'str'` (including the single-quotes). So we have to print them back exactly as-is here (e.g. I tried adding `escapeSingleQuotedString` like `getDDLComment` below, but it added extra escaping which we did not want). The extra test cases you suggested should show that this works even for different types of string-typed defaults. ########## sql/core/src/test/resources/sql-tests/inputs/describe.sql: ########## @@ -97,3 +97,14 @@ DROP VIEW temp_v; DROP VIEW temp_Data_Source_View; DROP VIEW v; + +-- Show column default values +CREATE TABLE d (a STRING, b INT DEFAULT 42) USING parquet COMMENT 'table_comment'; Review Comment: Sounds good, done. ########## sql/core/src/test/resources/sql-tests/inputs/show-create-table.sql: ########## @@ -45,6 +45,14 @@ SHOW CREATE TABLE tbl; DROP TABLE tbl; +-- default column values +CREATE TABLE tbl (a INT, b STRING DEFAULT 'abc', c INT DEFAULT 42) USING parquet Review Comment: Done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org