github-actions[bot] commented on code in PR #67718:
URL: https://github.com/apache/doris/pull/67718#discussion_r4043272241
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java:
##########
@@ -344,6 +345,21 @@ public Void visitCast(Cast cast, CollectorContext context)
{
);
}
+ @Override
+ public Void visitTryCast(TryCast tryCast, CollectorContext context) {
+ // TRY_CAST semantics cover the WHOLE value: for a composite type any
element
+ // conversion failure makes the entire cast NULL. Narrowing the
read/type down to
+ // only the fields an outer expression accesses would drop the
conversion attempts
+ // of the other fields and silently change the result (e.g.
element_at(try_cast(s as
+ // struct<a:int,b:int>), 'a') must still yield NULL when only field b
is unparsable,
+ // even though field a alone converts fine). Plain Cast over nested
types is pruned
+ // field-by-field on purpose, a TryCast never is: read the whole child
value and keep
+ // the cast identity and target type intact.
+ return tryCast.child(0).accept(this,
+ new CollectorContext(context.statementContext,
context.bottomFilter)
+ );
Review Comment:
Preserve `TryCast` when a derived child is rebuilt. For example:
```text
Project element_at(
TryCast(element_at(wrapper, 'inner') AS struct<good:int,bad:int>),
'good')
Scan wrapper struct<inner:struct<good:string,bad:string>,unused:int>
```
The fresh context here records `[wrapper, inner]`, so pruning can remove
`wrapper.unused` while retaining the complete `inner` value. That changes the
wrapper slot and rebuilds the inner `ElementAt`; `SlotTypeReplacer.rewriteCast`
then sees a changed child and unconditionally returns `new Cast(...)`, erasing
`TryCast`. With strict casting and `inner.bad = 'bad'`, the rewritten
expression raises instead of returning NULL for the whole try-cast row. Please
preserve the dynamic cast kind when rebuilding (for example through
`withChildren`/`withTargetType` or explicit `TryCast` handling), and add a
derived-child regression that asserts the physical expression and result
semantics.
--
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]