Skip to content
Open
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 @@ -838,6 +838,13 @@ case class DescribeColumnCommand(
Row("data_type", dataType),
Row("comment", comment.getOrElse("NULL"))
)

// show default value if present
val defaultKey = CURRENT_DEFAULT_COLUMN_METADATA_KEY
if (field.metadata.contains(defaultKey)) {
buffer += Row("default", field.metadata.getString(defaultKey))
}

if (isExtended) {
// Show column stats when EXTENDED or FORMATTED is specified.
buffer += Row("min", cs.flatMap(_.min.map(
Expand All @@ -854,10 +861,6 @@ case class DescribeColumnCommand(
hist <- c.histogram
} yield histogramDescription(hist)
buffer ++= histDesc.getOrElse(Seq(Row("histogram", "NULL")))
val defaultKey = CURRENT_DEFAULT_COLUMN_METADATA_KEY
if (field.metadata.contains(defaultKey)) {
buffer += Row("default", field.metadata.getString(defaultKey))
}
}
buffer.toSeq
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,34 @@ trait DescribeTableSuiteBase extends command.DescribeTableSuiteBase
}
}

test("DESCRIBE table_name column_name should show default value") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is put in v1.DescribeTableSuiteBase. Does v2 tables have the same issue?

withTable("t") {
sql(s"""CREATE TABLE t(
| id INT,
| name STRING COMMENT 'name column' DEFAULT 'default',
| value DOUBLE
|) $defaultUsing""".stripMargin)
val descriptionDf = sql("DESCRIBE t name")
QueryTest.checkAnswer(
descriptionDf,
Seq(
Row("col_name", "name"),
Row("data_type", "string"),
Row("comment", "name column"),
Row("default", "'default'")))
}
}

test("DESCRIBE EXTENDED table_name column_name should not duplicate default value") {
withTable("t") {
sql(s"CREATE TABLE t(name STRING DEFAULT 'test') $defaultUsing")
val descriptionDf = sql("DESCRIBE TABLE EXTENDED t name")
val defaultRows = descriptionDf.collect().filter(_.getString(0) == "default")
assert(defaultRows.length == 1, "Default value should appear only once")
assert(defaultRows(0).getString(1) == "'test'")
}
}

test("DESCRIBE AS JSON partitions, clusters, buckets") {
withNamespaceAndTable("ns", "table") { t =>
val tableCreationStr =
Expand Down