Skip to content

[Enhancement] Add human_readable_seconds function#63923

Open
prakash-atul wants to merge 1 commit into
apache:masterfrom
prakash-atul:feature/human_readable_seconds
Open

[Enhancement] Add human_readable_seconds function#63923
prakash-atul wants to merge 1 commit into
apache:masterfrom
prakash-atul:feature/human_readable_seconds

Conversation

@prakash-atul
Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: #48203

Related PR: #61850

Problem Summary:

It adds human_readable_seconds(double) function with behavior aligned to Presto/Trino semantics.

Example:

select human_readable_seconds(3762);
-- 1 hour, 2 minutes, 42 seconds

This PR includes:

  • BE implementation for human_readable_seconds
  • FE constant folding support
  • scalar function registration
  • BE unit tests
  • FE unit tests
  • regression tests
  • Presto dialect compatibility tests
  • FE/BE consistency validation using testFoldConst

Behavior matches Presto/Trino:

  • rounds to whole seconds
  • uses absolute value for negative inputs
  • does not emit milliseconds
  • rejects NaN/Infinity inputs

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.
    • Added new human_readable_seconds(double) scalar function.
  • 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

Copilot AI review requested due to automatic review settings May 31, 2026 17:34
@hello-stephen
Copy link
Copy Markdown
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?

@prakash-atul
Copy link
Copy Markdown
Author

Hi @zclllyybb , the PR is ready for review.

I addressed the previous review feedback and aligned the implementation with Presto/Trino semantics. I also added FE/BE unit tests, regression tests, and FE/BE consistency validation.

Docs PR: apache/doris-website#3868

Thanks!

@zclllyybb
Copy link
Copy Markdown
Contributor

run buildall

@zclllyybb
Copy link
Copy Markdown
Contributor

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

I found one correctness issue that should be fixed before merge. The new function is otherwise focused and well covered for normal values, nullability, constants, NaN/Inf, and FE/BE consistency around common boundaries.

Critical checkpoint conclusions:

  • Goal and tests: the PR adds Presto-compatible human_readable_seconds; normal/null/constant/folding tests are present, but out-of-range finite DOUBLE behavior is not covered.
  • Scope: the implementation is small and focused.
  • Concurrency/lifecycle/config/transactions/persistence/data writes: not applicable; this is scalar expression evaluation only.
  • Parallel code paths: FE constant folding and BE execution are both implemented, but they diverge for large finite inputs.
  • Error handling: NaN/Inf are rejected, but finite values that cannot be rounded into int64 are not handled consistently.
  • FE-BE protocol/type consistency: signature and return type are otherwise consistent.
  • Test coverage/results: good coverage for ordinary cases; add coverage for out-of-range finite values after deciding whether to reject or clamp.
  • Observability/performance: no additional observability needed; no hot-path performance concern found.

User focus: no additional user-provided review focus was specified.

Comment thread be/src/exprs/function/function_utility.cpp
@prakash-atul prakash-atul force-pushed the feature/human_readable_seconds branch from f855a59 to 1c0b720 Compare June 1, 2026 05:03
@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 91.18% (62/68) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 54.06% (21045/38927)
Line Coverage 37.60% (199437/530408)
Region Coverage 33.87% (156178/461097)
Branch Coverage 34.86% (67958/194954)

