Skip to content

Commit 846d9b2

Browse files
authored
[fix](be) Preserve NULL propagation in date floor functions (#67951)
`month_floor` and `week_floor` validated a constant non-positive period before processing the merged NULL map. As a result, rows with a NULL date and period `0` could error instead of returning NULL. Return an all-NULL result block before the constant-period fast path while preserving validation for non-NULL rows. ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
1 parent 27bd90e commit 846d9b2

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎be/src/exprs/function/function_datetime_floor_ceil.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ class FunctionDateTimeFloorCeil : public FunctionDateTimeFloorCeilBase {
175175
}
176176
}
177177

178+
// A constant period is validated before the vectorized loop below. Return early when every
179+
// row is already NULL so NULL propagation takes precedence over period validation.
180+
if (input_rows_count > 0 && std::all_of(result_null_map.begin(), result_null_map.end(),
181+
[](uint8_t is_null) { return is_null != 0; })) {
182+
auto col_to = ColumnVector<PType>::create();
183+
col_to->resize(input_rows_count);
184+
block.replace_by_position(
185+
result,
186+
ColumnNullable::create(std::move(col_to), std::move(result_null_map_column)));
187+
return Status::OK();
188+
}
189+
178190
// Extract nested columns from const(nullable) wrappers
179191
argument_columns[0] = col_const[0] ? static_cast<const ColumnConst&>(
180192
*block.get_by_position(arguments[0]).column)

‎be/test/exprs/function/function_time_test.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,21 @@ TEST(VTimestampFunctionsTest, date_test) {
453453
static_cast<void>(check_function<DataTypeDateV2, true>(func_name, input_types, data_set));
454454
}
455455

456+
TEST(VTimestampFunctionsTest, date_floor_null_period_validation_test) {
457+
const InputTypeSet input_types = {Nullable {PrimitiveType::TYPE_DATEV2},
458+
Consted {PrimitiveType::TYPE_INT}};
459+
460+
// NULL input rows must be returned as NULL before validating a constant period.
461+
const DataSet null_date_data_set = {{{Null(), int32_t {0}}, Null()}};
462+
static_cast<void>(
463+
check_function<DataTypeDateV2, true>("month_floor", input_types, null_date_data_set));
464+
465+
// A non-NULL input row must still reject an invalid constant period.
466+
const DataSet non_null_date_data_set = {{{std::string("2023-01-01"), int32_t {0}}, Null()}};
467+
static_cast<void>(check_function<DataTypeDateV2, true>("month_floor", input_types,
468+
non_null_date_data_set, -1, -1, true));
469+
}
470+
456471
TEST(VTimestampFunctionsTest, week_test) {
457472
std::string func_name = "week";
458473

0 commit comments

Comments
 (0)