Skip to content

[fix](function) Handle relative day constants and nulls - #68001

Open
Mryange wants to merge 1 commit into
apache:masterfrom
Mryange:fix-relative-day-null-const
Open

Mryange wants to merge 1 commit into
apache:masterfrom
Mryange:fix-relative-day-null-const

Conversation

@Mryange

@Mryange Mryange commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

next_day and previous_day reused a mutated date value when the date argument was constant, producing cumulative cross-row results. Nullable inputs were also unpacked before execution, causing NULL weekday rows to be parsed as empty strings and fail the entire query. The functions now use ColumnView to handle constant and nullable columns directly, compute each row from an independent date value, propagate NULL results, and continue rejecting invalid non-NULL weekdays.

Release note

None

Check List (For Author)

  • Test

    • 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
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@Mryange

Mryange commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for three avoidable hot-path regressions in the new manual NULL/constant handling.

Critical checkpoint conclusions:

  • Goal and correctness: The functional fix is sound under static review. ColumnView covers plain, constant, nullable, and Const(Nullable) inputs; date state is reconstructed per row; NULL rows short-circuit before payload parsing; invalid non-NULL weekdays still return InvalidArgument. FE and BE nullable return types and DateV2/TimestampNs behavior align.
  • Scope/design: The change is focused on the shared relative-day implementation and its BE unit coverage.
  • Concurrency/lifecycle/memory: No new shared mutable state, locking, or special lifecycle is introduced. Result and null-map columns remain size-aligned and column-owned.
  • Configuration/compatibility/persistence/data writes: No configuration, protocol/storage format, persistence, transaction, or rolling-upgrade surface is changed.
  • Parallel paths: Both next_day/previous_day and DateV2/TimestampNs paths were traced; no distinct correctness issue remains.
  • Performance: The accepted inline findings must be addressed: preserve partial-constant fast paths, remove the release assertion from the row loop, and retain the all-NULL constant-result shortcut.
  • Tests: Existing next/previous-day regressions cover multi-row constant-date behavior and error cases; the added BE unit test covers actual NULLs in both positions, and existing TimestampNs coverage exercises nullable input. Per the review-runner contract, this was a static review only; no builds or tests were run. The text-only BE build-hygiene gate passed.
  • User focus: No additional focus was provided.

Review status: complete after three bounded rounds. Every candidate was independently verified and deduplicated; the final normal and risk-focused round returned NO_NEW_VALUABLE_FINDINGS.

return result;
}

bool use_default_implementation_for_nulls() const override { return false; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opting out of the framework NULL implementation also drops its only_null shortcut. next_day(NULL, e) is not foldable when e is a slot, so it reaches BE; this path previously returned a constant NULL column immediately, but now reserves/fills a row-sized DateV2 column and null map and executes the scalar loop for every row. Please retain an early only_null result before these allocations (and before constant-weekday validation, to preserve NULL precedence) while keeping the new per-row handling for mixed-null inputs.

const auto week_view = ColumnView<TYPE_STRING>::create(week_column);
for (size_t i = 0; i < input_rows_count; ++i) {
if (date_view.is_null_at(i) || week_view.is_null_at(i)) {
DORIS_CHECK(null_map != nullptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is inside the scalar row loop, while the repository guidance and check.h explicitly require DCHECK in loops where release checks add overhead. The relationship between input nullability and the result null map is fixed for the block, so please either validate it once before the loop or use the debug-only form here. Suggested local fix:

Suggested change
DORIS_CHECK(null_map != nullptr);
DCHECK(null_map != nullptr);

}
auto dtv = date_v2_from_date_like(date_view.value_at(i));
auto week = week_view.value_at(i);
auto week_day = day_of_week(week);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please preserve the partial-constant fast paths here. For next_day(date_col, 'MON'), the framework's all-constant handling does not run because only one argument is constant, so week_view.is_const reaches this loop. The removed right_const branch ran day_of_week once; this version copies, uppercases, and hashes the same literal for every row, changing that work from O(1) to O(N). The analogous constant-date path now also repeats DateV2/TimestampNs conversion. Cache a constant weekday lazily after the NULL short-circuit, and cache an immutable converted constant date that is copied before each per-row mutation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你说的对,可是过去就是因为他自己手写了null和const的处理,导致他变成错的了。

@Mryange

Mryange commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 91.89% (34/37) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.03% (29320/46521)
Line Coverage 47.96% (305864/637798)
Region Coverage 43.59% (246843/566242)
Branch Coverage 45.13% (114694/254134)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (37/37) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.24% (34345/45049)
Line Coverage 61.11% (385346/630542)
Region Coverage 57.51% (324359/564008)
Branch Coverage 58.29% (147696/253363)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants