github-actions[bot] commented on code in PR #62583:
URL: https://github.com/apache/doris/pull/62583#discussion_r3099492858


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -3482,13 +3482,146 @@ public Expression 
visitFunctionCallExpression(DorisParser.FunctionCallExpression
             boolean isDistinct = ctx.DISTINCT() != null;
             List<Expression> params = Lists.newArrayList();
             params.addAll(visit(ctx.funcExpression(), Expression.class));
+            Optional<Expression> rewritten = rewriteCompatibilityFunction(
+                    ctx, dbName, functionName, isDistinct, params, 
ctx.windowSpec(), ctx.identifier());
+            if (rewritten.isPresent()) {
+                return rewritten.get();
+            }
             List<OrderKey> orderKeys = visit(ctx.sortItem(), OrderKey.class);
             
params.addAll(orderKeys.stream().map(OrderExpression::new).collect(Collectors.toList()));
             return processUnboundFunction(ctx, dbName, functionName, 
isDistinct, params,
                     ctx.windowSpec(), ctx.identifier());
         });
     }
 
+    private Optional<Expression> 
rewriteCompatibilityFunction(ParserRuleContext ctx, String dbName,
+            String functionName, boolean isDistinct, List<Expression> params,
+            WindowSpecContext windowContext, IdentifierContext hintContext) {
+        if (dbName != null || isDistinct || windowContext != null || 
hintContext != null) {
+            return Optional.empty();
+        }
+
+        String normalizedName = functionName.toLowerCase(Locale.ROOT);
+        switch (normalizedName) {
+            case "date_part":
+                return Optional.of(rewriteDatePart(params));
+            case "dateadd":
+                return Optional.of(rewriteDateAdd(params));

Review Comment:
   `to_timestamp` is being lowered to `str_to_date`, but those functions do not 
have the same type contract. `StrToDate.computeSignature()` returns `DATEV2` 
when the format literal has no time part, so `to_timestamp('2026-04-16', 
'%Y-%m-%d')` will analyze as a DATE instead of a timestamp/datetime value. A 
compatibility alias needs to preserve the original return-type semantics, not 
just map to a roughly similar function name.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -3482,13 +3482,146 @@ public Expression 
visitFunctionCallExpression(DorisParser.FunctionCallExpression
             boolean isDistinct = ctx.DISTINCT() != null;
             List<Expression> params = Lists.newArrayList();
             params.addAll(visit(ctx.funcExpression(), Expression.class));
+            Optional<Expression> rewritten = rewriteCompatibilityFunction(
+                    ctx, dbName, functionName, isDistinct, params, 
ctx.windowSpec(), ctx.identifier());
+            if (rewritten.isPresent()) {
+                return rewritten.get();
+            }
             List<OrderKey> orderKeys = visit(ctx.sortItem(), OrderKey.class);
             
params.addAll(orderKeys.stream().map(OrderExpression::new).collect(Collectors.toList()));
             return processUnboundFunction(ctx, dbName, functionName, 
isDistinct, params,
                     ctx.windowSpec(), ctx.identifier());
         });
     }
 
+    private Optional<Expression> 
rewriteCompatibilityFunction(ParserRuleContext ctx, String dbName,
+            String functionName, boolean isDistinct, List<Expression> params,
+            WindowSpecContext windowContext, IdentifierContext hintContext) {
+        if (dbName != null || isDistinct || windowContext != null || 
hintContext != null) {
+            return Optional.empty();
+        }
+
+        String normalizedName = functionName.toLowerCase(Locale.ROOT);

Review Comment:
   These parser-level rewrites run before 
`FunctionRegistry.findFunctionBuilder()`, so names that were already supported 
aliases no longer participate in normal builtin-vs-UDF resolution. Doris 
explicitly supports `prefer_udf_over_builtin=true`, but after this change a 
user-defined `split` or `char_length` can never win because the parser rewrites 
the call to a different builtin name first. For existing aliases this is a 
behavior regression, not just additive compatibility.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java:
##########
@@ -373,6 +378,11 @@ public Expression visitCurrentCatalog(CurrentCatalog 
currentCatalog, ExpressionR

Review Comment:
   `current_version()` and `version_long()` only get semantics here through FE 
constant folding, but unlike `version()` there is no BE/runtime implementation 
for these names. `FoldConstantRule.evaluateOrThrow()` returns the expression 
unchanged when `debug_skip_fold_constant=true`, and 
`ExpressionTranslator.visitScalarFunction()` will then emit a plain builtin 
`FunctionCallExpr` for BE execution. Since BE only registers `version()` 
(`be/src/exprs/function/function_utility.cpp`), the new functions can fail on 
that existing execution path. The new regression test only checks `version()` 
under `debug_skip_fold_constant=true`, so this break is currently uncovered.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -3482,13 +3482,146 @@ public Expression 
visitFunctionCallExpression(DorisParser.FunctionCallExpression
             boolean isDistinct = ctx.DISTINCT() != null;
             List<Expression> params = Lists.newArrayList();
             params.addAll(visit(ctx.funcExpression(), Expression.class));
+            Optional<Expression> rewritten = rewriteCompatibilityFunction(
+                    ctx, dbName, functionName, isDistinct, params, 
ctx.windowSpec(), ctx.identifier());
+            if (rewritten.isPresent()) {
+                return rewritten.get();
+            }
             List<OrderKey> orderKeys = visit(ctx.sortItem(), OrderKey.class);
             
params.addAll(orderKeys.stream().map(OrderExpression::new).collect(Collectors.toList()));
             return processUnboundFunction(ctx, dbName, functionName, 
isDistinct, params,
                     ctx.windowSpec(), ctx.identifier());
         });
     }
 
