Skip to content

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

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

[refine](function) Unify nullable array access with ColumnArrayView#66234
Mryange wants to merge 2 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

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