Skip to content

[refine](function) Unify nullable array access with ColumnArrayView - #66234

Open
Mryange wants to merge 3 commits into
apache:masterfrom
Mryange:refine-array-nullable-view
Open

[refine](function) Unify nullable array access with ColumnArrayView#66234
Mryange wants to merge 3 commits into
apache:masterfrom
Mryange:refine-array-nullable-view

Conversation

@Mryange

@Mryange Mryange commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary: Doris Array columns always store nested elements in ColumnNullable, but several Array functions still manually handled an unreachable non-nullable nested layout and duplicated const/outer-null unwrapping. This change uses ColumnArrayView for scalar Array read paths, preserves concrete columns where generic output or hashing is required, and updates the affected element_at test fixtures to the valid physical layout.

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

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

@Mryange

Mryange commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

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

Request changes: two blocking regressions remain.

  1. array_apply no longer compiles for decimal scalar dispatch because this translation unit lacks the complete ColumnDecimal definition; the current macOS BE UT fails on the reviewed head.
  2. element_at now unconditionally treats the shared array/map nested column as ColumnNullable, but synthetic arrays over non-nullable ColumnMap values are valid and now fail a bad cast.

Critical checkpoint conclusions:

  • Goal and functional proof: using ColumnArrayView is consistent with the enforced DataTypeArray nested-nullable layout for true arrays, but the PR is not functionally complete until the compile failure and synthetic map path are fixed.
  • Scope and parallel paths: the refactor is otherwise focused. The main array, map, direct-function, lambda-function, const, outer-null, inner-null, empty-array, and multi-argument hash paths were traced; no additional correctness issue was substantiated.
  • Concurrency and lifecycle: these scalar read/transform paths introduce no new threads, shared mutable state, locks, static initialization, or special lifetime ownership.
  • Compatibility and persistence: no storage-format, FE-BE protocol, configuration, transaction, or persistence change is introduced. The map-value failure is an in-process physical-column compatibility regression and is called out inline.
  • Error handling, memory, performance, and observability: no ignored Status, new untracked significant allocation, redundant asymptotic work, or new observability requirement was found. The changed loops remain linear in flattened element count.
  • Tests: existing array regression suites cover the modified functions and many null/empty/decimal cases, and the element-at fixtures were updated to the valid array layout. However, the live macOS BE UT currently fails during compilation, and the non-nullable map-value element_at case needs coverage. No local build or tests were run because this is a review-only environment.
  • User focus: no additional focus was provided; the entire PR was reviewed.

constexpr PrimitiveType PType = DispatchType::PType;
*dst = _apply_internal<typename PrimitiveTypeTraits<PType>::CppType, OP>(
src_column, src_offsets, cmp);
auto array_view = ColumnArrayView<PType>::create(array_column);

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.

This new view instantiation currently breaks the BE build for decimal arrays. dispatch_switch_scalar instantiates ColumnArrayView<TYPE_DECIMAL32/64/V2> here, but this translation unit does not include the complete ColumnDecimal definition, so the live macOS BE UT fails in column_execute_util.h with implicit instantiation of undefined template 'doris::ColumnDecimal<...>'. Please include core/column/column_decimal.h here (or make the view header provide the concrete type it requires) so every supported scalar instantiation compiles.

} else {
nested_column = array_column.get_data_ptr();
}
const auto& nested_null_column =

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.

This helper is also used by _execute_map, which wraps ColumnMap::get_values_ptr() in a synthetic ColumnArray. DataTypeMap preserves each declared child type, so a valid map with a non-nullable value type has a plain ColumnInt32/ColumnString here rather than ColumnNullable; this unconditional cast then fails instead of returning the mapped value. The Array storage invariant does not cover that synthetic map-value array. Please retain conditional unwrapping for this shared path (or split the map and true-array paths), and add a non-nullable-map-value element_at test.

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66234

Problem Summary: ColumnArrayView scalar dispatch instantiates decimal column types in array_apply, but the translation unit did not include the complete ColumnDecimal definition. Include the decimal column header so decimal array dispatch can compile.

### Release note

None

### Check List (For Author)

- Test: No need to test (header dependency fix; build not run yet)
- Behavior changed: No
- Does this need documentation: No
@Mryange

