gengliangwang commented on a change in pull request #24938: [SPARK-27946][SQL]
Hive DDL to Spark DDL conversion USING "show create table"
URL: https://github.com/apache/spark/pull/24938#discussion_r373709698
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
##########
@@ -1002,7 +1002,109 @@ case class ShowPartitionsCommand(
}
}
-case class ShowCreateTableCommand(table: TableIdentifier) extends
RunnableCommand {
+/**
+ * Provides common utilities between `ShowCreateTableCommand` and
`ShowCreateTableAsSparkCommand`.
+ */
+trait ShowCreateTableCommandBase {
+
+ protected val table: TableIdentifier
+
+ protected def showTableLocation(metadata: CatalogTable, builder:
StringBuilder): Unit = {
+ if (metadata.tableType == EXTERNAL) {
+ metadata.storage.locationUri.foreach { location =>
+ builder ++= s"LOCATION
'${escapeSingleQuotedString(CatalogUtils.URIToString(location))}'\n"
+ }
+ }
+ }
+
+ protected def showTableComment(metadata: CatalogTable, builder:
StringBuilder): Unit = {
+ metadata
+ .comment
+ .map("COMMENT '" + escapeSingleQuotedString(_) + "'\n")
+ .foreach(builder.append)
+ }
+
+ protected def showTableProperties(metadata: CatalogTable, builder:
StringBuilder): Unit = {
+ if (metadata.properties.nonEmpty) {
+ val props = metadata.properties.map { case (key, value) =>
+ s"'${escapeSingleQuotedString(key)}' =
'${escapeSingleQuotedString(value)}'"
+ }
+
+ builder ++= "TBLPROPERTIES "
+ builder ++= concatByMultiLines(props)
+ }
+ }
+
+ protected def showDataSourceTableDataColumns(
+ metadata: CatalogTable, builder: StringBuilder): Unit = {
+ val columns = metadata.schema.fields.map(_.toDDL)
+ builder ++= concatByMultiLines(columns)
+ }
+
+ protected def showDataSourceTableOptions(metadata: CatalogTable, builder:
StringBuilder): Unit = {
+ builder ++= s"USING ${metadata.provider.get}\n"
Review comment:
Is `metadata.provider` always defined here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]