Uh oh!
There was an error while loading. Please reload this page.
[SPARK-26551][SQL] Fix schema pruning error when selecting one complex field and having is not null predicate on another one - #23474
[SPARK-26551][SQL] Fix schema pruning error when selecting one complex field and having is not null predicate on another one#23474viirya wants to merge 4 commits into
Conversation
…is not null predicate on another one.
viirya
commented
Jan 6, 2019
SparkQA
commented
Jan 6, 2019
Test build #100820 has finished for PR 23474 at commit
|
viirya
commented
Jan 6, 2019
retest this please. |
SparkQA
commented
Jan 6, 2019
Test build #100825 has finished for PR 23474 at commit
|
viirya
commented
Jan 6, 2019
retest this please... |
SparkQA
commented
Jan 6, 2019
Test build #100829 has finished for PR 23474 at commit
|
dongjoon-hyun
commented
Jan 6, 2019
Thank you for pinging me, @viirya ! |
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jan 7, 2019
Test build #100861 has finished for PR 23474 at commit
|
HyukjinKwon
commented
Jan 7, 2019
retest this please |
SparkQA
commented
Jan 7, 2019
Test build #100864 has finished for PR 23474 at commit
|
viirya
commented
Jan 7, 2019
retest this please. |
SparkQA
commented
Jan 7, 2019
Test build #100869 has finished for PR 23474 at commit
|
dbtsai
commented
Jan 7, 2019
When we read Now, the issue is when we read To fix the root cause, and avoid the misunderstanding of the meaning of What do you think? Thanks. |
viirya
commented
Jan 8, 2019
I think It is harder to mark |
dbtsai
commented
Jan 8, 2019
If it's really difficult to mark !rootFields.exists { root =>
root.field.name == opt.field.name && {
// If the merged field type of root and opt field is different from opt field type,// we will keep it.// For example, when root field type is `struct<name:struct<last:string>>`,// and opt field type is `struct<name:struct<middle:string>>`, the merged field type will be// `struct<name:struct<last:string,middle:string>>`. Since the merged one contains more// nested fields than opt field type, we have to keep it.valrootFieldType=StructType(Array(root.field))
valoptFieldType=StructType(Array(opt.field))
valmerged= optFieldType.merge(rootFieldType)
merged.sameType(optFieldType)
}Add @hvanhovell@gatorsmile for more input. Thanks! |
dongjoon-hyun
commented
Jan 8, 2019
+1 for @dbtsai 's refactored code. |
| optRootFields.filter { opt => | ||
| !rootFields.exists(_.field.name == opt.field.name) | ||
| val optFieldType = StructType(Array(opt.field)) |
There was a problem hiding this comment.
Can we move optFieldType right after val rootFieldType = StructType(Array(root.field))? Thanks!
There was a problem hiding this comment.
Do you mean moving it inside the exists call?
There was a problem hiding this comment.
I make it out of exist call so it can be reused, isn't? Moving it to after rootFieldType is for readability?
There was a problem hiding this comment.
It's not very expensive, and we only need to compute it when root.field.name == opt.field.name. As a result, I feel moving it right after val rootFieldType will be more readable.
root.field.name == opt.field.name && {
valrootFieldType=StructType(Array(root.field))
valoptFieldType=StructType(Array(opt.field))
valmerged= optFieldType.merge(rootFieldType)
merged.sameType(optFieldType)
}There was a problem hiding this comment.
Ok. I see. Let me move it. Thanks.
dbtsai
commented
Jan 10, 2019
LGTM. Just one minor comment. Thanks! |
SparkQA
commented
Jan 10, 2019
Test build #101024 has finished for PR 23474 at commit
|
SparkQA
commented
Jan 11, 2019
Test build #101075 has finished for PR 23474 at commit
|
…x field and having is not null predicate on another one
## What changes were proposed in this pull request?
Schema pruning has errors when selecting one complex field and having is not null predicate on another one:
```scala
val query = sql("select * from contacts")
.where("name.middle is not null")
.select(
"id",
"name.first",
"name.middle",
"name.last"
)
.where("last = 'Jones'")
.select(count("id"))
```
```
java.lang.IllegalArgumentException: middle does not exist. Available: last
[info] at org.apache.spark.sql.types.StructType.$anonfun$fieldIndex$1(StructType.scala:303)
[info] at scala.collection.immutable.Map$Map1.getOrElse(Map.scala:119)
[info] at org.apache.spark.sql.types.StructType.fieldIndex(StructType.scala:302)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.$anonfun$getProjection$6(ProjectionOverSchema.scala:58)
[info] at scala.Option.map(Option.scala:163)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.getProjection(ProjectionOverSchema.scala:56)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.unapply(ProjectionOverSchema.scala:32)
[info] at org.apache.spark.sql.execution.datasources.parquet.ParquetSchemaPruning$$anonfun$$nestedInanonfun$buildNewProjection$1$1.applyOrElse(Parque
tSchemaPruning.scala:153)
```
## How was this patch tested?
Added tests.
Closes#23474 from viirya/SPARK-26551.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: DB Tsai <d_tsai@apple.com>
(cherry picked from commit 50ebf3a)
Signed-off-by: DB Tsai <d_tsai@apple.com>dbtsai
commented
Jan 11, 2019
LGTM. Merged into master and 2.4 branch. Thanks! |
…x field and having is not null predicate on another one
## What changes were proposed in this pull request?
Schema pruning has errors when selecting one complex field and having is not null predicate on another one:
```scala
val query = sql("select * from contacts")
.where("name.middle is not null")
.select(
"id",
"name.first",
"name.middle",
"name.last"
)
.where("last = 'Jones'")
.select(count("id"))
```
```
java.lang.IllegalArgumentException: middle does not exist. Available: last
[info] at org.apache.spark.sql.types.StructType.$anonfun$fieldIndex$1(StructType.scala:303)
[info] at scala.collection.immutable.Map$Map1.getOrElse(Map.scala:119)
[info] at org.apache.spark.sql.types.StructType.fieldIndex(StructType.scala:302)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.$anonfun$getProjection$6(ProjectionOverSchema.scala:58)
[info] at scala.Option.map(Option.scala:163)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.getProjection(ProjectionOverSchema.scala:56)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.unapply(ProjectionOverSchema.scala:32)
[info] at org.apache.spark.sql.execution.datasources.parquet.ParquetSchemaPruning$$anonfun$$nestedInanonfun$buildNewProjection$1$1.applyOrElse(Parque
tSchemaPruning.scala:153)
```
## How was this patch tested?
Added tests.
Closesapache#23474 from viirya/SPARK-26551.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: DB Tsai <d_tsai@apple.com>…x field and having is not null predicate on another one
## What changes were proposed in this pull request?
Schema pruning has errors when selecting one complex field and having is not null predicate on another one:
```scala
val query = sql("select * from contacts")
.where("name.middle is not null")
.select(
"id",
"name.first",
"name.middle",
"name.last"
)
.where("last = 'Jones'")
.select(count("id"))
```
```
java.lang.IllegalArgumentException: middle does not exist. Available: last
[info] at org.apache.spark.sql.types.StructType.$anonfun$fieldIndex$1(StructType.scala:303)
[info] at scala.collection.immutable.Map$Map1.getOrElse(Map.scala:119)
[info] at org.apache.spark.sql.types.StructType.fieldIndex(StructType.scala:302)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.$anonfun$getProjection$6(ProjectionOverSchema.scala:58)
[info] at scala.Option.map(Option.scala:163)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.getProjection(ProjectionOverSchema.scala:56)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.unapply(ProjectionOverSchema.scala:32)
[info] at org.apache.spark.sql.execution.datasources.parquet.ParquetSchemaPruning$$anonfun$$nestedInanonfun$buildNewProjection$1$1.applyOrElse(Parque
tSchemaPruning.scala:153)
```
## How was this patch tested?
Added tests.
Closesapache#23474 from viirya/SPARK-26551.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: DB Tsai <d_tsai@apple.com>
(cherry picked from commit 50ebf3a)
Signed-off-by: DB Tsai <d_tsai@apple.com>…x field and having is not null predicate on another one
## What changes were proposed in this pull request?
Schema pruning has errors when selecting one complex field and having is not null predicate on another one:
```scala
val query = sql("select * from contacts")
.where("name.middle is not null")
.select(
"id",
"name.first",
"name.middle",
"name.last"
)
.where("last = 'Jones'")
.select(count("id"))
```
```
java.lang.IllegalArgumentException: middle does not exist. Available: last
[info] at org.apache.spark.sql.types.StructType.$anonfun$fieldIndex$1(StructType.scala:303)
[info] at scala.collection.immutable.Map$Map1.getOrElse(Map.scala:119)
[info] at org.apache.spark.sql.types.StructType.fieldIndex(StructType.scala:302)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.$anonfun$getProjection$6(ProjectionOverSchema.scala:58)
[info] at scala.Option.map(Option.scala:163)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.getProjection(ProjectionOverSchema.scala:56)
[info] at org.apache.spark.sql.execution.ProjectionOverSchema.unapply(ProjectionOverSchema.scala:32)
[info] at org.apache.spark.sql.execution.datasources.parquet.ParquetSchemaPruning$$anonfun$$nestedInanonfun$buildNewProjection$1$1.applyOrElse(Parque
tSchemaPruning.scala:153)
```
## How was this patch tested?
Added tests.
Closesapache#23474 from viirya/SPARK-26551.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: DB Tsai <d_tsai@apple.com>
(cherry picked from commit 50ebf3a)
Signed-off-by: DB Tsai <d_tsai@apple.com>
What changes were proposed in this pull request?
Schema pruning has errors when selecting one complex field and having is not null predicate on another one:
How was this patch tested?
Added tests.