rdblue commented on a change in pull request #28026: [SPARK-31257][SQL] Unify
create table syntax (WIP)
URL: https://github.com/apache/spark/pull/28026#discussion_r401301040
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala
##########
@@ -1557,6 +1568,634 @@ class PlanResolutionSuite extends AnalysisTest {
checkFailure("testcat.tab", "foo")
}
+ private def compareNormalized(plan1: LogicalPlan, plan2: LogicalPlan): Unit
= {
+ /**
+ * Normalizes plans:
+ * - CreateTable the createTime in tableDesc will replaced by -1L.
+ */
+ def normalizePlan(plan: LogicalPlan): LogicalPlan = {
+ plan match {
+ case CreateTable(tableDesc, mode, query) =>
+ val newTableDesc = tableDesc.copy(createTime = -1L)
+ CreateTable(newTableDesc, mode, query)
+ case _ => plan // Don't transform
+ }
+ }
+ comparePlans(normalizePlan(plan1), normalizePlan(plan2))
+ }
+
+ test("create table - schema") {
+ def createTable(
+ table: String,
+ database: Option[String] = None,
+ tableType: CatalogTableType = CatalogTableType.MANAGED,
+ storage: CatalogStorageFormat = CatalogStorageFormat.empty.copy(
+ inputFormat = HiveSerDe.sourceToSerDe("textfile").get.inputFormat,
+ outputFormat = HiveSerDe.sourceToSerDe("textfile").get.outputFormat,
+ serde = Some("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe")),
+ schema: StructType = new StructType,
+ provider: Option[String] = Some("hive"),
+ partitionColumnNames: Seq[String] = Seq.empty,
+ comment: Option[String] = None,
+ mode: SaveMode = SaveMode.ErrorIfExists,
+ query: Option[LogicalPlan] = None): CreateTable = {
+ CreateTable(
+ CatalogTable(
+ identifier = TableIdentifier(table, database),
+ tableType = tableType,
+ storage = storage,
+ schema = schema,
+ provider = provider,
+ partitionColumnNames = partitionColumnNames,
+ comment = comment
+ ), mode, query
+ )
+ }
+
+ def compare(sql: String, plan: LogicalPlan): Unit = {
+ compareNormalized(parseAndResolve(sql), plan)
+ }
+
+ compare("CREATE TABLE my_tab(a INT COMMENT 'test', b STRING) STORED AS
textfile",
+ createTable(
+ table = "my_tab",
+ database = Some("default"),
+ schema = (new StructType)
+ .add("a", IntegerType, nullable = true, "test")
+ .add("b", StringType)
+ )
+ )
+ withSQLConf(SQLConf.LEGACY_CREATE_HIVE_TABLE_BY_DEFAULT_ENABLED.key ->
"true") {
Review comment:
@cloud-fan, this is the SQL that uses Hive without this patch because of the
`PARTITION BY` clause (and the statement using this config option below).
----------------------------------------------------------------
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]