Skip to content

Conversation

@linrrzqqq
Copy link
Contributor

@linrrzqqq linrrzqqq commented Jan 29, 2026

What problem does this PR solve?

Issue Number: close #xxx

Related PR: Fix the wrong behavior introduced in: #57253

Problem Summary:

Release note

doc: apache/doris-website#3315

Support all time unit in Mysql: https://dev.mysql.com/doc/refman/8.4/en/expressions.html#temporal-intervals

Affected function: DATE_ADD/SUB, EXTRACT

select extract(year_month from '2026-01-01 11:45:14.123456') as year_month,
       extract(day_hour from '2026-01-01 11:45:14.123456') as day_hour,
       extract(day_minute from '2026-01-01 11:45:14.123456') as day_minute,
       extract(day_second from '2026-01-01 11:45:14.123456') as day_second,
       extract(day_microsecond from '2026-01-01 11:45:14.123456') as day_microsecond,
       extract(hour_minute from '2026-01-01 11:45:14.123456') as hour_minute,
       extract(hour_second from '2026-01-01 11:45:14.123456') as hour_second,
       extract(hour_microsecond from '2026-01-01 11:45:14.123456') as hour_microsecond,
       extract(minute_second from '2026-01-01 11:45:14.123456') as minute_second,
       extract(minute_microsecond from '2026-01-01 11:45:14.123456') as minute_microsecond,
       extract(second_microsecond from '2026-01-01 11:45:14.123456') as second_microsecond;

+------------+----------+------------+-------------+-----------------------+-------------+-------------+-----------------------+--------------+----------------------+-------------------+
| year_month | day_hour | day_minute | day_second  | day_microsecond       | hour_minute | hour_second | hour_microsecond      | minute_second| minute_microsecond   | second_microsecond |
+------------+----------+------------+-------------+-----------------------+-------------+-------------+-----------------------+--------------+----------------------+-------------------+
| 2026-01    | 1 11     | 1 11:45    | 1 11:45:14  | 1 11:45:14.123456     | 11:45       | 11:45:14    | 11:45:14.123456       | 45:14        | 45:14.123456         | 14.123456         |
+------------+----------+------------+-------------+-----------------------+-------------+-------------+-----------------------+--------------+----------------------+-------------------+

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?

Check List (For Reviewer who merge this PR)

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

@linrrzqqq linrrzqqq requested a review from zclllyybb as a code owner January 29, 2026 07:08
@Thearas
Copy link
Contributor

Thearas commented Jan 29, 2026

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?

@linrrzqqq
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 58.26% (201/345) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.70% (19262/36552)
Line Coverage 36.10% (179004/495817)
Region Coverage 32.56% (138850/426407)
Branch Coverage 33.51% (60106/179361)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 96.19% (328/341) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.51% (25622/35830)
Line Coverage 54.15% (267819/494588)
Region Coverage 51.75% (222895/430734)
Branch Coverage 53.10% (95624/180077)

@linrrzqqq
Copy link
Contributor Author

run nonConcurrent

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 96.19% (328/341) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.51% (25622/35830)
Line Coverage 54.16% (267846/494588)
Region Coverage 51.75% (222909/430734)
Branch Coverage 53.11% (95633/180077)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 85.10% (594/698) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 96.19% (328/341) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.50% (25617/35830)
Line Coverage 54.14% (267758/494588)
Region Coverage 51.66% (222532/430734)
Branch Coverage 53.07% (95573/180077)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 85.10% (594/698) 🎉
Increment coverage report
Complete coverage report

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for all MySQL-compatible compound time units for INTERVAL operations in DATE_ADD/SUB and EXTRACT functions. It also fixes incorrect behavior introduced in PR #57253 where invalid format exceptions were expected but now the functions handle partial or malformed inputs more gracefully (similar to MySQL).

Changes:

  • Added support for 11 new compound time units: YEAR_MONTH, DAY_HOUR, DAY_MINUTE, DAY_SECOND, DAY_MICROSECOND, HOUR_MINUTE, HOUR_SECOND, HOUR_MICROSECOND, MINUTE_SECOND, MINUTE_MICROSECOND, SECOND_MICROSECOND
  • Refactored interval parsing logic in C++ backend to handle flexible input formats with better MySQL compatibility
  • Changed error handling from exceptions to best-effort parsing for malformed interval strings

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test_dateadd_with_other_timeunit.groovy Converts exception tests to query tests with expected outputs for malformed inputs
test_date_function.groovy Removes exception test for invalid hour format
doc_date_functions_test.groovy Renames alias from 'year_month' to 'year_and_month' for clarity
test_dateadd_with_other_timeunit.out Adds expected outputs for new query tests
test_add_sub_union_type.out Complete new test output file with 810 lines of test results
ScalarFunctionVisitor.java Adds visitor methods for all new time unit functions
Interval.java Reorders TimeUnit enum and adds new compound time units
YearMonth*.java, DayHour*.java, etc. New scalar function classes for extract and add/sub operations
DateTimeExtractAndTransform.java Adds extract implementations for all new time units
DateTimeArithmetic.java Complete rewrite of interval parsing with unified approach
DatetimeFunctionBinder.java Binds new time units to function implementations
BuiltinScalarFunctions.java Registers all new scalar functions
DorisParser.g4 Updates grammar for EXTRACT and unitIdentifier
DorisLexer.g4 Adds new keywords for compound time units
function_time_test.cpp Adds comprehensive C++ unit tests (670+ lines)
vdatetime_value.cpp Adds template instantiations for new time units
function_date_or_datetime_to_string.cpp Registers new extract functions
function_date_or_datetime_computation.h Major refactoring to unified AddUnionTypeImpl template
function_date_or_datetime_computation.cpp Updates function registrations with macros
datetime_errors.h Adds error helpers and time unit name mapping
date_time_transforms.h Adds format implementations for extract
date_format_type.h Adds low-level format structs for string conversion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

4 participants