Mryange commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17615	4124	4028	4028
q2	2054	339	206	206
q3	10272	1427	831	831
q4	4686	479	340	340
q5	7501	863	580	580
q6	186	175	138	138
q7	784	819	596	596
q8	9365	1656	1514	1514
q9	5541	4343	4325	4325
q10	6753	1747	1472	1472
q11	520	377	331	331
q12	711	592	470	470
q13	18113	3402	2781	2781
q14	262	274	252	252
q15	q16	801	781	711	711
q17	998	928	987	928
q18	6957	5733	5543	5543
q19	1328	1280	1156	1156
q20	828	675	582	582
q21	5907	2655	2412	2412
q22	437	353	301	301
Total cold run time: 101619 ms
Total hot run time: 29497 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4454	4364	4344	4344
q2	308	327	218	218
q3	4542	4949	4392	4392
q4	2043	2148	1464	1464
q5	4451	4348	4350	4348
q6	236	181	134	134
q7	1779	2003	1882	1882
q8	2587	2216	2156	2156
q9	8118	8140	7958	7958
q10	4710	4661	4244	4244
q11	587	407	376	376
q12	749	780	533	533
q13	3315	3624	2982	2982
q14	297	303	273	273
q15	q16	720	750	663	663
q17	1363	1364	1321	1321
q18	8033	7442	7444	7442
q19	1241	1123	1086	1086
q20	2214	2183	1931	1931
q21	5314	4535	4414	4414
q22	511	478	412	412
Total cold run time: 57572 ms
Total hot run time: 52573 ms

@hello-stephen

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

query5	4950	678	501	501
query6	481	227	208	208
query7	4928	591	354	354
query8	344	193	174	174
query9	8778	4086	4061	4061
query10	501	362	294	294
query11	6524	2354	2111	2111
query12	285	108	99	99
query13	1259	630	432	432
query14	6243	5180	4870	4870
query14_1	4247	4296	4219	4219
query15	212	215	186	186
query16	1030	491	480	480
query17	947	738	585	585
query18	2445	487	346	346
query19	219	198	158	158
query20	117	110	106	106
query21	248	159	138	138
query22	13635	13531	13403	13403
query23	17465	16517	16120	16120
query23_1	16282	16105	16183	16105
query24	7514	1765	1275	1275
query24_1	1318	1301	1274	1274
query25	538	456	361	361
query26	1367	364	215	215
query27	2580	599	387	387
query28	4432	2058	2005	2005
query29	1053	601	480	480
query30	336	262	242	242
query31	1113	1094	959	959
query32	105	59	57	57
query33	505	323	264	264
query34	1178	1162	645	645
query35	772	779	682	682
query36	998	1042	894	894
query37	159	107	92	92
query38	1847	1670	1643	1643
query39	880	872	840	840
query39_1	828	846	830	830
query40	254	168	146	146
query41	67	63	63	63
query42	96	92	95	92
query43	319	323	273	273
query44	1469	790	761	761
query45	188	186	175	175
query46	1069	1200	726	726
query47	2096	2074	2028	2028
query48	401	406	303	303
query49	571	428	313	313
query50	1077	403	326	326
query51	10585	10441	10512	10441
query52	84	87	75	75
query53	256	283	204	204
query54	287	229	217	217
query55	76	70	64	64
query56	312	304	302	302
query57	1318	1255	1221	1221
query58	285	252	254	252
query59	1574	1639	1436	1436
query60	313	271	270	270
query61	170	173	168	168
query62	543	492	438	438
query63	257	215	199	199
query64	2989	1157	987	987
query65	4718	4662	4665	4662
query66	1847	526	451	451
query67	29266	29212	29137	29137
query68	3273	1573	1037	1037
query69	433	301	259	259
query70	918	833	805	805
query71	377	349	314	314
query72	3096	2716	2349	2349
query73	845	748	429	429
query74	5090	4953	4717	4717
query75	2541	2520	2142	2142
query76	2322	1199	804	804
query77	360	370	282	282
query78	11999	11914	11342	11342
query79	1416	1159	730	730
query80	1026	570	470	470
query81	532	326	288	288
query82	541	158	118	118
query83	379	331	301	301
query84	336	157	130	130
query85	968	633	527	527
query86	378	247	231	231
query87	1826	1819	1757	1757
query88	3734	2820	2802	2802
query89	443	380	324	324
query90	1879	198	196	196
query91	205	200	164	164
query92	65	59	58	58
query93	1554	1559	904	904
query94	631	352	307	307
query95	781	500	486	486
query96	1057	795	345	345
query97	2630	2608	2475	2475
query98	215	205	201	201
query99	1083	1104	974	974
Total cold run time: 266382 ms
Total hot run time: 177371 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.05	0.05
query3	0.26	0.15	0.14
query4	1.61	0.13	0.14
query5	0.23	0.22	0.22
query6	1.27	1.07	1.06
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.39	0.32	0.31
query10	0.55	0.63	0.57
query11	0.19	0.14	0.14
query12	0.18	0.14	0.14
query13	0.47	0.46	0.49
query14	1.01	1.02	1.00
query15	0.62	0.59	0.59
query16	0.31	0.32	0.32
query17	1.08	1.09	1.09
query18	0.22	0.19	0.21
query19	2.07	1.92	1.96
query20	0.01	0.02	0.01
query21	15.44	0.23	0.13
query22	4.77	0.05	0.06
query23	16.16	0.31	0.12
query24	3.00	0.43	0.33
query25	0.12	0.05	0.04
query26	0.73	0.22	0.15
query27	0.04	0.04	0.03
query28	3.51	0.95	0.52
query29	12.48	4.20	3.32
query30	0.26	0.14	0.15
query31	2.77	0.58	0.31
query32	3.21	0.60	0.48
query33	3.12	3.34	3.16
query34	15.51	4.21	3.55
query35	3.47	3.46	3.54
query36	0.55	0.44	0.42
query37	0.08	0.06	0.07
query38	0.05	0.04	0.04
query39	0.03	0.03	0.03
query40	0.18	0.15	0.16
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.32 s
Total hot run time: 24.97 s

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66234

Problem Summary: array_enumerate_uniq created a second mutable pointer to its result nested column before constructing ColumnNullable. The mutable constructor then observed a shared subcolumn and failed with COW::assert_mutable. Move the uniquely owned result column and null map into ColumnNullable, and remove the obsolete input array pointer.

### Release note

None

### Check List (For Author)

- Test: No need to test yet (clang-format and diff checks only; regression test not run)
- Behavior changed: No, restores expected execution
- Does this need documentation: No
@Mryange

Mryange commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17708	4131	4134	4131
q2	2145	368	206	206
q3	10133	1425	812	812
q4	4678	463	343	343
q5	7498	831	577	577
q6	184	169	138	138
q7	758	796	601	601
q8	9416	1650	1635	1635
q9	5574	4360	4292	4292
q10	6730	1729	1493	1493
q11	501	355	328	328
q12	752	590	465	465
q13	18150	3391	2760	2760
q14	269	268	233	233
q15	q16	788	771	699	699
q17	970	884	980	884
q18	6996	5694	5528	5528
q19	1372	1195	987	987
q20	823	711	580	580
q21	6003	2669	2535	2535
q22	423	357	295	295
Total cold run time: 101871 ms
Total hot run time: 29522 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4511	4351	4424	4351
q2	299	315	205	205
q3	4575	4959	4326	4326
q4	2058	2127	1329	1329
q5	4373	4255	4263	4255
q6	228	175	129	129
q7	1719	1920	1828	1828
q8	2477	2152	2167	2152
q9	8081	8171	7678	7678
q10	4682	4696	4221	4221
q11	567	417	401	401
q12	773	771	539	539
q13	3270	3662	2903	2903
q14	283	319	274	274
q15	q16	725	721	623	623
q17	1374	1309	1427	1309
q18	7908	7431	7337	7337
q19	1189	1124	1090	1090
q20	2193	2201	1938	1938
q21	5187	4518	4410	4410
q22	513	444	405	405
Total cold run time: 56985 ms
Total hot run time: 51703 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 3.95% (6/152) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 59.05% (25571/43301)
Line Coverage 43.15% (256343/594097)
Region Coverage 38.83% (203057/522967)
Branch Coverage 40.16% (92577/230504)

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17682	4150	4176	4150
q2	2022	327	209	209
q3	10276	1449	825	825
q4	4684	472	341	341
q5	7584	910	570	570
q6	188	173	141	141
q7	791	831	611	611
q8	9377	1764	1666	1666
q9	5652	4383	4340	4340
q10	6779	1732	1446	1446
q11	510	368	329	329
q12	723	575	467	467
q13	18111	3471	2775	2775
q14	265	267	238	238
q15	q16	782	777	710	710
q17	972	1010	1008	1008
q18	7081	5880	5607	5607
q19	1143	1377	1137	1137
q20	836	718	604	604
q21	5535	2650	2327	2327
q22	432	362	311	311
Total cold run time: 101425 ms
Total hot run time: 29812 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4533	4480	4465	4465
q2	294	318	206	206
q3	4558	4907	4429	4429
q4	2069	2166	1377	1377
q5	4454	4293	4257	4257
q6	230	178	131	131
q7	1825	2081	1692	1692
q8	2540	2344	2175	2175
q9	8054	8072	7932	7932
q10	4673	4767	4237	4237
q11	619	417	368	368
q12	759	770	556	556
q13	3254	3551	2936	2936
q14	302	315	261	261
q15	q16	705	733	667	667
q17	1391	1380	1456	1380
q18	7782	7314	7270	7270
q19	1187	1100	1109	1100
q20	2205	2221	1946	1946
q21	5283	4565	4454	4454
q22	529	465	397	397
Total cold run time: 57246 ms
Total hot run time: 52236 ms

@hello-stephen

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

