Skip to content

Conversation

@tommyhugh2333-rgb
Copy link

@tommyhugh2333-rgb tommyhugh2333-rgb commented Jan 21, 2026

Problem Summary

Implemented the scalar function gamma(x) which calculates the Gamma function.
This implementation maps the SQL function gamma to the C++ standard library function std::tgamma.

  • Backend: Registered gamma to std::tgamma in math.cpp.
  • Frontend: Added function signature in FunctionSet.java and implemented Gamma.java for Nereids optimizer.

Checklist

  • Manual test (add detailed scripts or steps below)
    • Executed SELECT gamma(5); in MySQL client.
    • Result: 24 (Correct, 4! = 24).
  • 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.

@hello-stephen
Copy link
Contributor

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?

@zclllyybb zclllyybb self-assigned this Jan 21, 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.

should add regression-test case, beut case, and fe fold-constant implementation

@tommyhugh2333-rgb
Copy link
Author

Hi @zclllyybb, thanks for your review!

I have addressed all your comments:

  1. Refactor: Reverted changes in FoldConstantRuleOnFE.java and moved the constant folding logic to the compute() method in Gamma.java using the imported class.
  2. License: Added the missing Apache License header to test_gamma.groovy.
  3. Format: Fixed code style issues and synchronized the BE unit test cases with the regression test.

Please check it again when you have time. Thanks!

@zclllyybb
Copy link
Contributor

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17663	4853	4586	4586
q2	2053	308	198	198
q3	10215	1286	727	727
q4	10212	814	303	303
q5	7535	2052	1886	1886
q6	191	172	141	141
q7	881	737	582	582
q8	9265	1341	1163	1163
q9	4952	4671	4553	4553
q10	6807	1649	1266	1266
q11	525	311	277	277
q12	391	382	230	230
q13	17798	3806	3078	3078
q14	247	233	214	214
q15	604	530	536	530
q16	635	653	595	595
q17	661	775	507	507
q18	6765	6450	6838	6450
q19	1655	1029	654	654
q20	418	366	259	259
q21	3091	2224	2066	2066
q22	1125	1106	1062	1062
Total cold run time: 103689 ms
Total hot run time: 31327 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5165	4967	4939	4939
q2	328	408	324	324
q3	2373	2945	2516	2516
q4	1405	1880	1440	1440
q5	4535	4319	4298	4298
q6	235	174	134	134
q7	2031	1939	1843	1843
q8	2549	2487	2583	2487
q9	7156	7181	7261	7181
q10	2461	2730	2324	2324
q11	565	490	453	453
q12	775	706	572	572
q13	3348	3819	3070	3070
q14	295	290	268	268
q15	537	503	496	496
q16	601	650	621	621
q17	1089	1325	1396	1325
q18	7446	7277	7316	7277
q19	807	818	781	781
q20	1899	1979	1830	1830
q21	4594	4296	4116	4116
q22	1094	1007	956	956
Total cold run time: 51288 ms
Total hot run time: 49251 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 173049 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 bf46530d29676404ef8c1f91b438c778f1c09af3, data reload: false

query5	4388	651	521	521
query6	328	228	196	196
query7	4230	467	262	262
query8	351	234	233	233
query9	8691	2917	2876	2876
query10	481	314	270	270
query11	15234	15054	14987	14987
query12	180	118	118	118
query13	1246	471	358	358
query14	5792	3038	2803	2803
query14_1	2692	2691	2709	2691
query15	202	193	171	171
query16	973	481	377	377
query17	1097	687	575	575
query18	2445	419	318	318
query19	195	174	150	150
query20	124	113	115	113
query21	208	136	120	120
query22	3934	4140	3989	3989
query23	15982	15704	15285	15285
query23_1	15339	15341	15275	15275
query24	7192	1560	1171	1171
query24_1	1151	1166	1188	1166
query25	529	456	385	385
query26	1251	271	148	148
query27	2763	458	272	272
query28	4566	2193	2175	2175
query29	742	518	434	434
query30	305	240	203	203
query31	766	639	548	548
query32	90	92	69	69
query33	533	348	302	302
query34	911	879	541	541
query35	726	745	671	671
query36	876	916	859	859
query37	140	96	84	84
query38	2796	2722	2710	2710
query39	769	735	733	733
query39_1	705	713	732	713
query40	215	132	119	119
query41	70	63	61	61
query42	101	92	87	87
query43	446	448	433	433
query44	1360	751	745	745
query45	191	189	178	178
query46	840	951	598	598
query47	1476	1486	1251	1251
query48	322	327	261	261
query49	634	439	359	359
query50	699	265	213	213
query51	3760	3887	3879	3879
query52	93	95	82	82
query53	216	221	171	171
query54	311	277	265	265
query55	86	85	78	78
query56	317	306	309	306
query57	959	1018	948	948
query58	279	273	274	273
query59	2117	2229	2145	2145
query60	360	332	340	332
query61	169	173	171	171
query62	379	350	348	348
query63	201	173	173	173
query64	4950	1130	825	825
query65	3827	3712	3700	3700
query66	1458	428	319	319
query67	15568	15548	15497	15497
query68	2410	1072	722	722
query69	408	304	274	274
query70	1011	940	956	940
query71	298	293	261	261
query72	5217	3116	3375	3116
query73	608	732	309	309
query74	8764	8787	8592	8592
query75	2269	2326	1919	1919
query76	2275	1056	661	661
query77	345	382	324	324
query78	9690	9903	9128	9128
query79	1072	912	606	606
query80	645	525	450	450
query81	475	266	234	234
query82	1376	152	121	121
query83	365	269	252	252
query84	254	108	94	94
query85	824	468	410	410
query86	353	298	291	291
query87	2857	2828	2732	2732
query88	3519	2604	2570	2570
query89	309	258	227	227
query90	1913	168	168	168
query91	178	154	134	134
query92	80	75	73	73
query93	1062	1046	653	653
query94	455	312	290	290
query95	582	338	319	319
query96	683	500	237	237
query97	2383	2380	2371	2371
query98	230	207	200	200
query99	611	580	519	519
Total cold run time: 245329 ms
Total hot run time: 173049 ms