+    private Optional<Expression> 
rewriteCompatibilityFunction(ParserRuleContext ctx, String dbName,
+            String functionName, boolean isDistinct, List<Expression> params,
+            WindowSpecContext windowContext, IdentifierContext hintContext) {
+        if (dbName != null || isDistinct || windowContext != null || 
hintContext != null) {
+            return Optional.empty();
+        }
+
+        String normalizedName = functionName.toLowerCase(Locale.ROOT);
+        switch (normalizedName) {
+            case "date_part":
+                return Optional.of(rewriteDatePart(params));
+            case "dateadd":
+                return Optional.of(rewriteDateAdd(params));
+            case "to_timestamp":
+                return Optional.of(rewriteSimpleAlias(normalizedName, 
"str_to_date", 2, params));
+            case "to_char":
+                return Optional.of(rewriteSimpleAlias(normalizedName, 
"date_format", 2, params));
+            case "strpos":
+                return Optional.of(rewriteStrpos(params));
+            case "regexp_substr":
+                return Optional.of(rewriteRegexpSubstr(params));
+            case "char_length":
+                return Optional.of(rewriteSimpleAlias(normalizedName, 
"character_length", 1, params));
+            case "split":
+                return Optional.of(rewriteSplit(params));
+            default:
+                return Optional.empty();
+        }
+    }
+
+    private Expression rewriteDatePart(List<Expression> params) {
+        if (params.size() != 2) {
+            throw new AnalysisException("date_part requires exactly 2 
arguments");
+        }
+
+        String field = getRequiredStringLiteral(params.get(0), "date_part 
field");
+        Expression source = params.get(1);
+        String normalizedField = field.trim().toLowerCase(Locale.ROOT);
+
+        switch (normalizedField) {
+            case "year":
+            case "month":
+            case "day":
+            case "hour":
+            case "minute":
+            case "second":
+            case "week":
+            case "quarter":
+                return new UnboundFunction(normalizedField, false, 
ImmutableList.of(source));
+            default:
+                throw new AnalysisException("Unsupported date_part field: '" + 
field + "'");
+        }
+    }
+
+    private Expression rewriteDateAdd(List<Expression> params) {
+        if (params.size() != 3) {
+            throw new AnalysisException("dateadd requires exactly 3 
arguments");
+        }
+
+        String unit = getRequiredStringLiteral(params.get(0), "dateadd unit");
+        Expression delta = params.get(1);
+        Expression source = params.get(2);
+        String normalizedUnit = unit.trim().toLowerCase(Locale.ROOT);
+

Review Comment:
   `DATEADD` was already supported in Nereids via `DatetimeFunctionBinder` with 
the existing `DATEADD(unit, amount, ts)` form (`TIMESTAMP_ADD_FUNCTION_NAMES` 
includes `DATEADD`, and `DatetimeFunctionBinderTest#testTimestampAdd` covers 
that path). This parser rewrite now intercepts every `dateadd(...)` call first 
and requires the unit to be a string literal, so previously valid inputs like 
`DATEADD(DAY, 1, ts)` are rejected before the binder can run. Please preserve 
the old binder path or make the rewrite accept both forms instead of narrowing 
the syntax.



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