Skip to content

[feature](function) Support Hive-compatible encode and decode - #68131

Open
hacklu-tu wants to merge 8 commits into
apache:masterfrom
hacklu-tu:feature/hive-encode-decode
Open

hacklu-tu wants to merge 8 commits into
apache:masterfrom
hacklu-tu:feature/hive-encode-decode

Conversation

@hacklu-tu

@hacklu-tu hacklu-tu commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: #48203

Related PR: apache/doris-website#4151

Problem Summary:

Doris does not provide Hive-compatible encode(string, charset) and decode(binary, charset) scalar functions, which makes Hive workload migration harder.

This PR:

  • adds Nereids signatures and constant folding for encode and decode;
  • adds vectorized BE implementations backed by ICU with strict malformed and unmappable input handling;
  • supports the six character sets documented by Hive: US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, and UTF-16, matched case-insensitively;
  • follows Java/Hive UTF-16 BOM behavior and propagates nulls;
  • adds FE/BE unit tests and SQL regression coverage for supported conversions and error cases.

Release note

Add Hive-compatible encode and decode scalar functions for US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, and UTF-16.

Check List (For Author)

  • Test

    • Regression test
      • test_encode_decode passed in generated-output and comparison modes on a native Linux Doris cluster.
    • Unit Test
      • BE function_character_encoding_test.*: 3 tests passed.
      • FE StringArithmeticTest: 10 tests passed; Maven reactor succeeded.
      • Native Linux FE/BE build succeeded.
    • 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. Adds Hive-compatible encode and decode functions, including UTF-16 BOM semantics, null propagation, and strict conversion errors.
  • 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

### What problem does this PR solve?

Issue Number: apache#48203

Related PR: None

Problem Summary: Doris lacks Hive-compatible encode(string, charset) and decode(binary, charset) scalar functions. Add FE signatures and constant folding, BE vectorized ICU conversion with strict malformed and unmappable input handling, case-insensitive support for the six Hive-documented character sets, Java-compatible UTF-16 BOM behavior, null propagation, and focused tests.

### Release note

Add Hive-compatible encode and decode scalar functions for US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, and UTF-16.

### Check List (For Author)

- Test: Unit and regression tests
    - BE function_character_encoding_test.*: 3 tests passed.
    - FE StringArithmeticTest: 10 tests passed; Maven reactor succeeded.
    - Native Linux FE/BE build succeeded.
    - test_encode_decode regression suite passed in generated-output and comparison modes.
- Behavior changed: Yes. Add encode and decode with Hive-compatible types, supported character sets, UTF-16 BOM semantics, null propagation, and strict conversion errors.
- Does this need documentation: Yes. A follow-up doris-website PR is required.
### What problem does this PR solve?

Add positive regression coverage for Hive-compatible encode and decode across supported character sets, BOM handling, empty strings, and null propagation.

### How does this PR solve the problem?

Exercise table-driven encode/decode queries and record runner-generated expected output while retaining the existing invalid-conversion checks.

### Check List

- [x] Regression test
- [x] FE unit test
- [x] BE unit test
@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?

…lict

### What problem does this PR solve?

Related PR: apache#68131

Problem Summary: CI stopped before compilation because master URL tests and encode/decode helpers conflicted in StringArithmeticTest. Merge master and preserve both test groups.

### Release note

None

### Check List (For Author)

- Test: run-fe-ut.sh --run org.apache.doris.nereids.trees.expressions.functions.executable.StringArithmeticTest (12 tests passed)
- Behavior changed: No
- Does this need documentation: No
@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17758	3872	3886	3872
q2	2302	362	303	303
q3	10016	1467	812	812
q4	4693	476	354	354
q5	7486	825	558	558
q6	182	168	136	136
q7	734	797	584	584
q8	9371	1587	1497	1497
q9	5458	4235	4215	4215
q10	6748	1600	1346	1346
q11	437	276	241	241
q12	631	419	294	294
q13	18092	2658	2022	2022
q14	266	265	233	233
q15	q16	736	716	659	659
q17	1726	1171	987	987
q18	6639	5622	5566	5566
q19	1187	1271	956	956
q20	482	417	268	268
q21	5693	3088	2738	2738
q22	456	381	320	320
Total cold run time: 101093 ms
Total hot run time: 27961 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4590	4667	4538	4538
q2	811	619	547	547
q3	4927	5110	4747	4747
q4	2306	2330	1478	1478
q5	4617	4414	4653	4414
q6	222	171	124	124
q7	1807	1713	1445	1445
q8	2332	2062	2023	2023
q9	7312	7293	7200	7200
q10	4292	4213	3832	3832
q11	517	367	342	342
q12	700	717	504	504
q13	2286	2634	2012	2012
q14	263	275	244	244
q15	q16	673	681	625	625
q17	7317	6650	6662	6650
q18	11886	11037	11793	11037
q19	1081	1007	1015	1007
q20	2198	2163	1930	1930
q21	5399	4467	4618	4467
q22	522	457	430	430
Total cold run time: 66058 ms
Total hot run time: 59596 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 153039 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 6e11697f36c907ec50ba9abfdc38ca6747952deb, data reload: false

