Skip to content

[refine](expr) Replace manual type switch-case with dispatch_switch helpers#62042

Open
Mryange wants to merge 2 commits intoapache:masterfrom
Mryange:use-dispatch-not-switch-case
Open

[refine](expr) Replace manual type switch-case with dispatch_switch helpers#62042
Mryange wants to merge 2 commits intoapache:masterfrom
Mryange:use-dispatch-not-switch-case

Conversation

@Mryange
Copy link
Copy Markdown
Contributor

@Mryange Mryange commented Apr 2, 2026

What problem does this PR solve?

Several aggregate/scalar functions in be/src/exprs/ use large hand-written switch-case blocks to dispatch on PrimitiveType. These are verbose, error-prone, and generate repetitive boilerplate.

This PR replaces them with the existing dispatch_switch_scalar / dispatch_switch_number utilities from call_on_type_index.h:

  • least_greast.cpp (FunctionFieldImpl::execute): ~15 manual cases → dispatch_switch_scalar
  • aggregate_function_group_array_set_op_impl.h: ~16 manual cases → dispatch_switch_scalar + string branch
  • function_array_cum_sum.cpp (_execute_by_type): ~13 manual cases → dispatch_switch_number with constexpr if type promotion

Release note

None

  • 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
Copy Markdown
Contributor

Thearas commented Apr 2, 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?

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented Apr 2, 2026

run buildall

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented Apr 2, 2026

run buildall

@doris-robot
Copy link
Copy Markdown

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

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17608	3661	3638	3638
q2	q3	10695	890	600	600
q4	4670	461	366	366
q5	7463	1334	1146	1146
q6	195	169	141	141
q7	908	930	778	778
q8	9452	1406	1314	1314
q9	5606	5333	5269	5269
q10	6322	2024	1768	1768
q11	485	276	274	274
q12	892	704	511	511
q13	18076	2767	2160	2160
q14	285	286	257	257
q15	q16	915	854	789	789
q17	1084	1066	802	802
q18	6532	5536	5563	5536
q19	1172	1211	1111	1111
q20	611	565	409	409
q21	4719	2421	2023	2023
q22	447	372	327	327
Total cold run time: 98137 ms
Total hot run time: 29219 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4526	4377	4281	4281
q2	q3	4629	4813	4140	4140
q4	2030	2064	1331	1331
q5	4920	5012	5149	5012
q6	207	174	137	137
q7	1978	1744	1651	1651
q8	3246	3016	3075	3016
q9	8255	8222	8201	8201
q10	4438	4453	4210	4210
q11	612	424	389	389
q12	664	724	498	498
q13	2938	3078	2385	2385
q14	303	318	267	267
q15	q16	742	789	668	668
q17	1306	1246	1236	1236
q18	7899	7014	7046	7014
q19	1138	1127	1184	1127
q20	2197	2224	1945	1945
q21	5942	5250	4979	4979
q22	544	523	424	424
Total cold run time: 58514 ms
Total hot run time: 52911 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.92% (20044/37876)
Line Coverage 36.52% (188143/515116)
Region Coverage 32.80% (146159/445603)
Branch Coverage 33.95% (63950/188376)

@doris-robot
Copy link
Copy Markdown

TPC-DS: Total hot run time: 180443 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 6c07bcb351fc73ca60ee2ea717dbd53aa903f439, data reload: false

query5	4338	641	507	507
query6	342	235	212	212
query7	4328	604	343	343
query8	333	241	229	229
query9	8748	3941	3986	3941
query10	507	402	362	362
query11	6665	5489	5140	5140
query12	192	134	131	131
query13	1317	633	450	450
query14	5693	5214	4812	4812
query14_1	4170	4138	4139	4138
query15	214	201	180	180
query16	1043	457	444	444
query17	1156	813	622	622
query18	2722	490	372	372
query19	247	231	184	184
query20	149	129	130	129
query21	218	150	120	120
query22	13988	14788	14599	14599
query23	17996	17173	16710	16710
query23_1	17188	16802	16907	16802
query24	7849	1736	1360	1360
query24_1	1342	1315	1343	1315
query25	588	484	431	431
query26	1271	331	185	185
query27	2621	585	361	361
query28	4442	1995	1974	1974
query29	968	696	569	569
query30	297	242	200	200
query31	1094	1050	996	996
query32	90	78	71	71
query33	560	363	312	312
query34	1224	1197	703	703
query35	769	814	681	681
query36	1296	1316	1122	1122
query37	159	104	87	87
query38	3172	3012	2964	2964
query39	909	890	867	867
query39_1	827	836	838	836
query40	239	160	158	158
query41	70	67	64	64
query42	295	284	271	271
query43	318	328	278	278
query44	
query45	210	200	198	198
query46	1158	1280	811	811
query47	2332	2319	2265	2265
query48	387	417	311	311
query49	658	558	432	432
query50	730	292	217	217
query51	4318	4273	4196	4196
query52	281	289	270	270
query53	340	348	279	279
query54	332	303	301	301
query55	108	95	98	95
query56	356	347	330	330
query57	1764	1635	1754	1635
query58	308	289	283	283
query59	2886	3000	2779	2779
query60	390	333	314	314
query61	157	154	154	154
query62	691	626	551	551
query63	338	271	267	267
query64	5187	1385	1068	1068
query65	
query66	1394	473	388	388
query67	24410	24331	24096	24096
query68	
query69	449	335	307	307
query70	995	953	993	953
query71	366	324	316	316
query72	2862	2694	2407	2407
query73	822	751	454	454
query74	9801	9700	9597	9597
query75	3551	3384	2975	2975
query76	2304	1112	761	761
query77	402	416	343	343
query78	11200	11376	10732	10732
query79	1533	1081	799	799
query80	831	769	668	668
query81	459	284	236	236
query82	1304	155	120	120
query83	345	298	263	263
query84	259	141	118	118
query85	861	498	471	471
query86	379	316	317	316
query87	3303	3190	3099	3099
query88	3550	2681	2733	2681
query89	471	433	383	383
query90	1973	188	180	180
query91	178	167	146	146
query92	80	79	71	71
query93	916	886	522	522
query94	536	324	279	279
query95	665	461	347	347
query96	1067	739	353	353
query97	2693	2663	2544	2544
query98	240	226	225	225
query99	1070	1085	955	955
Total cold run time: 259433 ms
Total hot run time: 180443 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (48/48) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.79% (26630/37095)
Line Coverage 54.75% (281158/513567)
Region Coverage 51.86% (233216/449716)
Branch Coverage 53.27% (100640/188942)

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