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

    https://github.com/apache/spark/pull/13120#discussion_r63719953
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/createDataSourceTables.scala
 ---
    @@ -348,13 +349,23 @@ object CreateDataSourceTableUtils extends Logging {
             className = provider,
             options = options)
     
    -    def newSparkSQLSpecificMetastoreTable(): CatalogTable = {
    +    def newSparkSQLSpecificMetastoreTable(relation: HadoopFsRelation): 
CatalogTable = {
           CatalogTable(
             identifier = tableIdent,
             tableType = tableType,
             schema = Nil,
             storage = CatalogStorageFormat(
    -          locationUri = None,
    +          // We don't want Hive metastore to implicitly create a table 
directory,
    +          // which may be not the one Data Source table is referring to,
    +          // yet which will be left behind when the table is dropped for 
an external table
    +          locationUri = if (isExternal) {
    +            Some(relation.location.paths.map(_.toUri.toString).map {
    +              case p if new File(p).isDirectory => p
    +              case p => new File(p).getParent
    --- End diff --
    
    @liancheng In this code path, we are creating a non-hive compatible 
metastore table, which means we don't expect users to query the table from Hive 
directly and get the correct results, right? And the purpose of populating this 
locationURI is to avoid hive metastore to implicitly create a directory.  A 
query against the table from spark sql will use the path set in 
`CatalogTable.storage.serdeProperties.get("path")`. So I think it is OK that 
the single file lives in a directory containing multiple files, right?


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