query5	4329	627	468	468
query6	446	181	170	170
query7	4820	538	285	285
query8	328	175	164	164
query9	8798	3994	3991	3991
query10	455	307	255	255
query11	5744	2172	2000	2000
query12	160	96	101	96
query13	1247	583	423	423
query14	6540	4577	4250	4250
query14_1	4030	3980	3963	3963
query15	210	213	185	185
query16	998	492	449	449
query17	935	746	515	515
query18	2411	457	327	327
query19	205	172	132	132
query20	103	96	100	96
query21	216	137	112	112
query22	13059	13081	12791	12791
query23	15702	14588	13942	13942
query23_1	14008	14155	14046	14046
query24	7481	1748	1234	1234
query24_1	1279	1243	1245	1243
query25	523	406	348	348
query26	1262	308	163	163
query27	2715	570	335	335
query28	4555	1985	1919	1919
query29	1071	592	461	461
query30	330	247	211	211
query31	914	838	622	622
query32	169	89	93	89
query33	496	311	235	235
query34	1220	1136	638	638
query35	738	763	631	631
query36	804	786	703	703
query37	159	111	91	91
query38	1847	1774	1681	1681
query39	696	697	667	667
query39_1	662	650	680	650
query40	222	121	100	100
query41	66	64	67	64
query42	97	93	92	92
query43	345	350	301	301
query44	1432	727	679	679
query45	190	179	168	168
query46	1062	1163	699	699
query47	1484	1524	1384	1384
query48	409	425	285	285
query49	578	418	287	287
query50	1014	361	247	247
query51	10574	10197	10404	10197
query52	87	92	73	73
query53	238	259	175	175
query54	267	207	195	195
query55	82	78	68	68
query56	232	232	220	220
query57	1393	1413	1393	1393
query58	250	198	205	198
query59	2006	2065	1790	1790
query60	281	246	217	217
query61	141	147	142	142
query62	412	324	266	266
query63	219	173	177	173
query64	2843	996	840	840
query65	4008	3965	3934	3934
query66	1818	449	305	305
query67	20151	20122	19739	19739
query68	3243	1437	937	937
query69	407	319	271	271
query70	994	899	872	872
query71	291	243	207	207
query72	2927	2553	2195	2195
query73	837	739	414	414
query74	4646	4486	4307	4307
query75	2414	2331	1931	1931
query76	2348	1150	709	709
query77	373	415	288	288
query78	9028	9010	8487	8487
query79	1205	1119	741	741
query80	516	476	343	343
query81	469	298	240	240
query82	274	166	122	122
query83	268	272	242	242
query84	292	139	108	108
query85	779	469	375	375
query86	286	242	240	240
query87	1982	1977	1812	1812
query88	3704	2741	2727	2727
query89	334	295	246	246
query90	2131	188	179	179
query91	174	149	126	126
query92	102	89	88	88
query93	1471	1480	833	833
query94	505	342	306	306
query95	692	455	349	349
query96	1031	767	356	356
query97	2456	2447	2297	2297
query98	209	185	188	185
query99	743	741	631	631
Total cold run time: 241008 ms
Total hot run time: 153039 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.12 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 6e11697f36c907ec50ba9abfdc38ca6747952deb, data reload: false

query1	0.01	0.00	0.01
query2	0.10	0.06	0.05
query3	0.26	0.13	0.13
query4	1.61	0.14	0.14
query5	0.24	0.21	0.21
query6	1.17	0.96	0.96
query7	0.04	0.01	0.00
query8	0.05	0.03	0.04
query9	0.39	0.34	0.35
query10	0.60	0.54	0.57
query11	0.20	0.14	0.14
query12	0.18	0.15	0.15
query13	0.47	0.47	0.48
query14	0.96	0.95	0.95
query15	0.61	0.60	0.58
query16	0.30	0.32	0.31
query17	1.06	1.07	1.10
query18	0.22	0.21	0.20
query19	2.00	1.96	1.96
query20	0.02	0.02	0.01
query21	15.47	0.22	0.13
query22	4.86	0.06	0.06
query23	16.08	0.31	0.12
query24	3.00	0.44	0.34
query25	0.11	0.05	0.05
query26	0.74	0.21	0.14
query27	0.04	0.04	0.05
query28	3.51	0.78	0.36
query29	12.48	4.02	3.21
query30	0.28	0.14	0.14
query31	2.79	0.56	0.31
query32	3.22	0.58	0.49
query33	3.15	3.19	3.15
query34	15.55	3.94	3.29
query35	3.25	3.27	3.26
query36	0.56	0.45	0.42
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.16	0.15
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.09 s
Total hot run time: 24.12 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.52% (29586/46578)
Line Coverage 48.25% (308144/638703)
Region Coverage 43.83% (248610/567243)
Branch Coverage 45.39% (115598/254669)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.25% (34392/45106)
Line Coverage 61.16% (386165/631431)
Region Coverage 57.58% (325317/564970)
Branch Coverage 58.33% (148095/253880)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 75.44% (43/57) 🎉
Increment coverage report
Complete coverage report

### What problem does this PR solve?

Issue Number: apache#48203

Related PR: apache#68131

Problem Summary: The FE incremental coverage gate reported 75.44% because the encode and decode scalar expression contracts were not exercised. Add focused unit tests for signatures, child rewriting, argument validation, and scalar visitor delegation.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.trees.expressions.functions.scalar.EncodeDecodeTest (3 tests passed)
    - ./run-fe-ut.sh --coverage --run org.apache.doris.nereids.trees.expressions.functions.scalar.EncodeDecodeTest (3 tests passed; affected lines fully covered)
- Behavior changed: No
- Does this need documentation: No
@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17890	3924	3837	3837
q2	2274	343	288	288
q3	9995	1423	772	772
q4	4679	472	364	364
q5	7453	824	557	557
q6	176	178	134	134
q7	709	798	588	588
q8	9338	1624	1540	1540
q9	5383	4224	4179	4179
q10	6727	1617	1335	1335
q11	426	271	247	247
q12	627	410	290	290
q13	18072	2636	2007	2007
q14	256	257	232	232
q15	q16	728	714	669	669
q17	1777	1107	1017	1017
q18	6519	5614	5588	5588
q19	1167	1205	1047	1047
q20	477	382	258	258
q21	5558	2546	2368	2368
q22	436	338	303	303
Total cold run time: 100667 ms
Total hot run time: 27620 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4136	4029	4045	4029
q2	738	574	547	547
q3	4528	4928	4379	4379
q4	2231	2305	1460	1460
q5	4243	4072	4091	4072
q6	227	170	126	126
q7	1718	1623	1453	1453
q8	2161	2261	2100	2100
q9	7518	7304	7292	7292
q10	4273	4267	3831	3831
q11	567	402	371	371
q12	738	723	535	535
q13	2466	2840	2161	2161
q14	288	315	282	282
q15	q16	737	717	618	618
q17	7945	7229	7195	7195
q18	11872	11020	11820	11020
q19	1164	1064	1086	1064
q20	2264	2237	1933	1933
q21	5791	4963	4859	4859
q22	521	458	411	411
Total cold run time: 66126 ms
Total hot run time: 59738 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 153063 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 7a9f82b620e68885d50a0ba7410ee2a53a4643fb, data reload: false

