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

    https://github.com/apache/spark/pull/19622#discussion_r148171454
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala ---
    @@ -630,32 +632,33 @@ private[spark] class HiveExternalCatalog(conf: 
SparkConf, hadoopConf: Configurat
         }
       }
     
    -  override def alterTableSchema(db: String, table: String, schema: 
StructType): Unit = withClient {
    +  override def alterTableDataSchema(
    +      db: String, table: String, newDataSchema: StructType): Unit = 
withClient {
         requireTableExists(db, table)
    -    val rawTable = getRawTable(db, table)
    -    // Add table metadata such as table schema, partition columns, etc. to 
table properties.
    -    val updatedProperties = rawTable.properties ++ 
tableMetaToTableProps(rawTable, schema)
    -    val withNewSchema = rawTable.copy(properties = updatedProperties, 
schema = schema)
    -    verifyColumnNames(withNewSchema)
    +    val oldTable = getTable(db, table)
    +    verifyDataSchema(oldTable.identifier, oldTable.tableType, 
newDataSchema)
    +
    +    val newProps = 
oldTable.properties.filterNot(_._1.startsWith(DATASOURCE_SCHEMA)) ++
    +      tableMetaToTableProps(oldTable, StructType(newDataSchema ++ 
oldTable.partitionSchema))
     
    -    if (isDatasourceTable(rawTable)) {
    +    if (isDatasourceTable(oldTable)) {
           // For data source tables, first try to write it with the schema 
set; if that does not work,
           // try again with updated properties and the partition schema. This 
is a simplified version of
           // what createDataSourceTable() does, and may leave the table in a 
state unreadable by Hive
           // (for example, the schema does not match the data source schema, 
or does not match the
           // storage descriptor).
           try {
    -        client.alterTable(withNewSchema)
    +        client.alterTableDataSchemaAndProps(db, table, newDataSchema, 
newProps)
           } catch {
             case NonFatal(e) =>
               val warningMessage =
    -            s"Could not alter schema of table  
${rawTable.identifier.quotedString} in a Hive " +
    +            s"Could not alter schema of table  
${oldTable.identifier.quotedString} in a Hive " +
    --- End diff --
    
    nit: an extra space before `${oldTable.identifier.quotedString}`.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to