query5	4299	644	489	489
query6	451	218	209	209
query7	4836	642	354	354
query8	330	190	177	177
query9	8768	4062	4112	4062
query10	471	357	342	342
query11	5885	2321	2164	2164
query12	164	107	103	103
query13	1287	622	442	442
query14	6249	5231	4887	4887
query14_1	4205	4278	4225	4225
query15	225	207	181	181
query16	1037	478	422	422
query17	953	741	593	593
query18	2442	485	355	355
query19	217	201	148	148
query20	108	105	109	105
query21	240	161	138	138
query22	13595	13608	13570	13570
query23	17441	16612	16121	16121
query23_1	16280	16306	16316	16306
query24	7691	1793	1288	1288
query24_1	1321	1306	1267	1267
query25	585	473	413	413
query26	1328	360	219	219
query27	2614	601	406	406
query28	4490	2030	2081	2030
query29	1065	610	488	488
query30	336	267	231	231
query31	1123	1091	987	987
query32	98	62	62	62
query33	516	312	261	261
query34	1176	1158	660	660
query35	759	785	662	662
query36	1017	1019	867	867
query37	154	105	93	93
query38	1880	1719	1619	1619
query39	873	880	842	842
query39_1	837	826	849	826
query40	257	165	142	142
query41	66	64	64	64
query42	97	93	93	93
query43	327	335	284	284
query44	1485	793	785	785
query45	200	180	174	174
query46	1103	1205	775	775
query47	2122	2120	2000	2000
query48	405	428	289	289
query49	582	421	312	312
query50	1088	440	329	329
query51	10801	10601	10396	10396
query52	91	88	74	74
query53	266	279	201	201
query54	287	258	224	224
query55	75	70	66	66
query56	291	309	294	294
query57	1294	1281	1172	1172
query58	337	263	260	260
query59	1574	1639	1493	1493
query60	315	260	252	252
query61	153	149	150	149
query62	537	500	431	431
query63	245	199	200	199
query64	2829	1059	859	859
query65	4729	4598	4663	4598
query66	1827	494	380	380
query67	29360	29194	29159	29159
query68	3111	1642	1064	1064
query69	408	301	274	274
query70	943	801	851	801
query71	371	341	315	315
query72	3034	2792	2408	2408
query73	845	792	436	436
query74	5076	4908	4719	4719
query75	2562	2512	2132	2132
query76	2320	1205	827	827
query77	378	384	290	290
query78	11856	11905	11290	11290
query79	1381	1194	769	769
query80	676	561	462	462
query81	456	338	293	293
query82	565	157	122	122
query83	403	345	301	301
query84	324	159	131	131
query85	956	625	533	533
query86	331	243	226	226
query87	1833	1819	1760	1760
query88	3779	2836	2804	2804
query89	447	376	331	331
query90	1867	210	195	195
query91	202	195	161	161
query92	67	59	55	55
query93	1713	1549	955	955
query94	550	360	318	318
query95	836	589	470	470
query96	1063	804	363	363
query97	2591	2628	2468	2468
query98	216	214	221	214
query99	1093	1123	990	990
Total cold run time: 262802 ms
Total hot run time: 178275 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.10	0.05	0.04
query3	0.25	0.14	0.13
query4	1.61	0.14	0.14
query5	0.23	0.22	0.22
query6	1.16	0.82	0.79
query7	0.03	0.01	0.00
query8	0.05	0.04	0.03
query9	0.37	0.31	0.32
query10	0.54	0.54	0.54
query11	0.18	0.14	0.14
query12	0.18	0.14	0.15
query13	0.48	0.47	0.48
query14	1.02	1.01	1.00
query15	0.62	0.59	0.59
query16	0.33	0.33	0.32
query17	1.12	1.11	1.12
query18	0.23	0.21	0.20
query19	1.99	2.00	1.91
query20	0.02	0.02	0.02
query21	15.45	0.21	0.15
query22	4.85	0.06	0.06
query23	16.12	0.31	0.12
query24	3.00	0.46	0.31
query25	0.12	0.05	0.04
query26	0.75	0.21	0.16
query27	0.05	0.04	0.04
query28	3.47	0.93	0.53
query29	12.55	4.10	3.28
query30	0.27	0.15	0.16
query31	2.78	0.59	0.32
query32	3.26	0.60	0.49
query33	3.20	3.19	3.23
query34	15.49	4.24	3.54
query35	3.50	3.57	3.57
query36	0.55	0.45	0.43
query37	0.11	0.07	0.06
query38	0.06	0.04	0.04
query39	0.04	0.03	0.03
query40	0.19	0.15	0.14
query41	0.08	0.03	0.02
query42	0.04	0.02	0.03
query43	0.04	0.04	0.04
Total cold run time: 96.48 s
Total hot run time: 24.83 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 78.95% (120/152) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.73% (31982/42231)
Line Coverage 60.35% (356141/590129)
Region Coverage 56.87% (298428/524713)
Branch Coverage 58.31% (134426/230544)

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.

2 participants