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

    https://github.com/apache/spark/pull/14207#discussion_r73940895
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
    @@ -521,31 +521,29 @@ object DDLUtils {
         table.partitionColumns.nonEmpty || 
table.properties.contains(DATASOURCE_SCHEMA_NUMPARTCOLS)
       }
     
    -  // A persisted data source table may not store its schema in the 
catalog. In this case, its schema
    -  // will be inferred at runtime when the table is referenced.
    -  def getSchemaFromTableProperties(metadata: CatalogTable): 
Option[StructType] = {
    +  // A persisted data source table always store its schema in the catalog.
    +  def getSchemaFromTableProperties(metadata: CatalogTable): StructType = {
         require(isDatasourceTable(metadata))
    +    val msgSchemaCorrupted = "Could not read schema from the metastore 
because it is corrupted."
         val props = metadata.properties
    -    if (props.isDefinedAt(DATASOURCE_SCHEMA)) {
    +    props.get(DATASOURCE_SCHEMA).map { schema =>
           // Originally, we used spark.sql.sources.schema to store the schema 
of a data source table.
           // After SPARK-6024, we removed this flag.
           // Although we are not using spark.sql.sources.schema any more, we 
need to still support.
    -      
props.get(DATASOURCE_SCHEMA).map(DataType.fromJson(_).asInstanceOf[StructType])
    -    } else {
    -      metadata.properties.get(DATASOURCE_SCHEMA_NUMPARTS).map { numParts =>
    +      DataType.fromJson(schema).asInstanceOf[StructType]
    +    } getOrElse {
    --- End diff --
    
    I am not sure if `getOrElse` makes the code easier to follow.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to