@doris-robot
Copy link

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

query1	0.05	0.04	0.04
query2	0.10	0.05	0.05
query3	0.27	0.08	0.08
query4	1.60	0.11	0.12
query5	0.27	0.25	0.26
query6	1.15	0.67	0.65
query7	0.03	0.03	0.03
query8	0.06	0.04	0.04
query9	0.57	0.51	0.50
query10	0.55	0.54	0.55
query11	0.15	0.10	0.10
query12	0.14	0.10	0.11
query13	0.60	0.58	0.59
query14	0.96	0.94	0.96
query15	0.80	0.77	0.79
query16	0.40	0.42	0.40
query17	0.98	0.98	1.03
query18	0.23	0.21	0.21
query19	1.93	1.89	1.84
query20	0.01	0.02	0.01
query21	15.40	0.28	0.14
query22	5.28	0.06	0.04
query23	15.93	0.28	0.10
query24	1.00	0.55	0.27
query25	0.12	0.07	0.07
query26	0.14	0.14	0.13
query27	0.06	0.04	0.05
query28	4.02	1.07	0.90
query29	12.59	3.93	3.17
query30	0.27	0.13	0.12
query31	2.81	0.66	0.39
query32	3.24	0.56	0.46
query33	2.97	3.01	3.00
query34	16.08	5.07	4.41
query35	4.44	4.46	4.44
query36	0.68	0.51	0.48
query37	0.11	0.07	0.06
query38	0.07	0.04	0.03
query39	0.05	0.03	0.04
query40	0.17	0.14	0.12
query41	0.09	0.04	0.03
query42	0.04	0.03	0.03
query43	0.05	0.04	0.04
Total cold run time: 96.46 s
Total hot run time: 26.72 s

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.46% (19138/36478)
Line Coverage 35.85% (177845/496141)
Region Coverage 32.29% (137356/425407)
Branch Coverage 33.23% (59470/178958)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.23% (26183/35755)
Line Coverage 56.28% (278941/495597)
Region Coverage 54.06% (232413/429912)
Branch Coverage 55.74% (100185/179726)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 92.31% (12/13) 🎉
Increment coverage report
Complete coverage report

@tommyhugh2333-rgb
Copy link
Author

Hi @zclllyybb,
I checked the failed check (NonConcurrent Regression), and the error is "Lsan fail" (Memory LeakSanitizer failure).

Since my changes only involve adding a scalar math function (gamma) and shouldn't cause memory leaks, this looks like a flaky test or an unrelated environment issue.

Could you please help confirm whether this failure is caused by the code I added, or if it is an unrelated issue? Thanks!

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

@zclllyybb
Copy link
Contributor

Hi @zclllyybb, I checked the failed check (NonConcurrent Regression), and the error is "Lsan fail" (Memory LeakSanitizer failure).

Since my changes only involve adding a scalar math function (gamma) and shouldn't cause memory leaks, this looks like a flaky test or an unrelated environment issue.

Could you please help confirm whether this failure is caused by the code I added, or if it is an unrelated issue? Thanks!

I skipped it. code's good for me now.

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

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

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.23% (26183/35755)
Line Coverage 56.28% (278941/495597)
Region Coverage 54.06% (232413/429912)
Branch Coverage 55.74% (100185/179726)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 92.31% (12/13) 🎉
Increment coverage report
Complete coverage report

@zclllyybb
Copy link
Contributor

please link your docs PR in this PR content. then we can merge this.

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 reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants