emaynardigs opened a new pull request #27155: [SPARK-17636][SPARK-25557][SQL] Parquet and ORC predicate pushdown in nested fields URL: https://github.com/apache/spark/pull/27155 Firstly, much of this PR is a rebase of PR#22535, much thanks to @dbtsai for his work. ### What changes were proposed in this pull request? Spark can now push down predicates on struct columns when reading Parquet and ORC tables. ### Why are the changes needed? There are significant performance gains to be had from pushing down predicates. ### Does this PR introduce any user-facing change? No ### How was this patch tested? Existing UT were extended to cover the new functionality. Sanity check tests: ``` //// Setup //// spark.range(1000 * 1000).toDF("id").selectExpr("id", "STRUCT(id x, STRUCT(CAST(id AS STRING) z) y) nested").write.mode("overwrite").parquet("/tmp/data") spark.range(1000 * 1000).toDF("id").selectExpr("id", "STRUCT(id x, STRUCT(CAST(id AS STRING) z) y) nested").write.mode("overwrite").orc("/tmp/data_orc") def hack_benchmark(f: (() => Any)): Double = { (0 to 100).map(i => { val start = System.currentTimeMillis f() (System.currentTimeMillis - start) }).sum / 100.0 } //// Without patch //// scala> spark.read.parquet("/tmp/data").filter("nested.x = 100").explain == Physical Plan == *(1) Project [id#0L, nested#1] +- *(1) Filter (isnotnull(nested#1) && (nested#1.x = 100)) +- *(1) FileScan parquet [id#0L,nested#1] Batched: false, Format: Parquet, Location: InMemoryFileIndex[file:/tmp/data], PartitionFilters: [], PushedFilters: [IsNotNull(nested)], ReadSchema: struct<id:bigint,nested:struct<x:bigint,y:string>> scala> spark.read.orc("/tmp/data_orc").filter("nested.x = 100").explain == Physical Plan == *(1) Project [id#9253L, nested#9254] +- *(1) Filter (isnotnull(nested#9254) && (nested#9254.x = 100)) +- *(1) FileScan orc [id#9253L,nested#9254] Batched: false, Format: ORC, Location: InMemoryFileIndex[file:/tmp/data_orc], PartitionFilters: [], PushedFilters: [IsNotNull(nested)], ReadSchema: struct<id:bigint,nested:struct<x:bigint,y:string>> scala> hack_benchmark(spark.read.parquet("/tmp/data").filter("nested.x < 100").count _) res0: Double = 419.82 scala> hack_benchmark(spark.read.orc("/tmp/data_orc").filter("nested.x < 100").count _) res5: Double = 1525.83 //// With patch //// scala> spark.read.parquet("/tmp/data").filter("nested.x = 100").explain == Physical Plan == *(1) Project [id#54L, nested#55] +- *(1) Filter (isnotnull(nested#55) AND (nested#55.x = 100)) +- BatchScan[id#54L, nested#55] ParquetScan Location: InMemoryFileIndex[file:/tmp/data], ReadSchema: struct<id:bigint,nested:struct<x:bigint,y:string>>, PushedFilters: [EqualTo(nested.x,100)] scala> spark.read.orc("/tmp/data_orc").filter("nested.x = 100").explain == Physical Plan == *(1) Project [id#0L, nested#1] +- *(1) Filter (isnotnull(nested#1) AND (nested#1.x = 100)) +- BatchScan[id#0L, nested#1] OrcScan Location: InMemoryFileIndex[file:/tmp/data_orc], ReadSchema: struct<id:bigint,nested:struct<x:bigint,y:struct<z:string>>>, PushedFilters: [EqualTo(nested.x,100)] scala> hack_benchmark(spark.read.parquet("/tmp/data").filter("nested.x < 100").count _) res0: Double = 192.15 scala> hack_benchmark(spark.read.orc("/tmp/data_orc").filter("nested.x < 100").count _) res1: Double = 1029.57 ``` Note the significant performance improvement and the inclusion of the filter in `PushedFilters` in both cases.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
