hello-stephen commented on code in PR #71160:
URL: https://github.com/apache/doris/pull/71160#discussion_r4756427605
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java:
##########
@@ -122,6 +122,16 @@ public class InsertUtils {
*/
public static void executeBatchInsertTransaction(ConnectContext ctx,
String dbName, String tableName,
List<Column> columns, List<List<NamedExpression>>
constantExprsList) {
+ // Parsing can defer type-dependent determinism until binding. Recheck
every folded row
+ // before beginning the batch transaction or buffering/sending any row
of this statement.
+ for (List<NamedExpression> row : constantExprsList) {
+ for (Expression expr : row) {
+ if (!expr.isConstant()) {
Review Comment:
[P1] Validate every row's serialization before changing the transaction
For `t(id INT, v STRING)` with the default fast analyzer, execute:
```sql
BEGIN;
INSERT INTO t VALUES (0, 'prior');
INSERT INTO t VALUES (1, 'leaked'), (2, CAST(SHA2('x', 256) AS STRING));
COMMIT;
```
The second INSERT now reaches batch execution because parsing defers the
unresolved cast. FE has no SHA2 evaluator, so its reduced union retains
`Alias(Cast_STRING(Sha2(...)))`; this check accepts it as constant.
`getRowStringValue` buffers ID 1, then throws on the nonliteral SHA2 in ID 2.
Error handling retains the transaction buffer, so COMMIT persists ID 1 despite
that INSERT failing. The prior successful INSERT ensures COMMIT does not take
its zero-row shortcut. On the base, the unresolved cast fails during parsing
before any rows are buffered. Validate every row's serializer requirements, or
serialize into statement-local storage before mutating the transaction, and add
a stored-value regression for this case.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1483,6 +1490,39 @@ public LogicalPlan
visitInsertIntoTVF(InsertIntoTVFContext ctx) {
return withExplain(command, ctx.explainContext);
}
+ // VALUES command selection happens before binding. In particular, a CAST
of
+ // CURRENT_TIMESTAMP(6) has no source type yet. Keep the structural
restrictions of
+ // Expression.isConstant(), but defer type-dependent determinism until
analysis.
+ private static boolean isConstantForTransactionValues(Expression
expression) {
+ if (expression instanceof AggregateFunction
+ || expression instanceof Lambda
+ || expression instanceof MaxValue
+ || expression instanceof OrderExpression
+ || expression instanceof Properties
+ || expression instanceof SubqueryExpr
+ || expression instanceof UnboundVariable
+ || expression instanceof Variable
+ || expression instanceof VariableDesc
+ || expression instanceof WindowExpression
+ || expression instanceof WindowFrame
+ || expression instanceof TableGeneratingFunction) {
+ return false;
+ }
+ if (expression instanceof LeafExpression) {
+ return expression instanceof Literal;
+ }
+ try {
+ if (!expression.isDeterministic()) {
+ return false;
+ }
+ } catch (UnboundException e) {
Review Comment:
[P1] Evaluate deferred deterministic casts before stripping them
For `t(id INT, v STRING)`, with fast analysis enabled and
`enable_strict_cast=true`, this newly admitted statement silently stores the
wrong value:
```sql
BEGIN;
INSERT INTO t VALUES
(1, CAST(TRY_CAST(CONCAT('[[[]]]') AS ARRAY<INT>) AS STRING));
COMMIT;
```
The deferred TRY_CAST source binds, and CONCAT folds, but
`FoldConstantRuleOnFE.visitCast` deliberately leaves string-to-complex casts
unevaluated. The reduced tree is:
```text
OneRowRelation
Alias(Cast_STRING(TryCast_ARRAY<INT>(StringLiteral("[[[]]]"))))
```
Every node passes the new constantness check. `getRowStringValue` then
strips both casts (TryCast extends Cast) and sends `[[[]]]` to the STRING
column instead of NULL. The existing `function_p0/cast/test_try_cast`
regression confirms that the inner TRY_CAST of this input returns NULL under
strict casts. The base rejects the unresolved inner cast before batching.
Evaluate or reject residual semantic conversions before serialization; checking
that cast wrappers terminate in a literal still accepts this wrong value.
--
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]