Skip to content

[enhance](struct) Merge struct_element into element_at#64027

Open
csun5285 wants to merge 2 commits into
apache:masterfrom
csun5285:fix/DORIS-26105-struct-subscript-coredump
Open

[enhance](struct) Merge struct_element into element_at#64027
csun5285 wants to merge 2 commits into
apache:masterfrom
csun5285:fix/DORIS-26105-struct-subscript-coredump

Conversation

@csun5285
Copy link
Copy Markdown
Contributor

@csun5285 csun5285 commented Jun 2, 2026

doc: apache/doris-website#3898 element_at access for STRUCT type

What problem does this PR solve?

Issue Number: close #xxx

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

@csun5285
Copy link
Copy Markdown
Contributor Author

csun5285 commented Jun 2, 2026

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 33.33% (1/3) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 0.58% (2/347) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29274 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit cbd702383ab51d6cb01ece1026b2a361e937b288, 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	17698	4016	4054	4016
q2	q3	10810	1365	793	793
q4	4687	484	339	339
q5	7576	939	603	603
q6	183	172	138	138
q7	756	853	651	651
q8	9380	1697	1619	1619
q9	5804	4552	4513	4513
q10	6689	1817	1528	1528
q11	440	269	252	252
q12	629	426	290	290
q13	18096	3286	2716	2716
q14	268	261	252	252
q15	q16	820	786	708	708
q17	1014	1002	942	942
q18	6947	5756	5591	5591
q19	1363	1412	1120	1120
q20	519	403	261	261
q21	6346	2794	2614	2614
q22	482	402	328	328
Total cold run time: 100507 ms
Total hot run time: 29274 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	5118	4838	4835	4835
q2	q3	4908	5383	4655	4655
q4	2127	2184	1404	1404
q5	4760	4920	4638	4638
q6	224	175	127	127
q7	1889	1770	1593	1593
q8	2393	2082	2104	2082
q9	7965	7366	7410	7366
q10	4765	4685	4252	4252
q11	531	384	354	354
q12	733	739	529	529
q13	3056	3358	2847	2847
q14	282	283	260	260
q15	q16	676	699	612	612
q17	1263	1260	1250	1250
q18	7107	6686	6780	6686
q19	1123	1100	1127	1100
q20	2218	2217	1957	1957
q21	5304	4603	4428	4428
q22	521	458	413	413
Total cold run time: 56963 ms
Total hot run time: 51388 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

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

query5	4328	641	493	493
query6	454	203	183	183
query7	4877	562	312	312
query8	372	216	204	204
query9	8786	4042	4045	4042
query10	449	323	266	266
query11	5918	2361	2167	2167
query12	164	104	99	99
query13	1265	619	433	433
query14	6410	5438	5094	5094
query14_1	4462	4379	4397	4379
query15	206	196	180	180
query16	993	424	418	418
query17	1094	698	578	578
query18	2438	472	342	342
query19	200	182	143	143
query20	115	106	104	104
query21	227	137	116	116
query22	13641	13650	13485	13485
query23	17408	16575	16118	16118
query23_1	16188	16372	16312	16312
query24	7562	1798	1302	1302
query24_1	1330	1321	1362	1321
query25	568	448	388	388
query26	1316	339	172	172
query27	2618	575	326	326
query28	4458	1994	2000	1994
query29	1095	607	484	484
query30	312	242	202	202
query31	1136	1076	943	943
query32	120	60	58	58
query33	524	310	245	245
query34	1196	1131	642	642
query35	752	779	694	694
query36	1411	1391	1208	1208
query37	155	105	94	94
query38	3215	3201	3076	3076
query39	938	909	888	888
query39_1	901	931	885	885
query40	219	125	99	99
query41	65	62	64	62
query42	96	92	92	92
query43	321	330	272	272
query44	
query45	199	186	184	184
query46	1106	1243	776	776
query47	2332	2335	2233	2233
query48	401	438	305	305
query49	630	487	357	357
query50	998	365	264	264
query51	4265	4415	4358	4358
query52	88	88	78	78
query53	244	275	193	193
query54	271	241	203	203
query55	77	76	72	72
query56	259	225	225	225
query57	1416	1417	1294	1294
query58	258	219	217	217
query59	1610	1669	1448	1448
query60	299	262	245	245
query61	184	183	181	181
query62	717	669	590	590
query63	242	192	188	188
query64	2658	852	689	689
query65	
query66	1830	485	359	359
query67	29762	29697	29612	29612
query68	
query69	433	312	278	278
query70	988	999	934	934
query71	321	233	212	212
query72	3211	2920	2357	2357
query73	872	790	415	415
query74	5145	4938	4773	4773
query75	2729	2618	2247	2247
query76	2311	1222	778	778
query77	348	385	283	283
query78	12409	12531	11828	11828
query79	1491	1055	753	753
query80	588	485	390	390
query81	451	281	243	243
query82	869	159	124	124
query83	366	276	248	248
query84	262	141	117	117
query85	888	529	438	438
query86	385	301	277	277
query87	3385	3313	3225	3225
query88	3627	2731	2709	2709
query89	430	382	332	332
query90	1971	177	180	177
query91	176	169	141	141
query92	69	67	60	60
query93	1576	1412	851	851
query94	554	372	306	306
query95	680	382	364	364
query96	1085	864	358	358
query97	2703	2683	2587	2587
query98	217	207	203	203
query99	1177	1169	1026	1026
Total cold run time: 252222 ms
Total hot run time: 169828 ms

