-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25363][SQL] Fix schema pruning in where clause by ignoring unnecessary root fields #22357
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 1 commit
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| package org.apache.spark.sql.execution.datasources.parquet | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{And, Attribute, AttributeReference, Expression, NamedExpression} | ||
| import org.apache.spark.sql.catalyst.expressions.{And, Attribute, AttributeReference, Expression, IsNotNull, IsNull, NamedExpression} | ||
| import org.apache.spark.sql.catalyst.planning.PhysicalOperation | ||
| import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
|
|
@@ -196,6 +196,7 @@ private[sql] object ParquetSchemaPruning extends Rule[LogicalPlan] { | |
| */ | ||
| private def getRootFields(expr: Expression): Seq[RootField] = { | ||
| expr match { | ||
| case IsNotNull(_: Attribute) | IsNull(_: Attribute) => Seq.empty | ||
|
||
| case att: Attribute => | ||
| RootField(StructField(att.name, att.dataType, att.nullable), derivedFromAtt = true) :: Nil | ||
| case SelectedField(field) => RootField(field, derivedFromAtt = false) :: Nil | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about case IsNotNull(_: Attribute) | IsNull(_: Attribute) =>
expr.children.flatMap(getRootFields).map(_.copy(contentAccessed = false))
case _ =>
expr.children.flatMap(getRootFields) |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,30 @@ class ParquetSchemaPruningSuite | |
| Row(null) :: Row(null) :: Nil) | ||
| } | ||
|
|
||
| testSchemaPruning("select a single complex field and in where clause") { | ||
| val query = sql("select name.first from contacts where name.first = 'Jane'") | ||
| checkScan(query, "struct<name:struct<first:string>>") | ||
| checkAnswer(query, Row("Jane") :: Nil) | ||
|
||
| } | ||
|
|
||
| testSchemaPruning("select a single complex field array and in clause") { | ||
| val query = sql("select friends.middle from contacts where friends.first[0] = 'Susan'") | ||
| checkScan(query, | ||
| "struct<friends:array<struct<first:string,middle:string>>>") | ||
| checkAnswer(query.orderBy("id"), | ||
| Row(Array("Z.")) :: Nil) | ||
| } | ||
|
|
||
| testSchemaPruning("select a single complex field from a map entry and in clause") { | ||
| val query = | ||
| sql("select relatives[\"brother\"].middle from contacts " + | ||
| "where relatives[\"brother\"].first = 'John'") | ||
| checkScan(query, | ||
| "struct<relatives:map<string,struct<first:string,middle:string>>>") | ||
| checkAnswer(query.orderBy("id"), | ||
| Row("Y.") :: Nil) | ||
| } | ||
|
|
||
| private def testSchemaPruning(testName: String)(testThunk: => Unit) { | ||
| withSQLConf(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "true") { | ||
| test(s"Spark vectorized reader - without partition data column - $testName") { | ||
|
|
||
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.
line too long.
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.
which can be wildcard when there are more than 6 entities per https://github.com/databricks/scala-style-guide#imports