Skip to content

Commit

Permalink
[SPARK-19905][SQL] Bring back Dataset.inputFiles for Hive SerDe tables
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

`Dataset.inputFiles` works by matching `FileRelation`s in the query plan. In Spark 2.1, Hive SerDe tables are represented by `MetastoreRelation`, which inherits from `FileRelation`. However, in Spark 2.2, Hive SerDe tables are now represented by `CatalogRelation`, which doesn't inherit from `FileRelation` anymore, due to the unification of Hive SerDe tables and data source tables. This change breaks `Dataset.inputFiles` for Hive SerDe tables.

This PR tries to fix this issue by explicitly matching `CatalogRelation`s that are Hive SerDe tables in `Dataset.inputFiles`. Note that we can't make `CatalogRelation` inherit from `FileRelation` since not all `CatalogRelation`s are file based (e.g., JDBC data source tables).

## How was this patch tested?

New test case added in `HiveDDLSuite`.

Author: Cheng Lian <[email protected]>

Closes apache#17247 from liancheng/spark-19905-hive-table-input-files.
  • Loading branch information
liancheng authored and cloud-fan committed Mar 10, 2017
1 parent bc30351 commit ffee4f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.catalyst._
import org.apache.spark.sql.catalyst.analysis._
import org.apache.spark.sql.catalyst.catalog.CatalogRelation
import org.apache.spark.sql.catalyst.encoders._
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.aggregate._
Expand Down Expand Up @@ -2734,6 +2735,8 @@ class Dataset[T] private[sql](
fsBasedRelation.inputFiles
case fr: FileRelation =>
fr.inputFiles
case r: CatalogRelation if DDLUtils.isHiveTable(r.tableMeta) =>
r.tableMeta.storage.locationUri.map(_.toString).toArray
}.flatten
files.toSet.toArray
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1865,4 +1865,15 @@ class HiveDDLSuite
}
}
}

test("SPARK-19905: Hive SerDe table input paths") {
withTable("spark_19905") {
withTempView("spark_19905_view") {
spark.range(10).createOrReplaceTempView("spark_19905_view")
sql("CREATE TABLE spark_19905 STORED AS RCFILE AS SELECT * FROM spark_19905_view")
assert(spark.table("spark_19905").inputFiles.nonEmpty)
assert(sql("SELECT input_file_name() FROM spark_19905").count() > 0)
}
}
}
}

0 comments on commit ffee4f1

Please sign in to comment.