Skip to content

expression: return null for empty time format#67538

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
hawkingrei:issue-59445-time-format-null
Apr 12, 2026
Merged

expression: return null for empty time format#67538
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
hawkingrei:issue-59445-time-format-null

Conversation

@hawkingrei
Copy link
Copy Markdown
Member

@hawkingrei hawkingrei commented Apr 2, 2026

What problem does this PR solve?

Issue Number: close #59445

Problem Summary:

TIME_FORMAT(expr, format) should return NULL when format is an empty string.

What changed and how does it work?

  • Return NULL early in builtinTimeFormatSig.evalString when the format string is empty.
  • Add a regression case in TestTimeFormat for TIME_FORMAT('12:34:56', '').

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Validation:

  • bazel test //pkg/expression:expression_test --test_sharding_strategy=disabled --test_arg=-test.run=^TestTimeFormat$ --test_arg=-test.v --test_output=streamed
  • make lint

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix `TIME_FORMAT(expr, '')` to return `NULL`.

Summary by CodeRabbit

  • Bug Fixes

    • Time formatting now correctly returns NULL when given an empty format string, including in vectorized evaluation paths.
  • Tests

    • Added unit and vectorized tests asserting TimeFormat yields NULL for an empty format string and verifying correct non-NULL formatting for valid patterns to prevent regressions.

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 35d2f12b-5f6c-4122-954a-6f7f9e674f76

📥 Commits

Reviewing files that changed from the base of the PR and between f976add and 187e8d8.

📒 Files selected for processing (2)
  • pkg/expression/builtin_time_vec.go
  • pkg/expression/builtin_time_vec_test.go

📝 Walkthrough

Walkthrough

TIME_FORMAT now returns NULL when given an empty format string. Both scalar and vectorized evaluation paths were changed to treat "" as NULL, and unit tests (scalar and vectorized) were added to assert this behavior (issue #59445).

Changes

Cohort / File(s) Summary
Scalar TIME_FORMAT logic
pkg/expression/builtin_time.go
Treat empty formatMask as a NULL result: return ("", true, nil) when len(formatMask) == 0, avoiding calling b.formatTime with an empty format.
Vectorized TIME_FORMAT logic
pkg/expression/builtin_time_vec.go
When vectorized evaluation sees an empty format string (len(buf1.GetString(i)) == 0), append NULL and skip formatTime. Preserves existing NULL input checks.
Scalar tests
pkg/expression/builtin_time_test.go
Added regression assertion in TestTimeFormat verifying TIME_FORMAT('12:34:56', '') yields NULL (issue #59445).
Vectorized tests
pkg/expression/builtin_time_vec_test.go
Added TestVectorizedTimeFormatEmptyFormatReturnsNull: builds a vectorized function, supplies a chunk with an empty format in row 0 and "%H:%i:%s" in row 1, asserts NULL for row 0 and correct formatted string for row 1; verifies vectorization flags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • qw4990
  • AilinKid

Poem

🐰 I nibbled the format, found an empty shell,
A gentle hop fixed the clocking spell.
Empty string now yields a NULL so neat,
Time ticks tidy on nimble feet.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: making TIME_FORMAT return null for empty format strings.
Description check ✅ Passed The PR description follows the template with all required sections completed: issue number, problem summary, what changed, tests checklist, side effects, and release note.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #59445 by returning NULL when TIME_FORMAT is called with an empty format string, matching MySQL behavior. Changes were made to both scalar and vectorized implementations with corresponding tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing TIME_FORMAT behavior for empty format strings. No unrelated modifications or improvements are present in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.4)

Command failed


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.4488%. Comparing base (c245042) to head (187e8d8).
⚠️ Report is 20 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #67538        +/-   ##
================================================
+ Coverage   77.5948%   78.4488%   +0.8539%     
================================================
  Files          1981       1974         -7     
  Lines        547950     550676      +2726     
================================================
+ Hits         425181     431999      +6818     
+ Misses       121959     118240      -3719     
+ Partials        810        437       -373     
Flag Coverage Δ
integration 44.0164% <0.0000%> (+9.6766%) ⬆️
unit 77.0237% <100.0000%> (+0.6804%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 61.5065% <ø> (ø)
parser ∅ <ø> (∅)
br 49.9748% <ø> (-10.4636%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei hawkingrei force-pushed the issue-59445-time-format-null branch from f286831 to f976add Compare April 8, 2026 23:24
@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

}
if len(formatMask) == 0 {
return "", true, nil
}
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.

what about the vec version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. I fixed the vectorized path as well and added a dedicated vectorized regression test in 187e8d8.

@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 9, 2026
@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

Copy link
Copy Markdown
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 9, 2026
@hawkingrei hawkingrei requested a review from guo-shaoge April 9, 2026 08:27
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 9, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guo-shaoge, windtalker

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 9, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 9, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-09 08:23:13.210937104 +0000 UTC m=+1030998.416297162: ☑️ agreed by windtalker.
  • 2026-04-09 08:45:39.063609479 +0000 UTC m=+1032344.268969536: ☑️ agreed by guo-shaoge.

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

7 similar comments
@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

10 similar comments
@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member Author

/retest

@ti-chi-bot ti-chi-bot Bot merged commit a83fcdb into pingcap:master Apr 12, 2026
35 checks passed
premal pushed a commit to premal/tidb that referenced this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TIME_FORMAT should return NULL for empty format

3 participants