This is an automated email from the ASF dual-hosted git repository.

zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new bf53b2d1497 [Fix](function) fix wrong time to datetime cast in FE 
constant folding (#52896)
bf53b2d1497 is described below

commit bf53b2d149791ac7c3064a91f45ba4712d41f01f
Author: zclllyybb <[email protected]>
AuthorDate: Fri Jul 11 23:35:32 2025 +0800

    [Fix](function) fix wrong time to datetime cast in FE constant folding 
(#52896)
    
    when we cast time to datetime, before we wrongly get `now() + time`
    now fix it to get `date(now()) + time`
---
 .../doris/nereids/trees/expressions/literal/TimeV2Literal.java      | 6 +++---
 .../suites/correctness/test_cast_time_to_datetime.groovy            | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java
index 6420e22779e..becbb415b04 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeV2Literal.java
@@ -221,9 +221,9 @@ public class TimeV2Literal extends Literal {
 
     @Override
     protected Expression uncheckedCastTo(DataType targetType) throws 
AnalysisException {
-        DateTimeV2Literal time = (DateTimeV2Literal) 
DateTimeV2Literal.fromJavaDateType(
-                
LocalDateTime.now(DateUtils.getTimeZone()).plusHours(getHour()).plusMinutes(getMinute())
-                        .plusSeconds(getSecond()).plusNanos(getMicroSecond() * 
1000),
+        DateTimeV2Literal time = (DateTimeV2Literal) 
DateTimeV2Literal.fromJavaDateType(LocalDateTime
+                
.now(DateUtils.getTimeZone()).withHour(0).withMinute(0).withSecond(0).withNano(0).plusHours(getHour())
+                
.plusMinutes(getMinute()).plusSeconds(getSecond()).plusNanos(getMicroSecond() * 
1000),
                 ((TimeV2Type) dataType).getScale());
         if (targetType.isDateType()) {
             return new DateLiteral(time.getYear(), time.getMonth(), 
time.getDay());
diff --git 
a/regression-test/suites/correctness/test_cast_time_to_datetime.groovy 
b/regression-test/suites/correctness/test_cast_time_to_datetime.groovy
index 56e8c0fef2c..35b45f25c9b 100644
--- a/regression-test/suites/correctness/test_cast_time_to_datetime.groovy
+++ b/regression-test/suites/correctness/test_cast_time_to_datetime.groovy
@@ -16,6 +16,7 @@
 // under the License.
 
 suite("test_cast_time_to_datetime") {
+    waitUntilSafeExecutionTime("NOT_CROSS_DAY_BOUNDARY", 2)
     def result1 = sql """ select datediff(now(), from_unixtime(cast(1742194502 
as bigint),'yyyy-MM-dd HH:mm:ss')); """
     def result2 = sql """ select datediff(current_time(), 
from_unixtime(cast(1742194502 as bigint),'yyyy-MM-dd HH:mm:ss')); """
     assertEquals(result1[0][0], result2[0][0], "The results of the two SQL 
queries should be the same.")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to