Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14207#discussion_r71633776
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala 
---
    @@ -252,6 +252,222 @@ class DDLSuite extends QueryTest with 
SharedSQLContext with BeforeAndAfterEach {
         }
       }
     
    +  private def createDataSourceTable(
    +      path: File,
    +      userSpecifiedSchema: Option[String],
    +      userSpecifiedPartitionCols: Option[String]): (StructType, 
Seq[String]) = {
    +    var tableSchema = StructType(Nil)
    +    var partCols = Seq.empty[String]
    +
    +    val tabName = "tab1"
    +    withTable(tabName) {
    +      val partitionClause =
    +        userSpecifiedPartitionCols.map(p => s"PARTITIONED BY 
($p)").getOrElse("")
    +      val schemaClause = userSpecifiedSchema.map(s => 
s"($s)").getOrElse("")
    +      sql(
    +        s"""
    +           |CREATE TABLE $tabName $schemaClause
    +           |USING parquet
    +           |OPTIONS (
    +           |  path '$path'
    +           |)
    +           |$partitionClause
    +         """.stripMargin)
    +      val tableMetadata = 
spark.sessionState.catalog.getTableMetadata(TableIdentifier(tabName))
    +
    +      tableSchema = DDLUtils.getSchemaFromTableProperties(tableMetadata)
    +      partCols = 
DDLUtils.getPartitionColumnsFromTableProperties(tableMetadata)
    +    }
    +    (tableSchema, partCols)
    +  }
    +
    +  test("Create partitioned data source table without user specified 
schema") {
    +    import testImplicits._
    +    val df = sparkContext.parallelize(1 to 10).map(i => (i, 
i.toString)).toDF("num", "str")
    +
    +    // Case 1: with partitioning columns but no schema: 
Option("inexistentColumns")
    +    // Case 2: without schema and partitioning columns: None
    +    Seq(Option("inexistentColumns"), None).foreach { partitionCols =>
    +      withTempPath { pathToPartitionedTable =>
    +        df.write.format("parquet").partitionBy("num")
    +          .save(pathToPartitionedTable.getCanonicalPath)
    +        val (tableSchema, partCols) =
    +          createDataSourceTable(
    +            pathToPartitionedTable,
    +            userSpecifiedSchema = None,
    +            userSpecifiedPartitionCols = partitionCols)
    +        assert(tableSchema ==
    +          StructType(StructField("str", StringType, nullable = true) ::
    --- End diff --
    
    Sure, will do. 


---
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]

Reply via email to