Skip to content

Conversation

@uchenily
Copy link
Contributor

What problem does this PR solve?

The date_add function supports new type: DAY_SECOND, now we can use a string in the format 'day hour:minute:second' as the INTERVAL parameter.

mysql> select DATE_ADD('2025-10-23 10:10:10', INTERVAL '1 01:02:03' DAY_SECOND);
+-------------------------------------------------------------------+
| DATE_ADD('2025-10-23 10:10:10', INTERVAL '1 01:02:03' DAY_SECOND) |
+-------------------------------------------------------------------+
| 2025-10-24 11:12:13                                               |
+-------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> select * from datetime_table;
+---------------------+
| datetime            |
+---------------------+
| 2024-01-15 10:30:00 |
| 2024-01-15 14:45:30 |
| 2024-01-15 20:15:45 |
+---------------------+
3 rows in set (0.02 sec)

mysql> select DATE_ADD(datetime, INTERVAL '1 01:02:03' DAY_SECOND) from datetime_table;
+------------------------------------------------------+
| DATE_ADD(datetime, INTERVAL '1 01:02:03' DAY_SECOND) |
+------------------------------------------------------+
| 2024-01-16 11:32:03                                  |
| 2024-01-16 15:47:33                                  |
| 2024-01-16 21:17:48                                  |
+------------------------------------------------------+
3 rows in set (0.01 sec)

Co-authored-by: codeDing18 [email protected]

Issue Number: close #52132

Related PR: #xxx

Problem Summary:

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

@Thearas
Copy link
Contributor

Thearas commented Oct 23, 2025

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?

@codeDing18
Copy link
Contributor

run buildall

@doris-robot
Copy link

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

query1	0.06	0.06	0.05
query2	0.09	0.05	0.05
query3	0.26	0.09	0.08
query4	1.62	0.12	0.14
query5	0.28	0.26	0.24
query6	1.18	0.66	0.64
query7	0.03	0.02	0.02
query8	0.05	0.04	0.04
query9	0.62	0.53	0.53
query10	0.60	0.60	0.59
query11	0.17	0.12	0.14
query12	0.16	0.12	0.13
query13	0.64	0.61	0.59
query14	1.02	1.02	1.01
query15	0.85	0.86	0.87
query16	0.40	0.39	0.39
query17	1.05	1.09	1.03
query18	0.24	0.21	0.20
query19	1.87	1.82	1.83
query20	0.02	0.02	0.02
query21	15.42	0.19	0.13
query22	5.03	0.08	0.05
query23	15.70	0.26	0.11
query24	2.78	0.70	0.30
query25	0.08	0.08	0.07
query26	0.15	0.13	0.14
query27	0.07	0.06	0.06
query28	4.19	1.15	0.93
query29	12.57	4.01	3.29
query30	0.29	0.14	0.11
query31	2.82	0.61	0.39
query32	3.24	0.56	0.48
query33	2.98	3.05	3.13
query34	15.82	5.17	4.52
query35	4.59	4.55	4.57
query36	0.67	0.50	0.49
query37	0.11	0.07	0.07
query38	0.07	0.05	0.04
query39	0.04	0.03	0.03
query40	0.17	0.16	0.14
query41	0.08	0.04	0.04
query42	0.05	0.03	0.03
query43	0.05	0.04	0.04
Total cold run time: 98.18 s
Total hot run time: 27.57 s

