Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ abstract class PartitioningAwareFileIndex(
}

// retrieve the file metadata filters and reduce to a final filter expression
val fileMetadataFilterOpt = dataFilters.filter(_.references.forall {
case FileSourceMetadataAttribute(_) => true
case _ => false
}).reduceOption(expressions.And)
val fileMetadataFilterOpt = dataFilters.filter { f =>
f.references.nonEmpty && f.references.forall {
case FileSourceMetadataAttribute(_) => true
case _ => false
}
}.reduceOption(expressions.And)

// - create a bound references for filters: put the metadata struct at 0 position for each file
// - retrieve the final metadata struct (could be pruned) from filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ class FileIndexSuite extends SharedSparkSession {
SQLConf.get.setConf(StaticSQLConf.METADATA_CACHE_TTL_SECONDS, previousValue)
}
}

test("SPARK-38182: Fix NoSuchElementException if pushed filter does not contain any " +
"references") {
withTable("t") {
withSQLConf(SQLConf.OPTIMIZER_EXCLUDED_RULES.key ->
"org.apache.spark.sql.catalyst.optimizer.BooleanSimplification") {

sql("CREATE TABLE t (c1 int) USING PARQUET")
assert(sql("SELECT * FROM t WHERE c1 = 1 AND 2 > 1").count() == 0)
}
}
}
}

object DeletionRaceFileSystem {
Expand Down