Github user xwu0226 commented on a diff in the pull request: https://github.com/apache/spark/pull/16156#discussion_r90970607 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFilterSuite.scala --- @@ -578,4 +578,66 @@ class ParquetFilterSuite extends QueryTest with ParquetTest with SharedSQLContex // scalastyle:on nonascii } } + + test("SPARK-18539 - filtered by non-existing parquet column") { + Seq("parquet").foreach { format => + withSQLConf(SQLConf.PARQUET_FILTER_PUSHDOWN_ENABLED.key -> "true") { + withTempPath { path => + import testImplicits._ + Seq((1, "abc"), (2, "hello")).toDF("a", "b").write.format(format).save(path.toString) + + // user-specified schema contains nonexistent columns + val schema = StructType( + Seq(StructField("a", IntegerType), + StructField("b", StringType), + StructField("c", IntegerType))) + val readDf1 = spark.read.schema(schema).format(format).load(path.toString) + + // Read the table without any filter + checkAnswer(readDf1, Row(1, "abc", null) :: Row(2, "hello", null) :: Nil) + // Read the table with a filter on existing columns + checkAnswer(readDf1.filter("a < 2"), Row(1, "abc", null) :: Nil) + + // Read the table with a filter on nonexistent columns + checkAnswer(readDf1.filter("c < 2"), Nil) + checkAnswer(readDf1.filter("c is not null"), Nil) + + checkAnswer(readDf1.filter("c is null"), + Row(1, "abc", null) :: Row(2, "hello", null) :: Nil) + + checkAnswer(readDf1.filter("c is null and a < 2"), + Row(1, "abc", null) :: Nil) + + // With another parquet file that contains the column "c" + Seq((2, "abc", 3), (3, "hello", 4)).toDF("a", "b", "c") + .write.format(format).mode(SaveMode.Append).save(path.toString) + + // Right now, there are 2 parquet files. one with the column "c", + // the other does not have it. + val readDf2 = spark.read.schema(schema).format(format).load(path.toString) --- End diff -- Since the code change is in `SpecificParquetRecordReaderBase.initialize`, which is a common code path for both parquet readers, I did not include it originally. But it is safe to test both. I will add it . Thanks!
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org