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 @@ -559,7 +559,8 @@ class ResolveSessionCatalog(
"SHOW VIEWS, only SessionCatalog supports this command.")
}

case ShowTableProperties(r: ResolvedTable, propertyKey) if isSessionCatalog(r.catalog) =>
case ShowTableProperties(
r @ ResolvedTable(_, _, _: V1Table), propertyKey) if isSessionCatalog(r.catalog) =>
ShowTablePropertiesCommand(r.identifier.asTableIdentifier, propertyKey)

case ShowTableProperties(r: ResolvedView, propertyKey) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package org.apache.spark.sql.execution.datasources.v2

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.encoders.RowEncoder
import org.apache.spark.sql.catalyst.expressions.{Attribute, GenericRowWithSchema}
import org.apache.spark.sql.connector.catalog.Table
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeSet, GenericRowWithSchema}
import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Table, TableCatalog}

/**
* Physical plan node for showing table properties.
Expand All @@ -30,11 +30,15 @@ case class ShowTablePropertiesExec(
catalogTable: Table,
propertyKey: Option[String]) extends V2CommandExec {

override def producedAttributes: AttributeSet = AttributeSet(output)

override protected def run(): Seq[InternalRow] = {
import scala.collection.JavaConverters._
val toRow = RowEncoder(schema).resolveAndBind().createSerializer()

// The reservered properties are accessible through DESCRIBE
val properties = catalogTable.properties.asScala
.filter { case (k, v) => !CatalogV2Util.TABLE_RESERVED_PROPERTIES.contains(k) }
propertyKey match {
case Some(p) =>
val propValue = properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.sql.connector

import org.apache.spark.sql.{DataFrame, SaveMode}
import org.apache.spark.sql.{DataFrame, Row, SaveMode}
import org.apache.spark.sql.connector.catalog.{Identifier, Table, TableCatalog}

class DataSourceV2SQLSessionCatalogSuite
Expand Down Expand Up @@ -63,4 +63,20 @@ class DataSourceV2SQLSessionCatalogSuite
}
}
}

test("SPARK-31624: SHOW TBLPROPERTIES working with V2 tables and the session catalog") {
val t1 = "tbl"
withTable(t1) {
sql(s"CREATE TABLE $t1 (id bigint, data string) USING $v2Format TBLPROPERTIES " +
"(key='v', key2='v2')")

checkAnswer(sql(s"SHOW TBLPROPERTIES $t1"), Seq(Row("key", "v"), Row("key2", "v2")))

checkAnswer(sql(s"SHOW TBLPROPERTIES $t1('key')"), Row("key", "v"))

checkAnswer(
sql(s"SHOW TBLPROPERTIES $t1('keyX')"),
Row("keyX", s"Table default.$t1 does not have property: keyX"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2122,8 +2122,6 @@ class DataSourceV2SQLSuite
.add("value", StringType, nullable = false)

val expected = Seq(
Row(TableCatalog.PROP_OWNER, defaultUser),
Row("provider", provider),
Row("status", status),
Row("user", user))

Expand Down