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

    https://github.com/apache/spark/pull/5876#discussion_r29883765
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala ---
    @@ -144,39 +147,43 @@ private[hive] class HiveMetastoreCatalog(hive: 
HiveContext) extends Catalog with
           options: Map[String, String],
           isExternal: Boolean): Unit = {
         val (dbName, tblName) = processDatabaseAndTableName("default", 
tableName)
    -    val tbl = new Table(dbName, tblName)
    -
    -    tbl.setProperty("spark.sql.sources.provider", provider)
    +    val tableProperties = new scala.collection.mutable.HashMap[String, 
String]
    +    tableProperties.put("spark.sql.sources.provider", provider)
         if (userSpecifiedSchema.isDefined) {
           val threshold = hive.conf.schemaStringLengthThreshold
           val schemaJsonString = userSpecifiedSchema.get.json
           // Split the JSON string.
           val parts = schemaJsonString.grouped(threshold).toSeq
    -      tbl.setProperty("spark.sql.sources.schema.numParts", 
parts.size.toString)
    +      tableProperties.put("spark.sql.sources.schema.numParts", 
parts.size.toString)
           parts.zipWithIndex.foreach { case (part, index) =>
    -        tbl.setProperty(s"spark.sql.sources.schema.part.${index}", part)
    +        tableProperties.put(s"spark.sql.sources.schema.part.${index}", 
part)
           }
         }
    -    options.foreach { case (key, value) => tbl.setSerdeParam(key, value) }
     
    -    if (isExternal) {
    -      tbl.setProperty("EXTERNAL", "TRUE")
    -      tbl.setTableType(TableType.EXTERNAL_TABLE)
    +    val tableType = if (isExternal) {
    +      tableProperties.put("EXTERNAL", "TRUE")
    +      ExternalTable
         } else {
    -      tbl.setProperty("EXTERNAL", "FALSE")
    -      tbl.setTableType(TableType.MANAGED_TABLE)
    -    }
    -
    -    // create the table
    -    synchronized {
    -      client.createTable(tbl, false)
    -    }
    +      tableProperties.put("EXTERNAL", "FALSE")
    +      ManagedTable
    +    }
    +
    +    client.createTable(
    +      HiveTable(
    +        specifiedDatabase = Option(dbName),
    +        name = tblName,
    +        schema = Seq.empty,
    +        partitionColumns = Seq.empty,
    +        tableType = tableType,
    +        properties = tableProperties.toMap,
    +        serdeProperties = options))
       }
     
       def hiveDefaultTableFilePath(tableName: String): String = synchronized {
    -    val currentDatabase = 
client.getDatabase(hive.sessionState.getCurrentDatabase)
    -
    -    hiveWarehouse.getTablePath(currentDatabase, tableName).toString
    +    // Code based on: hiveWarehouse.getTablePath(currentDatabase, 
tableName)
    +    new Path(
    +      new Path(client.getDatabase(client.currentDatabase).location),
    +      tableName.toLowerCase).toString
       }
     
       def tableExists(tableIdentifier: Seq[String]): Boolean = synchronized {
    --- End diff --
    
    Should we remove this explicit `synchronized`? There are a few places where 
we still have it.


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