query5	4336	588	460	460
query6	455	181	170	170
query7	4796	548	288	288
query8	313	176	165	165
query9	8802	3939	3951	3939
query10	469	304	261	261
query11	5908	2176	1973	1973
query12	153	105	95	95
query13	1280	571	421	421
query14	6541	4565	4178	4178
query14_1	4006	3999	3996	3996
query15	205	196	189	189
query16	965	487	445	445
query17	914	691	541	541
query18	2422	478	338	338
query19	197	184	140	140
query20	104	105	104	104
query21	219	138	115	115
query22	13067	12940	12900	12900
query23	15439	14541	14116	14116
query23_1	14086	14114	14001	14001
query24	7440	1680	1241	1241
query24_1	1253	1215	1214	1214
query25	535	435	368	368
query26	1253	309	165	165
query27	2683	556	332	332
query28	4584	1932	1951	1932
query29	1073	590	457	457
query30	332	246	200	200
query31	890	766	629	629
query32	151	96	95	95
query33	526	327	248	248
query34	1220	1107	620	620
query35	729	767	640	640
query36	799	774	730	730
query37	148	103	88	88
query38	1836	1766	1692	1692
query39	712	705	660	660
query39_1	650	657	644	644
query40	220	124	102	102
query41	74	67	67	67
query42	92	91	89	89
query43	337	342	301	301
query44	1340	687	681	681
query45	186	181	174	174
query46	1098	1143	744	744
query47	1500	1482	1376	1376
query48	381	409	278	278
query49	607	408	298	298
query50	947	341	248	248
query51	10371	10441	10253	10253
query52	83	83	71	71
query53	229	241	173	173
query54	236	194	178	178
query55	81	72	77	72
query56	236	223	211	211
query57	1516	1372	1428	1372
query58	232	206	206	206
query59	1990	2075	1829	1829
query60	273	238	227	227
query61	138	137	137	137
query62	397	318	257	257
query63	218	168	165	165
query64	2850	958	823	823
query65	4036	3911	3949	3911
query66	1800	414	328	328
query67	20090	20104	19689	19689
query68	3259	1482	862	862
query69	412	294	252	252
query70	962	913	880	880
query71	295	217	213	213
query72	2910	2482	2100	2100
query73	836	766	418	418
query74	4649	4485	4266	4266
query75	2295	2273	1929	1929
query76	2331	1081	699	699
query77	346	378	318	318
query78	9296	9017	8380	8380
query79	1369	1247	762	762
query80	749	462	350	350
query81	488	282	241	241
query82	617	168	120	120
query83	339	273	235	235
query84	316	142	108	108
query85	951	449	375	375
query86	371	239	232	232
query87	1985	1969	1842	1842
query88	3603	2687	2710	2687
query89	358	284	245	245
query90	1715	179	178	178
query91	164	149	121	121
query92	100	87	86	86
query93	1525	1456	866	866
query94	591	330	324	324
query95	656	364	408	364
query96	995	797	337	337
query97	2454	2433	2328	2328
query98	204	191	185	185
query99	744	714	613	613
Total cold run time: 241114 ms
Total hot run time: 153063 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 23.9 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 7a9f82b620e68885d50a0ba7410ee2a53a4643fb, data reload: false

query1	0.00	0.00	0.00
query2	0.10	0.05	0.05
query3	0.25	0.14	0.13
query4	1.61	0.14	0.13
query5	0.24	0.22	0.22
query6	1.16	0.93	0.93
query7	0.04	0.00	0.01
query8	0.05	0.04	0.04
query9	0.40	0.33	0.33
query10	0.54	0.54	0.55
query11	0.20	0.15	0.13
query12	0.19	0.15	0.15
query13	0.48	0.47	0.47
query14	0.94	0.95	0.93
query15	0.61	0.59	0.58
query16	0.31	0.32	0.33
query17	1.10	1.08	1.05
query18	0.22	0.19	0.20
query19	2.05	1.87	1.88
query20	0.02	0.01	0.01
query21	15.42	0.22	0.13
query22	4.88	0.05	0.05
query23	16.16	0.30	0.12
query24	2.97	0.45	0.34
query25	0.10	0.06	0.05
query26	0.75	0.22	0.15
query27	0.04	0.04	0.03
query28	3.59	0.80	0.36
query29	12.59	4.05	3.20
query30	0.27	0.15	0.15
query31	2.76	0.57	0.31
query32	3.22	0.60	0.49
query33	3.23	3.17	3.14
query34	15.72	3.90	3.30
query35	3.25	3.25	3.25
query36	0.55	0.40	0.43
query37	0.09	0.06	0.06
query38	0.05	0.04	0.04
query39	0.05	0.03	0.04
query40	0.18	0.15	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.55 s
Total hot run time: 23.9 s

@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run cloud_p0

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.25% (34367/45070)
Line Coverage 61.13% (385636/630820)
Region Coverage 57.53% (324667/564302)
Branch Coverage 58.35% (147937/253548)

@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run check_coverage

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.25% (34367/45070)
Line Coverage 61.13% (385636/630820)
Region Coverage 57.53% (324667/564302)
Branch Coverage 58.35% (147937/253548)

@hacklu-tu

Copy link
Copy Markdown
Contributor Author

/review

1 similar comment
@linrrzqqq

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Static-only review of exact head 7a9f82b620e68885d50a0ba7410ee2a53a4643fb against base e85575e3ad60389259dfe267a90124e6299a230a. I found two correctness inconsistencies; the exact failure paths and requested coverage are in the inline comments.

Checkpoint conclusions:

  • Goal, approach, and tests: the six advertised charsets, strict conversion errors, UTF-16 BOM behavior, and NULL propagation are implemented and broadly tested, but the two retained invariance cases are uncovered.
  • Scope control: all 12 authoritative changed files plus registration, constant execution, literal serialization, column ownership, source discovery, and test discovery call chains were covered.
  • Concurrency: converter and scratch state are execution-local; no shared mutable state or lock-order issue is introduced.
  • Lifecycle and static initialization: ICU resources are RAII-owned and reset safely; no static-initialization hazard was found.
  • Configuration: no configuration surface is added or changed.
  • Compatibility: no persisted or wire format changes are introduced; old BEs cannot execute the new function names until upgraded, which is the ordinary limitation for a new scalar function.
  • Parallel paths: FE folding and BE runtime types/names agree, except for the retained charset-name normalization mismatch.
  • Null, const, and type safety: result ownership and checked shapes are sound, except for the retained constant-charset validation ordering.
  • Test coverage and result correctness: BE, FE, and ordered regression oracles are sound for covered cases; tests do not compare NULL plus an invalid constant charset or Unicode-folded literal names with runtime column names.
  • Observability: no new long-lived service or state transition needs metrics/logging.
  • Persistence and replay: not applicable; no durable state is changed.
  • Data writes: only scalar result columns are produced, and their storage owns the copied bytes.
  • FE/BE contract: signatures, nullability, physical return types, visitor dispatch, and serialization agree apart from the inline normalization issue.
  • Performance and memory: the implementation is linear and task-thread allocations are accounted; repeated converter setup and the no-op varbinary reserve were reviewed but lacked evidence of a material regression.
  • Other issues: none survived adjudication or the second convergence round.

