Eric Yang created SPARK-62321:
---------------------------------

             Summary: Nested column pruning does not apply to aggregate/reduce 
over arrays of structs, so all struct fields are read
                 Key: SPARK-62321
                 URL: https://issues.apache.org/jira/browse/SPARK-62321
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 5.0.0
            Reporter: Eric Yang


A query that folds over an array of structs with aggregate (or its alias 
reduce) reads every field of the struct from Parquet and ORC, even when the 
lambda only uses some of them. Other array higher-order functions such as 
transform, exists and forall read only the fields they use.

 
{code:java}
-- items: array<struct<price: bigint, qty: int, note: string>>
SELECT aggregate(items, 0L, (acc, x) -> acc + x.price * x.qty) FROM t;
-- ReadSchema: struct<items:array<struct<price:bigint,qty:int,note:string>>>
SELECT transform(items, x -> x.price * x.qty) FROM t;
-- ReadSchema: struct<items:array<struct<price:bigint,qty:int>>>
{code}
 

Applies to reduce and to aggregate with a finish function as well. When the 
unused fields are large, the scan reads far more data than needed: in a 
200k-row test file, the unused note field held 257.6MB of the 265.8MB of items 
column data.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to