[ 
https://issues.apache.org/jira/browse/SPARK-62419?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ganesha S updated SPARK-62419:
------------------------------
    Description: 
Follow-up to SPARK-62411.

When a generator reads some fields of a struct and the query above it reads the 
rest, the optimizer keeps the whole struct in the generator's output. For 
example:
{code:sql}
-- doc is STRUCT<ts: STRING, items: ARRAY<INT>>
SELECT doc.ts, item FROM t, LATERAL UNNEST(doc.items) AS u(item)
{code}
Only doc.ts is needed after the UNNEST, but all of doc, including the items 
array, is kept. UNNEST runs without whole-stage codegen, so doc is copied into 
every row it produces.

Nested column pruning already handles this when the struct also has fields the 
query does not read. It skips the case where every field is read somewhere, 
because it then treats the whole struct as needed.

Proposal: in this case, extract the fields before the generator, so that only 
the fields read above it are passed through. This applies to all generators 
that support nested column pruning.

  was:
Follow-up to SPARK-62411.

When a generator reads some fields of a struct and the query above it reads the 
rest, the
optimizer keeps the whole struct in the generator's output. For example:

{code:sql}
-- doc is STRUCT<ts: STRING, items: ARRAY<INT>>
SELECT doc.ts, item FROM t, LATERAL UNNEST(doc.items) AS u(item)
{code}

Only doc.ts is needed after the UNNEST, but all of doc, including the items 
array, is kept.
UNNEST runs without whole-stage codegen, so doc is copied into every row it 
produces.

Nested column pruning already handles this when the struct also has fields the 
query does not
read. It skips the case where every field is read somewhere, because it then 
treats the whole
struct as needed.

Proposal: in this case, extract the fields before the generator, so that only 
the fields read
above it are passed through. This applies to all generators that support nested 
column pruning.


> Prune nested fields of a struct whose fields are split between a generator 
> and the query above it
> -------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-62419
>                 URL: https://issues.apache.org/jira/browse/SPARK-62419
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 4.3.0
>            Reporter: Ganesha S
>            Priority: Major
>
> Follow-up to SPARK-62411.
> When a generator reads some fields of a struct and the query above it reads 
> the rest, the optimizer keeps the whole struct in the generator's output. For 
> example:
> {code:sql}
> -- doc is STRUCT<ts: STRING, items: ARRAY<INT>>
> SELECT doc.ts, item FROM t, LATERAL UNNEST(doc.items) AS u(item)
> {code}
> Only doc.ts is needed after the UNNEST, but all of doc, including the items 
> array, is kept. UNNEST runs without whole-stage codegen, so doc is copied 
> into every row it produces.
> Nested column pruning already handles this when the struct also has fields 
> the query does not read. It skips the case where every field is read 
> somewhere, because it then treats the whole struct as needed.
> Proposal: in this case, extract the fields before the generator, so that only 
> the fields read above it are passed through. This applies to all generators 
> that support nested column pruning.



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