[ 
https://issues.apache.org/jira/browse/SPARK-62411?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18151997#comment-18151997
 ] 

Ganesha S commented on SPARK-62411:
-----------------------------------

I'm working on the implementation and will raise a PR shortly. 

> Support nested column pruning through UNNEST
> --------------------------------------------
>
>                 Key: SPARK-62411
>                 URL: https://issues.apache.org/jira/browse/SPARK-62411
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 4.3.0
>            Reporter: Ganesha S
>            Priority: Major
>
> The optimizer removes unused nested fields before explode, posexplode, inline 
> and stack, but not before UNNEST (see 
> NestedColumnAliasing.canPruneGenerator). When a query uses a parent field 
> after an UNNEST, the whole parent struct is carried along and copied into 
> every output row.
> Example:
> {code:sql}
> SELECT d.doc_id, d.r.ts, n.id
> FROM (SELECT doc_id, from_json(json, '<schema>') AS r FROM docs) d,
>      LATERAL UNNEST(d.r.children) AS u(n)
> {code}
> Here all of d.r is copied for every element of children, although only d.r.ts 
> is needed. In our benchmark this makes UNNEST 7x to 23x slower than the same 
> query written with explode (1 to 6 levels of nesting). Selecting only the 
> needed fields before the UNNEST brings it within 1.1x to 1.5x of explode.
> Proposal: allow UNNEST in nested column pruning, the same way explode is 
> handled today.



--
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