-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25306][SQL] Avoid skewed filter trees to speed up createFilter in ORC
#22313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
ac06b0c
7720134
4acbaf8
5c46693
4a372a3
3cd4443
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ import java.sql.{Date, Timestamp} | |
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.orc.storage.ql.io.sarg.{PredicateLeaf, SearchArgument} | ||
| import org.scalatest.concurrent.TimeLimits | ||
| import org.scalatest.time.SpanSugar._ | ||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.spark.sql.{Column, DataFrame} | ||
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
|
|
@@ -39,7 +42,7 @@ import org.apache.spark.sql.types._ | |
| * - OrcFilterSuite uses 'org.apache.orc.storage.ql.io.sarg' package. | ||
| * - HiveOrcFilterSuite uses 'org.apache.hadoop.hive.ql.io.sarg' package. | ||
| */ | ||
| class OrcFilterSuite extends OrcTest with SharedSQLContext { | ||
| class OrcFilterSuite extends OrcTest with SharedSQLContext with TimeLimits { | ||
|
|
||
| private def checkFilterPredicate( | ||
| df: DataFrame, | ||
|
|
@@ -383,4 +386,13 @@ class OrcFilterSuite extends OrcTest with SharedSQLContext { | |
| )).get.toString | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-25306 createFilter should not hang") { | ||
| import org.apache.spark.sql.sources._ | ||
| val schema = new StructType(Array(StructField("a", IntegerType, nullable = true))) | ||
| val filters = (1 to 2000).map(LessThan("a", _)).toArray[Filter] | ||
| failAfter(2 seconds) { | ||
| OrcFilters.createFilter(schema, filters) | ||
|
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does parquet has the same problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In parquet, this is done as
can we follow it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first question, I don't think Parquet has the same issue because Parquet uses
canMakeFilterOnwhile ORC is trying to build a full result (with a fresh builder) to check if it's okay or not.For the second question,
flatMap) to computeconvertibleFilters, but we can change it withfilters.filter. I'll update like thatreduceOption(FilterApi.and)was the original ORC code which generated a skewed tree having exponential time complexity. We need to usebuildTree.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, Parquet has another issue here due to
.reduceOption(FilterApi.and). When I make a benchmark, Parquet seems to be unable to handle 1000 filters, @cloud-fan .