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.

@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.50% (19286/36733)
Line Coverage 35.98% (179175/498003)
Region Coverage 32.43% (139147/429056)
Branch Coverage 33.37% (60184/180363)

@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.56% (25766/36008)
Line Coverage 54.21% (269334/496830)
Region Coverage 51.92% (225075/433475)
Branch Coverage 53.22% (96383/181095)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 89.53% (624/697) 🎉
Increment coverage report
Complete coverage report

zclllyybb
zclllyybb previously approved these changes Feb 2, 2026
Copy link
Contributor

@zclllyybb zclllyybb left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Feb 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

PR approved by anyone and no changes requested.

BiteTheDDDDt
BiteTheDDDDt previously approved these changes Feb 6, 2026
@BiteTheDDDDt
Copy link
Contributor

gcc下编不过,导致performance流水线失败了

@linrrzqqq
Copy link
Contributor Author

run buildall

@github-actions github-actions bot removed the approved Indicates a PR has been approved by one committer. label Feb 6, 2026
@doris-robot
Copy link

TPC-H: Total hot run time: 31099 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 857c32b20e3bbac22250755aa5c55a9a03b841fc, data reload: false

------ Round 1 ----------------------------------
q1	17606	4497	4301	4301
q2	2084	342	226	226
q3	10150	1331	718	718
q4	10231	930	315	315
q5	7492	2136	1943	1943
q6	201	174	146	146
q7	885	709	597	597
q8	9255	1340	1112	1112
q9	5238	4899	4924	4899
q10	6840	1957	1580	1580
q11	513	303	272	272
q12	352	375	223	223
q13	17801	4057	3271	3271
q14	233	240	213	213
q15	907	801	813	801
q16	691	674	618	618
q17	624	826	472	472
q18	6707	6548	6342	6342
q19	1241	997	615	615
q20	376	356	251	251
q21	2695	2095	1901	1901
q22	358	318	283	283
Total cold run time: 102480 ms
Total hot run time: 31099 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4389	4359	4411	4359
q2	270	343	241	241
q3	2114	2586	2258	2258
q4	1347	1757	1266	1266
q5	4377	4227	4355	4227
q6	205	177	139	139
q7	1829	1804	1639	1639
q8	2869	2473	2374	2374
q9	7534	7517	7556	7517
q10	2873	3003	2695	2695
q11	565	503	455	455
q12	679	737	588	588
q13	4041	4274	3602	3602
q14	330	315	284	284
q15	837	797	815	797
q16	698	740	697	697
q17	1162	1328	1354	1328
q18	8471	7902	7988	7902
q19	879	870	886	870
q20	2331	2119	1972	1972
q21	4953	4411	4170	4170
q22	562	519	499	499
Total cold run time: 53315 ms
Total hot run time: 49879 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 28.62 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 857c32b20e3bbac22250755aa5c55a9a03b841fc, data reload: false

query1	0.05	0.04	0.04
query2	0.10	0.05	0.05
query3	0.26	0.09	0.09
query4	1.61	0.11	0.12
query5	0.26	0.24	0.24
query6	1.16	0.67	0.68
query7	0.03	0.02	0.02
query8	0.05	0.03	0.05
query9	0.57	0.51	0.50
query10	0.55	0.54	0.55
query11	0.14	0.09	0.10
query12	0.14	0.10	0.10
query13	0.62	0.61	0.61
query14	1.08	1.05	1.06
query15	0.87	0.86	0.87
query16	0.40	0.42	0.39
query17	1.09	1.10	1.15
query18	0.22	0.22	0.21
query19	2.14	1.95	2.07
query20	0.02	0.02	0.01
query21	15.40	0.29	0.14
query22	5.19	0.07	0.06
query23	15.86	0.30	0.10
query24	1.16	0.66	0.55
query25	0.09	0.08	0.15
query26	0.14	0.14	0.14
query27	0.08	0.07	0.05
query28	4.61	1.17	0.97
query29	12.56	3.99	3.17
query30	0.28	0.14	0.12
query31	2.82	0.65	0.41
query32	3.23	0.59	0.50
query33	3.38	3.24	3.20
query34	16.11	5.57	4.78
query35	4.82	4.81	4.81
query36	0.66	0.50	0.49
query37	0.12	0.07	0.07
query38	0.08	0.04	0.04
query39	0.05	0.03	0.03
query40	0.20	0.16	0.15
query41	0.08	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 98.36 s
Total hot run time: 28.62 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 14.06% (98/697) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Contributor

BE UT Coverage Report

Increment line coverage 58.26% (201/345) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.55% (19375/36871)
Line Coverage 36.06% (180046/499322)
Region Coverage 32.42% (139583/430482)
Branch Coverage 33.44% (60483/180854)

@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.63% (25883/36134)
Line Coverage 54.29% (270439/498138)
Region Coverage 51.87% (225595/434909)
Branch Coverage 53.24% (96684/181586)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 89.53% (624/697) 🎉
Increment coverage report
Complete coverage report

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Feb 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

PR approved by at least one committer and no changes requested.

@zclllyybb zclllyybb merged commit d18bd5c into apache:master Feb 9, 2026
31 of 32 checks passed
@linrrzqqq linrrzqqq deleted the more-interval-unit branch February 9, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.0.x dev/4.0.x-conflict reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants