wangyum commented on a change in pull request #31993:
URL: https://github.com/apache/spark/pull/31993#discussion_r613652117
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SchemaPruning.scala
##########
@@ -32,11 +33,10 @@ object SchemaPruning {
// in the resulting schema may differ from their ordering in the logical
relation's
// original schema
val mergedSchema = requestedRootFields
- .map { case root: RootField => StructType(Array(root.field)) }
+ .map { root: RootField => StructType(Array(root.field)) }
.reduceLeft(_ merge _)
- val dataSchemaFieldNames = dataSchema.fieldNames.toSet
val mergedDataSchema =
- StructType(mergedSchema.filter(f =>
dataSchemaFieldNames.contains(f.name)))
+ StructType(dataSchema.map(s =>
mergedSchema.find(_.name.equals(s.name)).getOrElse(s)))
Review comment:
```scala
spark.sql(
"""
|CREATE TABLE t1 (
| _col0 INT,
| _col1 STRING,
| _col2 STRUCT<c1: STRING, c2: STRING, c3: STRING, c4: BIGINT>)
|USING ORC
|""".stripMargin)
spark.sql("SELECT _col0, _col2.c1 FROM t1").show
```
The origin schema is:
```
`_col0` INT,`_col1` STRING,`_col2` STRUCT<`c1`: STRING, `c2`: STRING, `c3`:
STRING, `c4`: BIGINT>
```
Before this PR, the `pruneDataSchema` returns:
```
`_col0` INT,`_col2` STRUCT<`c1`: STRING>
```
After this PR, the `pruneDataSchema` returns:
```
`_col0` INT,`_col1` STRING,`_col2` STRUCT<`c1`: STRING>
```
It only prune nested schemas.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]