@zclllyybb zclllyybb self-assigned this Oct 23, 2025
@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 2.70% (1/37) 🎉
Increment coverage report
Complete coverage report

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 9.09% (6/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.65% (17935/34067)
Line Coverage 37.88% (162716/429534)
Region Coverage 32.27% (124039/384352)
Branch Coverage 33.70% (54376/161362)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 74.24% (49/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.44% (23895/33449)
Line Coverage 57.85% (248680/429865)
Region Coverage 52.93% (206204/389615)
Branch Coverage 54.72% (88841/162347)

@codeDing18
Copy link
Contributor

run feut

@codeDing18
Copy link
Contributor

run p0

@codeDing18
Copy link
Contributor

run cloud_p0

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 27.03% (10/37) 🎉
Increment coverage report
Complete coverage report

assert_cast<const IntervalColumnType&>(nest_col1_const->get_data_column());
Op::vector_constant(sources->get_data(), res_col->get_data(),
col1_inside_const.get_data()[0], nullmap0, nullmap1);
if constexpr (Transform::IntervalPRealType == TYPE_STRING) {
Copy link
Contributor

Choose a reason for hiding this comment

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

type is TYPE_STRING could represent day_second just now. shouldn't put the logic here.

Op::vector_constant(sources->get_data(), res_col->get_data(),
col1_inside_const.get_data()[0], nullmap0, nullmap1);
if constexpr (Transform::IntervalPRealType == TYPE_STRING) {
StringRef time_str = nest_col1_const->get_data_at(0).trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

why think col1 is const? for arguments all const, here will get non-const.

static constexpr PrimitiveType ArgPType = PType;
static constexpr PrimitiveType ReturnType = PType;
static constexpr PrimitiveType IntervalPType = PrimitiveType ::TYPE_INT;
static constexpr PrimitiveType IntervalPRealType = TYPE_STRING;
Copy link
Contributor

Choose a reason for hiding this comment

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

why add this? why cant just use IntervalPType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually a compromise solution. We introduced the IntervalPRealType field to handle cases like AddDaySecondImpl where the delta value passed during the execution of the execute method requires type conversion (StringRef → Integer). (So we cannot directly use the ADD_TIME_FUNCTION_IMPL macro to generate the code).

If we hadn't introduced the IntervalPRealType field and instead set IntervalPType = TYPE_STRING, then in FunctionDateOrDateTimeComputation::execute_impl, we would need to handle TYPE_STRING cases for all three scenarios: vector-vector, vector-const, and const-vector. While the vector-const scenario would be simple to handle, but handling other scenarios will be complex, as we would need to modify all execute methods to support the TYPE_STRING type.

Copy link
Contributor

Choose a reason for hiding this comment

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

need many other test include testFoldConst, scalar to scalar, ...

Copy link
Contributor Author

@uchenily uchenily Oct 23, 2025

Choose a reason for hiding this comment

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

done, we add new regression tests in regression-test/suites/query_p0/sql_functions/datetime_functions/test_dateadd_with_other_timeunit.groovy

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 74.24% (49/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.44% (23895/33449)
Line Coverage 57.85% (248677/429865)
Region Coverage 52.89% (206053/389615)
Branch Coverage 54.72% (88840/162347)

1 similar comment
@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 74.24% (49/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.44% (23895/33449)
Line Coverage 57.85% (248677/429865)
Region Coverage 52.89% (206053/389615)
Branch Coverage 54.72% (88840/162347)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 27.03% (10/37) 🎉
Increment coverage report
Complete coverage report

1 similar comment
@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 27.03% (10/37) 🎉
Increment coverage report
Complete coverage report

@uchenily
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

query1	0.06	0.06	0.06
query2	0.10	0.06	0.05
query3	0.26	0.09	0.08
query4	1.63	0.12	0.12
query5	0.29	0.28	0.25
query6	1.21	0.68	0.66
query7	0.05	0.03	0.03
query8	0.07	0.06	0.05
query9	0.62	0.55	0.54
query10	0.60	0.62	0.58
query11	0.17	0.12	0.13
query12	0.17	0.12	0.13
query13	0.63	0.62	0.62
query14	1.02	1.02	1.02
query15	0.86	0.85	0.88
query16	0.39	0.41	0.43
query17	1.06	1.08	1.05
query18	0.23	0.22	0.22
query19	1.94	1.85	1.90
query20	0.03	0.02	0.02
query21	15.43	0.19	0.14
query22	4.99	0.08	0.06
query23	15.64	0.28	0.11
query24	2.46	0.68	0.75
query25	0.08	0.07	0.07
query26	0.16	0.15	0.14
query27	0.08	0.06	0.06
query28	4.65	1.17	0.96
query29	12.55	4.08	3.36
query30	0.32	0.17	0.13
query31	2.82	0.61	0.39
query32	3.26	0.56	0.47
query33	3.08	3.11	3.04
query34	15.90	5.15	4.57
query35	4.63	4.60	4.58
query36	0.71	0.52	0.50
query37	0.12	0.07	0.08
query38	0.07	0.05	0.05
query39	0.04	0.03	0.04
query40	0.18	0.15	0.16
query41	0.09	0.04	0.04
query42	0.04	0.04	0.04
query43	0.04	0.04	0.04
Total cold run time: 98.73 s
Total hot run time: 28.38 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 51.35% (19/37) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Contributor

BE UT Coverage Report

Increment line coverage 9.09% (6/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.62% (17940/34091)
Line Coverage 37.85% (162764/430001)
Region Coverage 32.28% (124134/384596)
Branch Coverage 33.67% (54365/161461)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 74.24% (49/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.42% (23906/33473)
Line Coverage 57.82% (248819/430350)
Region Coverage 52.85% (206054/389862)
Branch Coverage 54.66% (88789/162452)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 83.78% (31/37) 🎉
Increment coverage report
Complete coverage report

@uchenily
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-DS: Total hot run time: 190014 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit f7b7cce38d3d585232b5c84417754a00a2e78da2, data reload: false

query1	1060	436	411	411
query2	6570	1758	1696	1696
query3	6755	232	219	219
query4	26584	23511	23544	23511
query5	5122	670	505	505
query6	350	257	265	257
query7	4682	511	301	301
query8	344	271	264	264
query9	8749	2634	2629	2629
query10	552	352	296	296
query11	15507	15297	14838	14838
query12	210	120	119	119
query13	1693	558	446	446
query14	12668	9329	9220	9220
query15	218	188	175	175
query16	7688	675	490	490
query17	1575	752	630	630
query18	2132	449	346	346
query19	261	239	197	197
query20	159	133	134	133
query21	221	138	118	118
query22	4615	4644	4471	4471
query23	34716	33761	33452	33452
query24	8111	2590	2567	2567
query25	618	533	501	501
query26	1342	296	164	164
query27	2738	517	422	422
query28	5500	2242	2273	2242
query29	855	646	509	509
query30	318	230	212	212
query31	1003	1010	748	748
query32	84	73	67	67
query33	594	376	335	335
query34	841	883	539	539
query35	839	877	798	798
query36	1041	1040	948	948
query37	138	112	90	90
query38	3783	3644	3474	3474
query39	1524	1436	1406	1406
query40	213	130	115	115
query41	60	59	58	58
query42	126	111	124	111
query43	487	512	487	487
query44	1256	749	741	741
query45	181	177	173	173
query46	883	1013	650	650
query47	1723	1785	1688	1688
query48	405	425	313	313
query49	750	490	412	412
query50	654	702	417	417
query51	3894	3924	3952	3924
query52	109	106	101	101
query53	242	275	212	212
query54	605	593	554	554
query55	91	86	86	86
query56	356	366	323	323
query57	1158	1191	1132	1132
query58	310	291	282	282
query59	2618	2561	2631	2561
query60	360	376	355	355
query61	184	186	179	179
query62	806	717	717	717
query63	240	198	192	192
query64	4466	1180	840	840
query65	4096	3959	3951	3951
query66	1097	432	337	337
query67	15237	15193	14858	14858
query68	9311	906	600	600
query69	508	334	291	291
query70	1348	1311	1291	1291
query71	505	333	324	324
query72	6068	4905	4680	4680
query73	704	569	358	358
query74	9211	9022	9034	9022
query75	4343	3395	2890	2890
query76	3798	1149	730	730
query77	823	415	317	317
query78	9697	9728	8812	8812
query79	2648	834	589	589
query80	696	601	636	601
query81	536	259	233	233
query82	525	162	129	129
query83	314	273	243	243
query84	300	120	93	93
query85	914	480	441	441
query86	391	314	291	291
query87	3782	3792	3694	3694
query88	3720	2228	2218	2218
query89	385	322	299	299
query90	1976	220	218	218
query91	170	160	141	141
query92	87	70	69	69
query93	1916	973	645	645
query94	688	424	332	332
query95	407	324	324	324
query96	499	572	276	276
query97	2943	2979	2870	2870
query98	243	215	225	215
query99	1469	1436	1263	1263
Total cold run time: 285292 ms
Total hot run time: 190014 ms

@doris-robot
Copy link

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

query1	0.05	0.05	0.05
query2	0.10	0.06	0.06
query3	0.26	0.09	0.09
query4	1.62	0.12	0.12
query5	0.28	0.26	0.25
query6	1.19	0.66	0.66
query7	0.03	0.03	0.03
query8	0.05	0.04	0.04
query9	0.63	0.52	0.52
query10	0.57	0.58	0.58
query11	0.17	0.11	0.11
query12	0.16	0.12	0.13
query13	0.64	0.61	0.60
query14	1.00	1.01	1.02
query15	0.86	0.83	0.83
query16	0.39	0.39	0.38
query17	1.03	1.02	1.02
query18	0.22	0.20	0.20
query19	1.90	1.81	1.82
query20	0.02	0.02	0.01
query21	15.44	0.18	0.13
query22	5.04	0.07	0.05
query23	15.70	0.27	0.10
query24	2.61	0.60	0.82
query25	0.06	0.07	0.07
query26	0.14	0.14	0.13
query27	0.08	0.06	0.05
query28	4.30	1.15	0.95
query29	12.58	4.05	3.33
query30	0.29	0.15	0.11
query31	2.82	0.60	0.38
query32	3.23	0.55	0.48
query33	3.13	3.05	3.13
query34	15.92	5.22	4.56
query35	4.59	4.53	4.58
query36	0.69	0.51	0.50
query37	0.10	0.07	0.07
query38	0.07	0.05	0.04
query39	0.04	0.03	0.03
query40	0.17	0.17	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.02
Total cold run time: 98.34 s
Total hot run time: 27.87 s

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 9.09% (6/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.63% (17941/34092)
Line Coverage 37.85% (162768/430013)
Region Coverage 32.27% (124119/384597)
Branch Coverage 33.67% (54365/161461)

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 51.35% (19/37) 🎉
Increment coverage report
Complete coverage report

@codeDing18
Copy link
Contributor

run feut

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 74.24% (49/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.32% (23875/33474)
Line Coverage 57.74% (248488/430364)
Region Coverage 52.75% (205658/389864)
Branch Coverage 54.54% (88606/162452)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 83.78% (31/37) 🎉
Increment coverage report
Complete coverage report

@codeDing18
Copy link
Contributor

run nonConcurrent

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 74.24% (49/66) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.32% (23873/33474)
Line Coverage 57.73% (248457/430364)
Region Coverage 52.76% (205707/389864)
Branch Coverage 54.54% (88603/162452)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 83.78% (31/37) 🎉
Increment coverage report
Complete coverage report

@uchenily uchenily requested a review from zclllyybb October 24, 2025 09:52
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.

[Bug] Function date_add doesn't support DAY_SECOND INTERVAL which Mysql supports

6 participants