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 @@ -238,6 +238,14 @@ private[parquet] object ParquetFilters {
case sources.Not(pred) =>
createFilter(schema, pred).map(FilterApi.not)

case sources.In(name, values) if canMakeFilterOn(name) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always push-down? Should we also consider the number of elements in values? What is the performance impact when the number of values is around 10 or more?

val conds = values.flatMap(v => makeEq.lift(nameToType(name)).map(_(name, v)))
var filter = conds(0)
conds.drop(1).foreach { v =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can eliminate the var by using reduceLeft

filter = FilterApi.or(filter, v)
}
Some(filter)

case _ => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ package org.apache.spark.sql.execution.datasources.parquet

import java.nio.charset.StandardCharsets

import org.apache.parquet.filter2.predicate.{FilterPredicate, Operators}
import org.apache.parquet.filter2.predicate.{FilterApi, FilterPredicate, Operators}
import org.apache.parquet.filter2.predicate.FilterApi._
import org.apache.parquet.filter2.predicate.Operators.{Column => _, _}

import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.expressions._
Expand Down Expand Up @@ -602,6 +601,40 @@ class ParquetFilterSuite extends QueryTest with ParquetTest with SharedSQLContex
}
}
}

test(" Convert IN predicate to Parquet filter predicate") {
val schema = StructType(Seq(
StructField("a", IntegerType, nullable = false)
))

assertResult(Some(
FilterApi.eq(intColumn("a"), 10: Integer))
) {
ParquetFilters.createFilter(
schema,
sources.In("a", Array(10)))
}

assertResult(Some(or(
FilterApi.eq(intColumn("a"), 10: Integer),
FilterApi.eq(intColumn("a"), 20: Integer)))
) {
ParquetFilters.createFilter(
schema,
sources.In("a", Array(10, 20)))
}

assertResult(Some(or(or(
FilterApi.eq(intColumn("a"), 10: Integer),
FilterApi.eq(intColumn("a"), 20: Integer)),
FilterApi.eq(intColumn("a"), 30: Integer)))
) {
ParquetFilters.createFilter(
schema,
sources.In("a", Array(10, 20, 30)))
}
}

}

class NumRowGroupsAcc extends AccumulatorV2[Integer, Integer] {
Expand Down