github-actions[bot] commented on code in PR #65319:
URL: https://github.com/apache/doris/pull/65319#discussion_r3535508363
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/StringLikeLiteral.java:
##########
@@ -312,6 +311,9 @@ protected DateTimeV2Literal castToDateTime(DataType
targetType, boolean strictCa
if (tz != null && tz.equalsIgnoreCase("CST")) {
tz = "+08:00";
}
+ if (!isDatetime) {
+ return getDateLiteralDateTime(year, month, date, hour, minute,
second, targetType);
Review Comment:
The date-only path returns here before the timezone suffix is validated.
`getDateLiteralDateTime(...)` only checks hour/minute/second and discards `tz`,
so inputs like `2024-05-01T00:00XYZ` or `2024-05-01T00:00+14:30` now fold to a
DATE/DATEV2 literal. BE cast execution still rejects those cases; the existing
cast tests expect null for both invalid timezone names and `+14:30`. Please
keep the timezone validation on this path before truncating to the date, for
example by factoring the validation from `getDateTimeLiteral(...)` or passing
`tz` into the date-only helper.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java:
##########
@@ -302,9 +302,10 @@ public int getMicroSecond() {
@Override
protected Expression uncheckedCastTo(DataType targetType) throws
AnalysisException {
+ long microsecondValue = ((Double) getValue()).longValue();
Review Comment:
This applies the signed full microsecond value before every target cast, but
BE only uses the microsecond field for TIMEV2->DATETIMEV2. For DATE, DATEV2,
and DATETIME(v1), `cast_to_date.h` adds signed hour/minute/second and ignores
the fractional part. That means a fold such as `cast(cast('-00:00:00.999999' as
time(6)) as date)` can move to the previous day in FE, while BE keeps the
current date. Please keep the full microsecond path for DATETIMEV2 and mirror
BE's hour/minute/second-only behavior for the other targets.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java:
##########
@@ -62,7 +62,7 @@ public TimeV2Literal(double value) throws AnalysisException {
+ (double) MIN_VALUE.getValue() + ", " + (double)
MAX_VALUE.getValue() + "]");
}
this.negative = value < 0;
- long v = (long) Math.abs(value);
+ long v = (long) Math.abs(Math.round(value));
Review Comment:
`sec_to_time(DoubleLiteral)` passes `sec * 1000000` to this constructor, but
BE does not round that value: `TimeValue::from_double_with_limit` truncates the
double-derived microseconds. With `Math.round`, `sec_to_time(cast(0.0000015 as
double))` folds to `00:00:00.000002` in FE, while BE keeps `00:00:00.000001`.
Please preserve truncation for the `sec_to_time(double)` path, or otherwise
split the rounding behavior so this constructor still matches BE execution.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java:
##########
@@ -107,6 +110,20 @@ public FunctionSignature
computeSignature(FunctionSignature signature) {
return signature.withReturnType(returnType);
}
+ private Literal getConstantFormatLiteral() {
+ Expression format = getArgument(1);
+ if (format instanceof Literal) {
+ return (Literal) format;
+ }
+ if (format.isConstant()) {
+ Expression evaluated = ExpressionEvaluator.INSTANCE.eval(format);
Review Comment:
This still does not handle nested constant format expressions.
`ExpressionEvaluator.eval(format)` is shallow here, so a constant format like
`concat('%Y-', cast('%j' as string))` still contains a `Cast` child during
signature inference and evaluates back to the original expression instead of a
`StringLikeLiteral`. For `str_to_date(col, concat('%Y-', cast('%j' as
string)))`, the first argument is not constant, so the root call cannot later
fold to a literal and callers can still see DATETIMEV2 even though the format
has no time fields. Please recursively fold/normalize the format before
deriving the signature, and add a nonconstant-input test for this case.
--
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]