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>
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