// visitUnboundFunction where the named call `element_at(s,'f')` gets this same rewrite. Apply the
// shared ElementAt.rewriteWhenAnalyze() here so both syntaxes behave identically; otherwise the
// BE receives element_at(struct) and aborts.
if (coerced instanceof RewriteWhenAnalyze) {
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.

maybe we need merge element_at and struct_element into one function

@csun5285 csun5285 force-pushed the fix/DORIS-26105-struct-subscript-coredump branch from cbd7023 to 5a06428 Compare June 3, 2026 10:58
Subscript access on a struct, s['field'], is parsed directly into an
element_at expression, but element_at only supported ARRAY and MAP and
aborted on a DCHECK in the BE (DORIS-26105). Rather than routing struct
field access through a separate struct_element function, make element_at
the single entry point for array/map/struct field access.

BE: FunctionArrayElement (element_at) now resolves a struct field by its
constant int/string index and the standalone struct_element function is
removed. The struct_element name is registered as a plain extra name on
the same implementation (not an alias: element_at is in the variadic set
because FunctionVariantElement shares the name, so an alias key would be
mangled to element_atStructString and fail to resolve), keeping any
persisted plan that still references struct_element resolvable.

FE: the StructElement node is removed and every struct field access form
(s['f'], s.f, element_at(s,'f'), struct_element(s,'f')) converges on
ElementAt, which absorbs the struct signature, legality check, int->name
normalization and the nested-column-pruning access path. struct_element
remains a user-facing SQL name bound to ElementAt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@csun5285 csun5285 force-pushed the fix/DORIS-26105-struct-subscript-coredump branch from 5a06428 to 51f5033 Compare June 3, 2026 11:53
@csun5285 csun5285 changed the title [fix](nereids) rewrite struct subscript s['f'] into struct_element [enhance](struct) Merge struct_element into element_at Jun 3, 2026
Projecting a struct field by its original mixed-case name (e.g. reading a
migrated Iceberg table whose schema keeps sName while Doris stores it as
sname, then querying sName) failed with an opaque error:
[INTERNAL_ERROR] function return type check failed ... real_return_type is nullptr.

Root cause: struct field names are canonically lower-cased by the FE (both
native DDL and the Iceberg schema read go through StructField.toLowerCase),
but a query may reference a field with different casing. The FE matches the
field case-insensitively and forwards the original-case name to the BE, while
DataTypeStruct::try_get_position_by_name compared case-sensitively, so the
field was not found, get_return_type returned nullptr and build() reported
the opaque internal error.

Fix:
- DataTypeStruct::try_get_position_by_name / get_position_by_name match the
  field name case-insensitively (iequal).
- element_at's struct return-type path throws the concrete "field not found /
  index out of bound" error instead of returning nullptr, so an unresolvable
  field surfaces a clear message rather than an internal error.

DORIS-26117

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@csun5285
Copy link
Copy Markdown
Contributor Author

csun5285 commented Jun 3, 2026

run buildall

csun5285 added a commit to csun5285/doris-website that referenced this pull request Jun 3, 2026
Reflect apache/doris#64027 latest changes: struct_element is now subsumed
by element_at (kept as a backward-compatible alias), struct field names are
matched case-insensitively, document the dot operator s.field access form,
and update the non-constant index error message.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29127 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 94397e5b8cd7026029bc76ccaffe209076de7179, 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	17696	4032	3997	3997
q2	q3	10743	1355	807	807
q4	4713	472	353	353
q5	7811	848	589	589
q6	202	172	138	138
q7	825	835	651	651
q8	10281	1709	1587	1587
q9	7299	4524	4508	4508
q10	6809	1816	1552	1552
q11	433	276	244	244
q12	637	423	287	287
q13	18153	3428	2791	2791
q14	274	255	245	245
q15	q16	817	773	708	708
q17	921	966	957	957
q18	6819	5725	5577	5577
q19	1176	1288	1028	1028
q20	504	394	256	256
q21	5975	2750	2537	2537
q22	467	373	315	315
Total cold run time: 102555 ms
Total hot run time: 29127 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	4853	4764	4791	4764
q2	q3	5100	5203	4672	4672
q4	2096	2189	1403	1403
q5	5017	4663	4657	4657
q6	227	182	127	127
q7	1957	1825	1555	1555
q8	2341	1945	1938	1938
q9	7455	7406	7438	7406
q10	4739	4666	4208	4208
q11	532	390	360	360
q12	735	822	590	590
q13	3022	3359	2818	2818
q14	276	279	271	271
q15	q16	669	700	624	624
q17	1292	1268	1239	1239
q18	7184	6644	6931	6644
q19	1132	1114	1127	1114
q20	2209	2222	1944	1944
q21	5246	4559	4555	4555
q22	514	436	412	412
Total cold run time: 56596 ms
Total hot run time: 51301 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 169412 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 94397e5b8cd7026029bc76ccaffe209076de7179, data reload: false

query5	4332	640	505	505
query6	440	206	189	189
query7	4807	582	294	294
query8	366	214	213	213
query9	8753	3995	4023	3995
query10	440	311	260	260
query11	5921	2318	2197	2197
query12	151	101	98	98
query13	1256	607	433	433
query14	6406	5370	5081	5081
query14_1	4418	4401	4386	4386
query15	211	205	178	178
query16	992	451	431	431
query17	1134	721	592	592
query18	2513	480	348	348
query19	215	187	153	153
query20	116	110	109	109
query21	216	135	118	118
query22	13663	13644	13415	13415
query23	17307	16551	16192	16192
query23_1	16296	16223	16365	16223
query24	7537	1783	1327	1327
query24_1	1269	1350	1294	1294
query25	543	444	386	386
query26	1313	320	167	167
query27	2664	521	339	339
query28	4465	2026	2040	2026
query29	1061	606	493	493
query30	312	234	201	201
query31	1139	1081	947	947
query32	113	60	57	57
query33	523	324	254	254
query34	1163	1187	670	670
query35	762	798	674	674
query36	1408	1369	1236	1236
query37	148	102	90	90
query38	3200	3154	3046	3046
query39	929	923	906	906
query39_1	886	884	889	884
query40	222	125	102	102
query41	66	62	63	62
query42	94	93	95	93
query43	321	323	277	277
query44	
query45	194	183	181	181
query46	1099	1175	735	735
query47	2324	2417	2183	2183
query48	415	390	287	287
query49	653	475	357	357
query50	1036	345	247	247
query51	4316	4374	4260	4260
query52	88	86	78	78
query53	233	267	191	191
query54	277	216	199	199
query55	77	73	68	68
query56	226	234	217	217
query57	1450	1400	1308	1308
query58	240	217	209	209
query59	1579	1619	1439	1439
query60	296	247	230	230
query61	159	158	161	158
query62	692	664	593	593
query63	230	183	183	183
query64	2569	773	635	635
query65	
query66	1777	479	348	348
query67	29940	29564	29449	29449
query68	
query69	418	309	258	258
query70	991	973	949	949
query71	290	232	229	229
query72	3023	2706	2385	2385
query73	861	711	425	425
query74	5159	4957	4798	4798
query75	2664	2574	2242	2242
query76	2320	1138	759	759
query77	354	376	289	289
query78	12385	12366	11893	11893
query79	1412	1060	787	787
query80	579	483	392	392
query81	454	285	251	251
query82	581	152	122	122
query83	361	275	246	246
query84	267	147	113	113
query85	888	555	470	470
query86	363	291	275	275
query87	3376	3363	3162	3162
query88	3611	2727	2710	2710
query89	430	382	331	331
query90	1911	181	185	181
query91	181	166	138	138
query92	63	62	58	58
query93	1501	1512	847	847
query94	555	353	305	305
query95	682	385	434	385
query96	1152	855	361	361
query97	2709	2712	2593	2593
query98	211	203	214	203
query99	1171	1170	1024	1024
Total cold run time: 251303 ms
Total hot run time: 169412 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 78.22% (79/101) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.95% (27497/38217)
Line Coverage 55.45% (294164/530534)
Region Coverage 52.01% (244473/470064)
Branch Coverage 53.26% (105885/198802)

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 58.33% (28/48) 🎉
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