Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/16600#discussion_r96184995
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
@@ -789,55 +789,50 @@ case class ShowCreateTableCommand(table:
TableIdentifier) extends RunnableComman
)
override def run(sparkSession: SparkSession): Seq[Row] = {
- val catalog = sparkSession.sessionState.catalog
- val tableMetadata = catalog.getTableMetadata(table)
-
- // TODO: unify this after we unify the CREATE TABLE syntax for hive
serde and data source table.
- val stmt = if (DDLUtils.isDatasourceTable(tableMetadata)) {
- showCreateDataSourceTable(tableMetadata)
- } else {
- showCreateHiveTable(tableMetadata)
- }
+ val tableMeta =
sparkSession.sessionState.catalog.getTableMetadata(table)
+ val tableName = tableMeta.identifier.quotedString
- Seq(Row(stmt))
- }
-
- private def showCreateHiveTable(metadata: CatalogTable): String = {
- def reportUnsupportedError(features: Seq[String]): Unit = {
+ if (tableMeta.unsupportedFeatures.nonEmpty) {
throw new AnalysisException(
- s"Failed to execute SHOW CREATE TABLE against table/view
${metadata.identifier}, " +
+ s"Failed to execute SHOW CREATE TABLE against table/view
$tableName, " +
"which is created by Hive and uses the following unsupported
feature(s)\n" +
- features.map(" - " + _).mkString("\n")
- )
+ tableMeta.unsupportedFeatures.map(" - " + _).mkString("\n"))
}
- if (metadata.unsupportedFeatures.nonEmpty) {
- reportUnsupportedError(metadata.unsupportedFeatures)
- }
+ val stmt = if (tableMeta.tableType == VIEW) {
+ val builder = StringBuilder.newBuilder
+ builder ++= s"CREATE VIEW $tableName"
- val builder = StringBuilder.newBuilder
+ if (tableMeta.schema.nonEmpty) {
+ builder ++= tableMeta.schema.map(_.name).mkString("(", ", ", ")")
+ }
- val tableTypeString = metadata.tableType match {
- case EXTERNAL => " EXTERNAL TABLE"
- case VIEW => " VIEW"
- case MANAGED => " TABLE"
+ builder ++= s" AS\n${tableMeta.viewText.get}"
+ builder.toString
+ } else if (DDLUtils.isHiveTable(tableMeta) &&
tableMeta.properties.nonEmpty) {
--- End diff --
this condition is true most of the time, because Hive metastore will
generate some table properties.
https://issues.apache.org/jira/browse/SPARK-19241 is tracking it
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]