englefly opened a new pull request, #67718:
URL: https://github.com/apache/doris/pull/67718

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Problem Summary:
   
   Nested column pruning rewrites a struct-field access over `TRY_CAST` into a 
plain `CAST` and narrows both the read and the conversion to the accessed 
field, dropping the whole-value semantics of TRY_CAST.
   
   Reproduction (single FE/BE, `enable_strict_cast=true`):
   
   ```sql
   CREATE TABLE t (id INT, s STRUCT<a:STRING,b:STRING> NULL)
   DISTRIBUTED BY HASH(id) BUCKETS 1
   PROPERTIES ("replication_num"="1");
   INSERT INTO t VALUES
     (1,named_struct('a','bad','b','2')),
     (2,named_struct('a','10','b','bad')),(3,NULL);
   
   -- with nested column pruning enabled (default)
   SELECT id, TRY_CAST(s AS STRUCT<a:INT,b:INT>)['a'] AS a_i FROM t;
   ```
   
   - id=2: `b='bad'` makes the whole-struct TRY_CAST fail and should yield 
NULL, but pruning drops field `b`, the conversion "succeeds" on `a='10'`, and 
the query returns 10.
   - id=1: the rebuilt plain CAST (instead of TRY_CAST) throws 
`[INVALID_ARGUMENT] parse number fail, string: 'bad'` under 
`enable_strict_cast=true` instead of returning NULL.
   - Root cause: `AccessPathExpressionCollector.visitCast` handles `TryCast` (a 
`Cast` subclass) like a plain cast and translates the narrowed nested access 
path through it, so `SlotTypeReplacer.rewriteCast` later rebuilds the 
expression as `new Cast(...)` with a pruned target type.
   
   Fix: do not translate a narrowed nested access path through a `TRY_CAST`; 
the collector then falls back to reading the whole child value, so the struct 
keeps all fields and the expression keeps its TRY_CAST identity and full target 
type. Field-by-field pruning of plain `CAST` over nested types is unchanged.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test:
       - [x] Unit Test: 
`PruneNestedColumnTest#testTryCastNotPrunedThroughFieldAccess` (whole class: 62 
tests pass)
       - [x] Manual test (detailed steps): reproduced the SQL above end-to-end 
on a local FE+BE cluster built from this change. With 
`enable_prune_nested_column` on and off all three rows return NULL (no 10, no 
exception under `enable_strict_cast=true`); `EXPLAIN VERBOSE` keeps 
`element_at(TRY_CAST(s AS struct<a:int,b:int>), 'a')` with `all access paths: 
[s]`, while plain `CAST` over the same struct is still pruned to 
`struct<a:int>` with `[s.a]`.
   
   - Behavior changed:
       - [x] Yes: enabling/disabling nested column pruning no longer changes 
TRY_CAST results or error semantics.
   
   - Does this need documentation?
       - [x] No.
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to