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

    https://github.com/apache/spark/pull/3960#discussion_r22893043
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala ---
    @@ -50,8 +52,76 @@ private[hive] class HiveMetastoreCatalog(hive: 
HiveContext) extends Catalog with
       /** Connection to hive metastore.  Usages should lock on `this`. */
       protected[hive] val client = Hive.get(hive.hiveconf)
     
    +  // TODO: Use this everywhere instead of tuples or databaseName, 
tableName,.
    +  /** A fully qualified identifier for a table (i.e., database.tableName) 
*/
    +  case class QualifiedTableName(database: String, name: String) {
    +    def toLowerCase = QualifiedTableName(database.toLowerCase, 
name.toLowerCase)
    +  }
    +
    +  /** A cache of Spark SQL data source tables that have been accessed. */
    +  protected[hive] val cachedDataSourceTables: 
LoadingCache[QualifiedTableName, LogicalPlan] = {
    +    val cacheLoader = new CacheLoader[QualifiedTableName, LogicalPlan]() {
    +      override def load(in: QualifiedTableName): LogicalPlan = {
    +        logDebug(s"Creating new cached data source for $in")
    +        val table = client.getTable(in.database, in.name)
    +        val schemaString = table.getProperty("spark.sql.sources.schema")
    +        val userSpecifiedSchema =
    +          if (schemaString == null) {
    +            None
    +          } else {
    +            Some(DataType.fromJson(schemaString).asInstanceOf[StructType])
    +          }
    +        // It does not appear that the ql client for the metastore has a 
way to enumerate all the
    +        // SerDe properties directly...
    +        val options = 
table.getTTable.getSd.getSerdeInfo.getParameters.toMap
    +
    +        val resolvedRelation =
    +          ResolvedDataSource(
    +            hive,
    +            userSpecifiedSchema,
    +            table.getProperty("spark.sql.sources.provider"),
    +            options)
    +
    +        LogicalRelation(resolvedRelation.relation)
    +      }
    +    }
    +
    +    CacheBuilder.newBuilder().maximumSize(1000).build(cacheLoader)
    +  }
    +
    +  def refreshTable(databaseName: String, tableName: String): Unit = {
    +    cachedDataSourceTables.refresh(QualifiedTableName(databaseName, 
tableName).toLowerCase)
    +  }
    +
    +  def invalidateTable(databaseName: String, tableName: String): Unit = {
    --- End diff --
    
    These should probably also take `tableIdentifiers`?


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