Validation status: no local build or test was run, as required by the review task. Author and CI reports were treated as external claims, not independent validation. At submission time GitHub reports successful compile, BE UT, FE UT, P0, cloud, and performance checks, while check_coverage_fe is failing and the automated code-review check remains pending. No additional review focus was supplied.

ConverterCache converters;
std::string converted;
CharacterSet constant_character_set = CharacterSet::UTF_8;
if (character_set_is_const && input_rows_count != 0 &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve NULL propagation before validating a constant charset

This parse runs before the row loop, so a nullable source column containing NULL plus a constant unsupported charset (for example, GBK) fails here. The same logical row with the charset supplied by a nonconstant column reaches the NULL branch first and returns NULL, making results depend on the physical const/vector shape. Please validate and cache the constant charset only when the first non-NULL row needs it, and cover this case for both functions.


private static Charset supportedCharacterSet(String name) {
String canonicalName;
switch (name.toUpperCase(Locale.ROOT)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Use identical charset-name folding in FE and BE

Locale.ROOT uppercasing applies Unicode mappings: Uſ-ASCII (U+017F long s) becomes US-ASCII, so a literal can fold successfully here. BE only uppercases ASCII bytes and rejects the identical value when it comes from a column, so constant folding changes query behavior. Please use the same ASCII-only validation on both sides (or otherwise share exactly the same normalization) and add a literal-versus-runtime regression case.

### What problem does this PR solve?

Issue Number: close apache#48203

Related PR: apache#68131

Problem Summary: FE constant folding normalized character set names with Unicode uppercasing, while BE only performs ASCII case-insensitive matching. This allowed names such as Uſ-ASCII to fold successfully in FE but fail when supplied through a runtime column. Match supported names with ASCII-only comparison and add literal-versus-runtime regression coverage.

### Release note

Fix inconsistent character set validation between FE constant folding and BE runtime execution for encode and decode.

### Check List (For Author)

- Test: Unit Test / Regression test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.trees.expressions.functions.executable.StringArithmeticTest (13 tests passed)
    - Added regression coverage for literal and runtime character set arguments; not run locally because it requires a Linux Doris cluster
- Behavior changed: Yes. Non-ASCII names that only become supported through Unicode case conversion are now rejected consistently.
- Does this need documentation: No
@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run buildall

### What problem does this PR solve?

Issue Number: apache#48203

Related PR: apache#68131

Problem Summary: The clean TeamCity compile build rejects the U+017F test literal because its Unicode escape lacks the trailing code point explanation required by FE Checkstyle. Define the charset once with a trailing U+017F comment and reuse it for encode and decode.

### Release note

None

### Check List (For Author)

- Test: Unit Test
  - mvn -pl fe-core -DskipTests -Dcheckstyle.cache.file=/tmp/doris-checkstyle-green-cache-68131 checkstyle:check (passed)
  - ./run-fe-ut.sh --run org.apache.doris.nereids.trees.expressions.functions.executable.StringArithmeticTest (13 tests passed)
- Behavior changed: No
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.57% (29587/46545)
Line Coverage 48.31% (308270/638139)
Region Coverage 43.92% (248826/566605)
Branch Coverage 45.45% (115608/254354)

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17626	3850	3860	3850
q2	2271	352	298	298
q3	10002	1392	788	788
q4	4680	472	342	342
q5	7565	830	545	545
q6	182	178	137	137
q7	737	777	581	581
q8	9298	1751	1529	1529
q9	5361	4199	4166	4166
q10	6633	1606	1355	1355
q11	431	277	254	254
q12	641	416	289	289
q13	18087	2615	1984	1984
q14	276	254	241	241
q15	q16	725	714	653	653
q17	1840	1196	1050	1050
q18	6440	5582	5537	5537
q19	1184	1248	1011	1011
q20	505	401	274	274
q21	5607	2583	2399	2399
q22	421	350	305	305
Total cold run time: 100512 ms
Total hot run time: 27588 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4199	4030	4081	4030
q2	752	586	583	583
q3	4533	4917	4396	4396
q4	2202	2295	1413	1413
q5	4176	4063	4087	4063
q6	221	171	127	127
q7	1674	1660	1439	1439
q8	2141	2313	2107	2107
q9	7431	7302	7439	7302
q10	4257	4270	3867	3867
q11	568	400	396	396
q12	734	754	517	517
q13	2442	2770	2149	2149
q14	274	296	283	283
q15	q16	684	726	629	629
q17	7867	7390	7047	7047
q18	11869	11085	11892	11085
q19	1181	1083	1102	1083
q20	2248	2226	1941	1941
q21	5814	4896	4762	4762
q22	517	459	414	414
Total cold run time: 65784 ms
Total hot run time: 59633 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 153699 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 3196b6e3906fb5c3d6b59c09e008af76997b20df, data reload: false

query5	4312	593	464	464
query6	429	183	177	177
query7	4961	530	279	279
query8	311	176	168	168
query9	8748	3904	3963	3904
query10	452	305	259	259
query11	5871	2170	2015	2015
query12	150	99	96	96
query13	1250	563	419	419
query14	6536	4551	4261	4261
query14_1	4051	3977	3931	3931
query15	209	211	178	178
query16	972	472	428	428
query17	914	670	547	547
query18	2437	461	337	337
query19	202	184	136	136
query20	104	107	107	107
query21	219	142	120	120
query22	13104	13024	12880	12880
query23	15370	14627	14092	14092
query23_1	14008	14019	14055	14019
query24	7529	1705	1237	1237
query24_1	1224	1241	1224	1224
query25	558	427	363	363
query26	1259	333	162	162
query27	2662	539	344	344
query28	4560	1947	1935	1935
query29	1047	625	474	474
query30	310	246	221	221
query31	884	767	625	625
query32	148	102	94	94
query33	521	317	254	254
query34	1215	1133	611	611
query35	740	786	645	645
query36	819	808	723	723
query37	152	109	90	90
query38	1826	1783	1690	1690
query39	676	714	656	656
query39_1	661	654	651	651
query40	224	125	105	105
query41	73	68	68	68
query42	97	89	90	89
query43	352	344	303	303
query44	1399	699	693	693
query45	184	173	174	173
query46	1022	1156	706	706
query47	1512	1520	1405	1405
query48	403	430	282	282
query49	594	411	294	294
query50	977	349	250	250
query51	10243	10466	10365	10365
query52	84	83	80	80
query53	241	263	178	178
query54	269	218	187	187
query55	74	72	71	71
query56	242	225	201	201
query57	1446	1328	1249	1249
query58	232	207	203	203
query59	1973	2072	1811	1811
query60	272	263	214	214
query61	159	140	148	140
query62	390	318	265	265
query63	218	176	171	171
query64	2842	982	806	806
query65	4049	3967	3930	3930
query66	1831	421	297	297
query67	20013	20895	19891	19891
query68	3096	1541	872	872
query69	420	315	265	265
query70	961	900	859	859
query71	283	236	220	220
query72	2890	2439	2132	2132
query73	794	878	438	438
query74	4644	4530	4276	4276
query75	2303	2286	1948	1948
query76	2329	1124	739	739
query77	367	397	307	307
query78	8980	9116	8514	8514
query79	1338	1238	780	780
query80	552	450	372	372
query81	490	278	238	238
query82	654	160	124	124
query83	356	275	247	247
query84	316	138	110	110
query85	864	448	373	373
query86	333	238	233	233
query87	2000	1977	1840	1840
query88	3629	2745	2717	2717
query89	375	283	244	244
query90	1880	180	176	176
query91	163	153	124	124
query92	100	85	89	85
query93	1489	1486	911	911
query94	531	330	310	310
query95	659	348	414	348
query96	1027	798	357	357
query97	2482	2431	2305	2305
query98	201	187	185	185
query99	724	713	610	610
Total cold run time: 241004 ms
Total hot run time: 153699 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 23.94 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 3196b6e3906fb5c3d6b59c09e008af76997b20df, data reload: false

query1	0.00	0.00	0.01
query2	0.09	0.04	0.05
query3	0.25	0.14	0.14
query4	1.60	0.14	0.14
query5	0.25	0.23	0.22
query6	1.16	0.94	0.93
query7	0.03	0.01	0.00
query8	0.05	0.03	0.03
query9	0.39	0.33	0.34
query10	0.57	0.56	0.55
query11	0.19	0.14	0.14
query12	0.18	0.16	0.16
query13	0.47	0.47	0.46
query14	0.95	0.93	0.94
query15	0.60	0.57	0.57
query16	0.32	0.32	0.30
query17	1.08	1.11	1.04
query18	0.22	0.20	0.20
query19	1.98	1.90	1.95
query20	0.02	0.01	0.01
query21	15.43	0.21	0.13
query22	4.94	0.05	0.05
query23	16.15	0.32	0.12
query24	2.93	0.42	0.32
query25	0.13	0.05	0.03
query26	0.74	0.20	0.14
query27	0.04	0.04	0.04
query28	3.58	0.75	0.35
query29	12.53	4.07	3.20
query30	0.28	0.16	0.15
query31	2.77	0.60	0.31
query32	3.23	0.59	0.49
query33	3.11	3.26	3.24
query34	15.72	3.97	3.31
query35	3.21	3.19	3.25
query36	0.55	0.44	0.43
query37	0.09	0.06	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.04
query40	0.18	0.15	0.14
query41	0.09	0.03	0.03
query42	0.04	0.04	0.03
query43	0.05	0.04	0.03
Total cold run time: 96.28 s
Total hot run time: 23.94 s

@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17645	4003	4044	4003
q2	2263	358	309	309
q3	10046	1383	786	786
q4	4682	467	365	365
q5	7453	847	557	557
q6	181	170	134	134
q7	732	790	587	587
q8	9309	1604	1422	1422
q9	5382	4151	4151	4151
q10	6756	1646	1339	1339
q11	446	277	247	247
q12	651	423	309	309
q13	18056	2636	2001	2001
q14	266	253	244	244
q15	q16	738	719	655	655
q17	1754	1132	1038	1038
q18	6549	5616	5565	5565
q19	1175	1203	1025	1025
q20	501	395	267	267
q21	5385	2503	2344	2344
q22	413	359	294	294
Total cold run time: 100383 ms
Total hot run time: 27642 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4307	4205	4173	4173
q2	757	616	545	545
q3	4512	4891	4356	4356
q4	2253	2307	1464	1464
q5	4260	4101	4129	4101
q6	225	169	125	125
q7	1674	1608	1434	1434
q8	2152	2425	1993	1993
q9	7521	7303	7327	7303
q10	4308	4298	3916	3916
q11	575	440	381	381
q12	715	743	527	527
q13	2489	2849	2221	2221
q14	293	290	262	262
q15	q16	694	709	644	644
q17	7966	7236	7148	7148
q18	11916	11097	11936	11097
q19	1165	1094	1106	1094
q20	2267	2243	1949	1949
q21	5761	4873	4720	4720
q22	534	453	443	443
Total cold run time: 66344 ms
Total hot run time: 59896 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 153391 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 c980c3094ad272bd3944ead39f8769a1d8ce662b, data reload: false

query5	4323	603	464	464
query6	437	182	162	162
query7	4828	532	281	281
query8	325	176	158	158
query9	8780	3994	3996	3994
query10	440	322	256	256
query11	5803	2184	2031	2031
query12	159	98	98	98
query13	1260	583	374	374
query14	6508	4552	4247	4247
query14_1	4005	4003	3997	3997
query15	204	207	177	177
query16	984	425	458	425
query17	914	680	529	529
query18	2435	454	334	334
query19	204	180	141	141
query20	110	102	108	102
query21	218	136	120	120
query22	13044	13070	12931	12931
query23	15604	14710	14057	14057
query23_1	14113	14094	14047	14047
query24	7490	1698	1232	1232
query24_1	1259	1243	1215	1215
query25	530	426	359	359
query26	1115	316	173	173
query27	2666	569	338	338
query28	4570	1969	1989	1969
query29	1047	590	469	469
query30	323	243	203	203
query31	885	760	632	632
query32	141	101	99	99
query33	515	329	254	254
query34	1178	1116	622	622
query35	720	759	667	667
query36	815	792	730	730
query37	153	108	95	95
query38	1854	1761	1704	1704
query39	697	693	646	646
query39_1	638	655	648	648
query40	224	127	102	102
query41	72	68	69	68
query42	94	100	93	93
query43	337	357	302	302
query44	1347	690	696	690
query45	191	185	172	172
query46	1022	1186	706	706
query47	1485	1517	1388	1388
query48	373	412	299	299
query49	595	406	306	306
query50	965	337	259	259
query51	10535	10233	10337	10233
query52	85	85	83	83
query53	243	295	175	175
query54	259	221	179	179
query55	75	74	73	73
query56	232	224	205	205
query57	1539	1376	1408	1376
query58	225	207	202	202
query59	1998	2057	1805	1805
query60	274	240	230	230
query61	143	143	140	140
query62	400	324	267	267
query63	213	178	175	175
query64	2636	990	849	849
query65	4055	3960	3909	3909
query66	1764	422	300	300
query67	20263	20143	19975	19975
query68	3044	1570	876	876
query69	406	302	268	268
query70	963	905	885	885
query71	296	238	211	211
query72	2840	2452	2113	2113
query73	810	713	415	415
query74	4651	4494	4304	4304
query75	2303	2270	1920	1920
query76	2321	1090	716	716
query77	344	400	299	299
query78	9030	9069	8452	8452
query79	1357	1211	704	704
query80	570	441	361	361
query81	463	282	239	239
query82	626	156	130	130
query83	349	268	246	246
query84	318	138	113	113
query85	823	439	368	368
query86	329	240	214	214
query87	1985	1967	1815	1815
query88	3620	2746	2724	2724
query89	362	285	244	244
query90	1940	175	183	175
query91	166	152	126	126
query92	100	87	87	87
query93	1462	1450	829	829
query94	539	333	260	260
query95	662	363	330	330
query96	1046	772	348	348
query97	2441	2431	2309	2309
query98	197	192	183	183
query99	741	700	608	608
Total cold run time: 240031 ms
Total hot run time: 153391 ms

@hello-stephen

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

query1	0.00	0.00	0.01
query2	0.09	0.05	0.05
query3	0.25	0.14	0.13
query4	1.61	0.14	0.15
query5	0.25	0.22	0.21
query6	1.15	0.94	0.91
query7	0.04	0.00	0.01
query8	0.05	0.04	0.03
query9	0.40	0.35	0.35
query10	0.54	0.55	0.55
query11	0.20	0.14	0.14
query12	0.18	0.14	0.14
query13	0.47	0.47	0.45
query14	0.94	0.96	0.94
query15	0.61	0.58	0.59
query16	0.31	0.34	0.34
query17	1.10	1.11	1.07
query18	0.22	0.19	0.20
query19	2.05	2.01	1.91
query20	0.02	0.01	0.01
query21	15.46	0.22	0.13
query22	4.75	0.05	0.06
query23	16.17	0.30	0.12
query24	3.00	0.41	0.34
query25	0.12	0.05	0.04
query26	0.75	0.20	0.14
query27	0.04	0.05	0.04
query28	3.54	0.81	0.36
query29	12.48	4.02	3.20
query30	0.28	0.16	0.14
query31	2.77	0.57	0.30
query32	3.23	0.59	0.48
query33	3.24	3.31	3.16
query34	15.59	3.98	3.30
query35	3.25	3.24	3.23
query36	0.56	0.43	0.43
query37	0.09	0.06	0.06
query38	0.05	0.04	0.03
query39	0.03	0.03	0.03
query40	0.17	0.16	0.14
query41	0.07	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 96.2 s
Total hot run time: 23.96 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 24.24% (16/66) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.23% (34353/45065)
Line Coverage 61.10% (385399/630798)
Region Coverage 57.51% (324526/564295)
Branch Coverage 58.29% (147802/253545)

@linrrzqqq linrrzqqq self-assigned this Sep 20, 2026
return Status::OK();
}

Status convert(StringRef input, std::string_view character_set_name, std::string& output) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P1:每行做了四次 ICU 扫描,实测慢约 2 倍

每个非空输入依次执行:

  1. ucnv_toUChars 预计算 UTF-16 大小
  2. ucnv_toUChars 真正转换
  3. ucnv_fromUChars 预计算结果大小
  4. ucnv_fromUChars 真正转换

这会完整扫描输入/中间结果四次,并生成 _utf16 中间缓冲区,最后还要把 std::string converted 再复制进结果列。

我用仓库自带 ICU、复用 converter,做了隔离转换内核的本地 microbenchmark,UTF8 → UTF16BE 的结果为:

输入长度 当前实现 ucnv_convertEx 直接转换 差距
15 B 200 ns/row 75 ns/row 2.67×
63 B 383 ns/row 157 ns/row 2.43×
1023 B 3978 ns/row 1991 ns/row 2.00×
65535 B 272 μs/row 124 μs/row 2.19×

吞吐测试:

  • Encode UTF8 → UTF16BE:230 MiB/s → 499 MiB/s
  • Decode Latin1 → UTF8:659 MiB/s → 1336 MiB/s

这不是完整 Doris 端到端 benchmark,但已经能证明转换内核有约 2 倍的优化空间。建议使用 ucnv_convertEx 的 pivot buffer 做直接转换,并使用可增长的目标 buffer。

此外:

  • _utf16 是普通 std::vector<UChar>
  • 输出 scratch 是普通 std::string
  • 一个 block 最多缓存 7 个 converter,每个 converter 都可能保留自己的最大 _utf16 容量

大字符串和混合 charset block 下,这些显著 scratch allocation 没有使用 Doris allocator。直接转换既能减少内存峰值,也能避免这部分中间缓冲。

### What problem does this PR solve?

Issue Number: close apache#48203

Related PR: apache#68131

Problem Summary: The BE character conversion path preflighted and converted every value twice through a full UTF-16 intermediate buffer. This repeatedly scanned input and pivot data and copied decode output once more into the result column. Stream conversion through ICU ucnv_convertEx with a bounded pivot, reuse block buffers, append decode output directly to ColumnString, and preserve strict conversion errors and Hive-compatible UTF-16 BOM behavior. On the same Linux Release build, the final implementation improved all 40 column execution cases by 1.96x to 3.92x. Extended reruns for every case whose initial CV exceeded 5% reduced CV to 1.0% to 2.8% and measured 2.17x to 3.93x.

### Release note

Improve the query performance of encode and decode without changing their SQL behavior.

### Check List (For Author)

- Test: Unit Test / Manual performance test
    - Linux Release build with ./build.sh --benchmark (passed)
    - ./run-be-ut.sh --run --filter='function_character_encoding_test.*' (5 tests passed)
    - 40-case Release benchmark correctness smoke test (40/40 passed)
    - Fixed-CPU ABBA performance test with 10 samples per case (1.96x to 3.92x)
    - Extended ABBA rerun for every case with initial CV above 5% (2.17x to 3.93x, CV 1.0% to 2.8%)
    - build-support/check-format.sh (passed)
    - build-support/check-build-hygiene.sh (passed)
    - clang-tidy attempted but blocked by the pre-existing unmatched NOLINTEND in be/src/core/types.h:576
- Behavior changed: No
- Does this need documentation: Yes. apache/doris-website#4151
### What problem does this PR solve?

Issue Number: apache#48203

Related PR: apache#68131

Problem Summary: encode and decode previously accepted a per-row character set column. Require the second argument to be a constant expression, including folded expressions such as upper('utf-8'). Reject table columns in FE. Do not fold away an invalid character set when the first argument is a null literal, so FE constant nulls and BE column nulls return the same error. Rewrite the regression CASE queries that evaluated every charset against every row.

### Release note

encode and decode now require a constant character set expression. An unsupported character set is rejected even when the input is NULL.

### Check List (For Author)

- Test: Unit Test / Regression test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.trees.expressions.functions.scalar.EncodeDecodeTest (4 tests passed)
    - ./run-be-ut.sh --run --filter='function_character_encoding_test.*' (7 tests passed)
    - ./run-regression-test.sh --run -d query_p0/sql_functions/binary_functions -s test_encode_decode (1 suite passed)
- Behavior changed: Yes. The character set argument must be constant. Invalid character sets error even when the first argument is NULL.
- Does this need documentation: Yes. apache/doris-website#4151
hacklu-tu added a commit to hacklu-tu/doris-website that referenced this pull request Sep 21, 2026
Document that encode and decode take a constant character set expression, reject table columns, and still error on an unsupported charset when the input is NULL.

Related PR: apache/doris#68131
@hacklu-tu

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17592	4162	4074	4074
q2	2191	365	304	304
q3	10129	1449	834	834
q4	4688	477	347	347
q5	7522	824	542	542
q6	191	182	143	143
q7	749	803	607	607
q8	9301	1512	1583	1512
q9	5498	4268	4214	4214
q10	6843	1319	1028	1028
q11	428	280	256	256
q12	633	412	295	295
q13	18030	2630	2004	2004
q14	265	255	244	244
q15	q16	741	719	669	669
q17	1750	1050	987	987
q18	6496	5607	5562	5562
q19	1356	1315	1090	1090
q20	468	395	260	260
q21	5833	3520	3023	3023
q22	457	376	311	311
Total cold run time: 101161 ms
Total hot run time: 28306 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5017	5058	4666	4666
q2	748	592	589	589
q3	4817	5263	4630	4630
q4	2277	2313	1459	1459
q5	4564	4416	4663	4416
q6	240	184	134	134
q7	1863	1740	1516	1516
q8	2573	2241	2197	2197
q9	7344	7220	7222	7220
q10	3736	3598	3095	3095
q11	522	405	370	370
q12	707	708	501	501
q13	2325	2624	2016	2016
q14	278	271	246	246
q15	q16	668	694	596	596
q17	7402	6826	6736	6736
q18	11987	11014	11766	11014
q19	1100	977	1022	977
q20	2228	2203	1906	1906
q21	5002	4202	4335	4202
q22	509	444	401	401
Total cold run time: 65907 ms
Total hot run time: 58887 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 153038 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 632fa2a98c7770f581d2b87611830acafb806baf, data reload: false

query5	4307	600	509	509
query6	438	217	182	182
query7	4881	569	307	307
query8	331	183	166	166
query9	8859	4002	4008	4002
query10	451	313	270	270
query11	5843	3556	3234	3234
query12	151	91	87	87
query13	1279	600	422	422
query14	6566	4590	4325	4325
query14_1	4096	4025	4083	4025
query15	198	192	178	178
query16	973	452	378	378
query17	895	652	536	536
query18	2412	450	320	320
query19	198	174	139	139
query20	80	79	80	79
query21	222	137	116	116
query22	13054	13117	12936	12936
query23	14050	13115	12327	12327
query23_1	12433	12391	12529	12391
query24	7313	1127	680	680
query24_1	668	632	671	632
query25	539	421	346	346
query26	1259	319	167	167
query27	2690	537	330	330
query28	4541	1940	1956	1940
query29	1625	743	520	520
query30	308	227	187	187
query31	902	773	642	642
query32	176	101	94	94
query33	536	323	258	258
query34	1186	1125	622	622
query35	743	762	652	652
query36	776	786	711	711
query37	149	108	93	93
query38	1839	1768	1693	1693
query39	714	696	682	682
query39_1	645	663	658	658
query40	236	127	107	107
query41	73	73	74	73
query42	102	94	94	94
query43	376	380	336	336
query44	1437	715	717	715
query45	185	188	168	168
query46	1075	1202	737	737
query47	1502	1525	1436	1436
query48	395	392	284	284
query49	595	405	297	297
query50	961	360	256	256
query51	10275	10255	10429	10255
query52	91	94	79	79
query53	256	262	188	188
query54	258	220	197	197
query55	84	77	70	70
query56	283	239	236	236
query57	1486	1457	1421	1421
query58	306	272	263	263
query59	2083	2144	1901	1901
query60	287	248	232	232
query61	175	167	163	163
query62	416	324	275	275
query63	218	181	186	181
query64	2915	1096	807	807
query65	3485	3440	3400	3400
query66	1778	407	301	301
query67	19881	19980	20130	19980
query68	3241	1492	826	826
query69	410	308	260	260
query70	935	842	834	834
query71	293	235	213	213
query72	2686	2332	2279	2279
query73	813	761	428	428
query74	4659	4503	4298	4298
query75	2342	2294	1978	1978
query76	2319	1121	804	804
query77	371	410	308	308
query78	9248	9062	8542	8542
query79	1319	1196	758	758
query80	586	456	364	364
query81	539	327	291	291
query82	929	163	126	126
query83	318	218	203	203
query84	308	148	114	114
query85	846	461	381	381
query86	332	245	228	228
query87	2013	1998	1843	1843
query88	3714	2730	2723	2723
query89	374	289	244	244
query90	1897	185	184	184
query91	168	156	127	127
query92	95	91	92	91
query93	1463	1481	885	885
query94	526	340	310	310
query95	664	389	338	338
query96	1052	792	336	336
query97	2422	2430	2352	2352
query98	167	171	150	150
query99	724	716	601	601
Total cold run time: 236816 ms
Total hot run time: 153038 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 23.65 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 632fa2a98c7770f581d2b87611830acafb806baf, data reload: false

query1	0.01	0.01	0.00
query2	0.10	0.05	0.04
query3	0.26	0.14	0.13
query4	1.60	0.13	0.14
query5	0.25	0.21	0.22
query6	1.16	0.92	0.89
query7	0.04	0.00	0.00
query8	0.06	0.03	0.04
query9	0.38	0.35	0.34
query10	0.58	0.54	0.55
query11	0.20	0.14	0.14
query12	0.18	0.14	0.14
query13	0.46	0.47	0.47
query14	0.95	0.93	0.96
query15	0.61	0.58	0.59
query16	0.33	0.33	0.32
query17	1.04	1.07	1.11
query18	0.20	0.20	0.19
query19	2.03	1.87	1.95
query20	0.02	0.02	0.01
query21	15.52	0.22	0.13
query22	4.79	0.06	0.05
query23	16.14	0.30	0.13
query24	2.99	0.41	0.31
query25	0.14	0.05	0.05
query26	0.73	0.21	0.14
query27	0.03	0.03	0.03
query28	3.54	0.75	0.31
query29	12.47	4.01	3.20
query30	0.29	0.16	0.15
query31	2.77	0.54	0.31
query32	3.22	0.58	0.48
query33	3.29	3.07	3.18
query34	15.63	3.92	3.27
query35	3.25	3.24	3.24
query36	0.56	0.43	0.42
query37	0.09	0.07	0.06
query38	0.05	0.03	0.03
query39	0.04	0.03	0.02
query40	0.18	0.14	0.14
query41	0.09	0.03	0.03
query42	0.03	0.02	0.02
query43	0.05	0.04	0.03
Total cold run time: 96.35 s
Total hot run time: 23.65 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.26% (34365/45060)
Line Coverage 61.18% (385857/630700)
Region Coverage 57.62% (325177/564366)
Branch Coverage 58.37% (147988/253513)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (67/67) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq

Copy link
Copy Markdown
Collaborator

run external

@linrrzqqq

Copy link
Copy Markdown
Collaborator

run feut

@linrrzqqq

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Static-only review of exact head 632fa2a98c7770f581d2b87611830acafb806baf against base e85575e3ad60389259dfe267a90124e6299a230a. I am requesting changes for two P2 issues: the new FE implementations are bypassed by the production folding rule, and the constant-only charset restriction rejects a query shape supported by Hive.

Checkpoint conclusions:

  • Goal and scope: registration, FE/BE types, strict conversion, UTF-16 BOM handling, and the focused factory integration are present, but the advertised behavior is incomplete because of the two inline findings.
  • Production paths and tests: direct evaluator tests bypass the planner gate; value-only regression tests can pass through BE; and the nonconstant regression cases codify the Hive-incompatible rejection. No build, test, benchmark, or runtime reproduction was run under this review task, so author/CI claims were not treated as independent validation.
  • Correctness and compatibility: FE/BE nullability and valid constant conversion behavior otherwise align; no persistence, wire-format, upgrade, configuration, transaction, or data-write change is introduced. The per-row charset contract is the material compatibility gap.
  • Concurrency, lifecycle, memory, and errors: converter state and result storage are execution-local, ICU handles are RAII-owned, errors are propagated, and static inspection found no separate thread-safety, ownership, offset, or overflow defect.
  • Integration and alternatives: builtin/visitor/factory registration is complete and there is no live legacy-planner implementation that restores the missing FE route. Optional BE folding is disabled by default and does not make the new FE evaluator production-reachable.
  • Observability and security: no new distributed/persistent operation needs additional telemetry, and no security-sensitive boundary is changed.
  • User focus: no additional review focus was supplied.

Coverage and convergence: all 14 changed paths were reviewed; normal BE, normal FE/integration, and risk-focused reviews converged after two rounds. The live head and all review threads were refreshed immediately before submission. The three existing threads were treated as hard duplicate fences and are not repeated here.

// calls with any null child to NULL and skips backend evaluation.
@Override
public boolean foldable() {
return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Keep valid literal calls reachable by planner folding

FoldConstantRuleOnFE.visitBoundFunction() calls preProcess() first, and that method returns this expression immediately when foldable() is false. Thus a real OneRowRelation -> Project(decode(X'E4B8AD', 'UTF-8')) plan never reaches the new StringArithmetic.decode implementation; the project remains a function instead of becoming Project('中'), so PhysicalOneRowRelation.computeResultInFe() cannot return the literal result without a BE. The new tests call ExpressionEvaluator directly, whose separate isConstant() gate bypasses this production path, so they do not prove planner folding. Please preserve invalid-charset-before-NULL behavior with targeted validation/folding instead of disabling folding for every input, and add a planner-level test; Encode has the same reachability problem.


@Override
public void checkLegalityBeforeTypeCoercion() {
if (!getArgument(1).isConstant()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve Hive's per-row charset contract

This rejects encode(payload, charset_name) (and the equivalent decode call), but Hive treats a constant charset only as a cache optimization: GenericUDFEncode and GenericUDFDecode read argument 2 per row when it is not constant. Since this PR is advertised as Hive-compatible, migrated queries using a charset column now fail analysis instead of running. Please retain per-row charsets (the BE already has a bounded converter cache) and add mixed-charset/NULL regression coverage; otherwise narrow the API and release claim explicitly to constant-only charsets.

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.26% (34365/45060)
Line Coverage 61.18% (385855/630700)
Region Coverage 57.62% (325176/564366)
Branch Coverage 58.37% (147986/253513)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (67/67) 🎉
Increment coverage report
Complete coverage report

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