@zclllyybb
Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 72.73% (32/44) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 91.89% (68/74) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 54.09% (21059/38935)
Line Coverage 37.64% (199698/530490)
Region Coverage 33.87% (156191/461123)
Branch Coverage 34.85% (67938/194958)

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.89% (68/74) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.90% (28171/38119)
Line Coverage 57.88% (306188/529037)
Region Coverage 54.75% (254873/465515)
Branch Coverage 56.40% (110365/195682)

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 6.86% (36/525) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29417 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 1c0b72056098e7b775fec80cb87d12cb8db88f57, 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	17732	4123	4072	4072
q2	q3	10782	1423	814	814
q4	4683	469	341	341
q5	7571	874	584	584
q6	182	172	137	137
q7	775	832	647	647
q8	9396	1631	1649	1631
q9	5713	4512	4432	4432
q10	6765	1785	1528	1528
q11	431	274	260	260
q12	637	427	294	294
q13	18137	3273	2818	2818
q14	280	248	239	239
q15	q16	822	773	707	707
q17	1000	998	947	947
q18	7072	5647	5609	5609
q19	1334	1279	1099	1099
q20	539	402	260	260
q21	6128	2841	2688	2688
q22	470	384	310	310
Total cold run time: 100449 ms
Total hot run time: 29417 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	5088	4861	4727	4727
q2	q3	4798	5370	4741	4741
q4	2060	2175	1380	1380
q5	4785	4909	4767	4767
q6	228	175	129	129
q7	1924	1800	1631	1631
q8	2409	2129	2235	2129
q9	8000	7916	7382	7382
q10	4714	4663	4250	4250
q11	527	402	383	383
q12	719	735	519	519
q13	3000	3382	2810	2810
q14	269	278	246	246
q15	q16	674	696	603	603
q17	1290	1264	1256	1256
q18	7176	6902	7022	6902
q19	1117	1113	1144	1113
q20	2209	2211	1943	1943
q21	5316	4562	4517	4517
q22	521	473	399	399
Total cold run time: 56824 ms
Total hot run time: 51827 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 170743 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 1c0b72056098e7b775fec80cb87d12cb8db88f57, data reload: false

query5	4335	637	522	522
query6	337	218	199	199
query7	4245	541	320	320
query8	341	241	226	226
query9	8793	4003	4028	4003
query10	449	348	298	298
query11	5765	2346	2202	2202
query12	187	135	129	129
query13	1285	633	457	457
query14	6121	5424	5120	5120
query14_1	4442	4402	4393	4393
query15	212	204	182	182
query16	993	451	427	427
query17	995	721	594	594
query18	2511	472	373	373
query19	219	205	173	173
query20	146	136	152	136
query21	215	139	117	117
query22	13707	13562	13447	13447
query23	17522	16513	16179	16179
query23_1	16298	16420	16263	16263
query24	7403	1760	1331	1331
query24_1	1326	1308	1313	1308
query25	589	536	464	464
query26	1308	316	180	180
query27	2713	559	350	350
query28	4450	2090	2045	2045
query29	999	663	536	536
query30	311	225	204	204
query31	1149	1073	948	948
query32	98	83	81	81
query33	559	366	305	305
query34	1207	1152	664	664
query35	788	798	706	706
query36	1381	1417	1270	1270
query37	161	113	96	96
query38	3217	3175	3055	3055
query39	924	919	936	919
query39_1	885	871	862	862
query40	244	159	136	136
query41	72	69	68	68
query42	119	114	119	114
query43	327	329	283	283
query44	
query45	215	207	202	202
query46	1074	1184	729	729
query47	2437	2409	2279	2279
query48	417	414	299	299
query49	656	505	406	406
query50	983	372	261	261
query51	4335	4318	4330	4318
query52	112	119	98	98
query53	265	289	209	209
query54	349	282	275	275
query55	99	94	87	87
query56	329	321	334	321
query57	1441	1432	1340	1340
query58	318	291	268	268
query59	1604	1653	1465	1465
query60	348	339	356	339
query61	153	162	158	158
query62	710	656	584	584
query63	252	207	205	205
query64	2426	812	650	650
query65	
query66	1741	480	355	355
query67	29780	29691	29540	29540
query68	
query69	465	337	290	290
query70	1069	1046	1035	1035
query71	315	269	278	269
query72	2970	2689	2463	2463
query73	862	806	429	429
query74	5133	4952	4753	4753
query75	2713	2588	2271	2271
query76	2293	1129	802	802
query77	404	418	323	323
query78	12249	12660	11837	11837
query79	1523	1093	750	750
query80	650	534	468	468
query81	478	277	244	244
query82	1401	155	121	121
query83	356	278	254	254
query84	302	140	113	113
query85	885	547	457	457
query86	410	312	314	312
query87	3401	3388	3216	3216
query88	3588	2728	2737	2728
query89	471	389	348	348
query90	2012	185	178	178
query91	179	165	144	144
query92	79	79	74	74
query93	1482	1451	870	870
query94	545	353	306	306
query95	696	489	350	350
query96	1074	799	375	375
query97	2743	2725	2617	2617
query98	243	242	233	233
query99	1162	1175	1041	1041
Total cold run time: 254379 ms
Total hot run time: 170743 ms

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.

3 participants