mrhhsg commented on PR #68579:
URL: https://github.com/apache/doris/pull/68579#issuecomment-5914013662

   @924060929 Thanks, reworked in 4a850b78c19 along these lines.
   
   **Lifecycle method instead of the interface.** `FoldLiteralArguments` and 
the `instanceof` dispatch in `TypeCoercionUtils` are gone. `ExpressionTrait` 
now has `prepareBeforeTypeCoercion()` next to the legality hooks; it returns 
the prepared expression and does nothing by default. `ExpressionAnalyzer.visit` 
and `TypeCoercionUtils.processBoundFunction` call it first, so the order is the 
one you described:
   
   ```
   bind arguments and function
   -> prepareBeforeTypeCoercion
   -> checkLegalityBeforeTypeCoercion
   -> compute signature / expected input types
   -> insert casts
   -> rewrite -> checkLegalityAfterRewrite
   ```
   
   A prepared function is a rebuilt object, so `expectedInputTypes()` computes 
the signature from the folded argument. The shared helper is 
`ExpressionUtils.foldConstantArgument` (returns the literal a constant argument 
evaluates to on FE, or the argument unchanged).
   
   **Only signature-dependent arguments are prepared.**
   - now / utc_timestamp (`DateTimeWithPrecision`) and utc_time: the precision.
   - date_trunc: only when neither argument is a date, where the literal time 
unit identifies the argument roles. Beside a date argument the other one is the 
unit and the signature does not need its value, so nothing is folded there 
anymore.
   
   **Value checks placed per function, no early folding.**
   - Aggregates are not removed by constant folding, so topn / topn_array / 
topn_weighted, sequence_match / sequence_count and ai_agg validate the literal 
in `checkLegalityAfterRewrite` and only require a constant before type coercion 
(a literal sequence pattern / ai_agg resource name is still validated before 
type coercion, as on master).
   - Scalar functions that null propagation or constant folding can remove 
before a rewrite-time check sees the argument (sha2, split_by_regexp, tokenize, 
array_apply, date_trunc beside a date, the AI scalar functions): 
`checkLegalityBeforeTypeCoercion` validates the value FE can evaluate, obtained 
with the same helper, but does not replace the argument, so the tree still 
reaches the rewrite as written. For example `tokenize(null, concat('par', 
'ser'))` and `sha2(null, 200 + 100)` are rejected during analysis like the 
equivalent literals. I read "an earlier validation point after argument 
preparation/folding" as this; if you meant a different point, say a hook inside 
the fold-constant rule between folding the arguments and folding the parent, I 
can move the checks there.
   - regexp_replace(_one), width_bucket, rand / random, uniform and 
orthogonal_bitmap_expr_calculate(_count) only require `isConstant()`.
   
   One consequence: the AI functions still require a literal resource name 
after the rewrite, so they no longer accept a constant expression under 
`debug_skip_fold_constant` (the early folding used to cover that). The PR 
description is updated.
   
   Tests: `ConstantFunctionArgumentTest` asserts which arguments the analysis 
folds (only the prepared ones), that the others are folded by the rewrite, the 
before-type-coercion checks including the null-propagation cases, and the 
after-rewrite checks of the aggregates (also through `_state`). The regression 
suite results are unchanged apart from the added cases.
   


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