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 3bf3bc2ec69 [fix](datetime) throw exception for date_floor/ceil
instead of return NULL (#60633)
3bf3bc2ec69 is described below
commit 3bf3bc2ec69f33af564729f938292e64e91ebf8c
Author: zclllyybb <[email protected]>
AuthorDate: Tue Feb 10 15:09:22 2026 +0800
[fix](datetime) throw exception for date_floor/ceil instead of return NULL
(#60633)
before:
```
select date_floor('2007-01-02', interval 0 month);
+--------------------------------------------+
| date_floor('2007-01-02', interval 0 month) |
+--------------------------------------------+
| NULL |
+--------------------------------------------+
```
now:
```sql
select date_floor('2007-01-02', interval 0 month);
Operation month_floor of 2007-01-02 00:00:00, 0, 0001-01-01 00:00:00 out of
range
```
---
.../functions/executable/TimeRoundSeries.java | 4 ++-
.../datetime_functions/test_date_floor_ceil.groovy | 38 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java
index bd1e8f0b28e..c32f733bedb 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java
@@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.nereids.annotation.Developing;
+import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
@@ -53,7 +54,8 @@ public class TimeRoundSeries {
private static LocalDateTime getDateCeilOrFloor(DATE tag, LocalDateTime
date, int period, LocalDateTime origin,
boolean getCeil) {
if (period < 1) {
- return null;
+ throw new AnalysisException("Operation " + tag.name().toLowerCase()
+ + (getCeil ? "_ceil" : "_floor") + " of " + period + " out
of range");
}
DateTimeV2Literal dt = (DateTimeV2Literal)
DateTimeV2Literal.fromJavaDateType(date);
diff --git
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy
index 83b3d1d7aeb..99b9a7d5362 100644
---
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy
+++
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy
@@ -309,4 +309,42 @@ suite("test_date_floor_ceil") {
testFoldConst("SELECT YEAR_CEIL('2001-01-01 0:00:00.000001', 10);");
testFoldConst("SELECT YEAR_CEIL('2001-01-01 0:00:00.000001',
'1970-01-01');");
testFoldConst("SELECT YEAR_CEIL('2001-01-01 0:00:00.000001', 10,
'1970-01-01');");
+
+ // period < 1 should throw exception (FE constant folding path)
+ test {
+ sql "select date_floor('2007-01-02', interval 0 month);"
+ exception "out of range"
+ }
+ test {
+ sql "select date_ceil('2007-01-02', interval 0 month);"
+ exception "out of range"
+ }
+ test {
+ sql "select month_floor('2023-07-14 15:30:45', 0);"
+ exception "out of range"
+ }
+ test {
+ sql "select date_floor('2023-07-14 15:30:45', interval -1 month);"
+ exception "out of range"
+ }
+
+ // period < 1 should throw exception (BE path, the original bug scenario)
+ sql """set debug_skip_fold_constant = true"""
+ test {
+ sql "select date_floor('2007-01-02', interval 0 month);"
+ exception "out of range"
+ }
+ test {
+ sql "select date_ceil('2007-01-02', interval 0 month);"
+ exception "out of range"
+ }
+ test {
+ sql "select month_floor('2023-07-14 15:30:45', 0);"
+ exception "out of range"
+ }
+ test {
+ sql "select date_floor('2023-07-14 15:30:45', interval -1 month);"
+ exception "out of range"
+ }
+ sql """set debug_skip_fold_constant = false"""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]