Skip to content

[fix](load) Preserve declared types in generated column dependencies - #67758

Open
feiniaofeiafei wants to merge 2 commits into
apache:masterfrom
feiniaofeiafei:codex/fix-generated-column-declared-type
Open

[fix](load) Preserve declared types in generated column dependencies#67758
feiniaofeiafei wants to merge 2 commits into
apache:masterfrom
feiniaofeiafei:codex/fix-generated-column-declared-type

Conversation

@feiniaofeiafei

@feiniaofeiafei feiniaofeiafei commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Related PR:#35284
Problem Summary:

Generated columns are substituted into dependent expressions before conversion to their declared types. For c BOOLEAN AS (a) and d INT AS (c + 1), inserting a = 2 stores c = true but d = 3, while evaluating c + 1 from the stored column returns 2. Similarly, x = 1.7, c INT AS (x), and d DOUBLE AS (c + 0.25) incorrectly store d = 1.95 instead of 1.25.

Cast each generated expression to its declared column type before registering it for substitution into dependent generated columns in BindSink. This also applies to new writes into existing tables; previously stored incorrect values are not recalculated.

Release note

Fix incorrect generated column values when a generated column references another generated column whose expression type differs from its declared type.

Check List (For Author)

  • Test

    • Regression test
      • Passed test_generated_column_declared_type, test_generated_column, and test_generated_column_update.
      • Added coverage for boolean and numeric dependency chains, NULLs, INSERT VALUES, INSERT SELECT, INSERT OVERWRITE, and numeric Stream Load. Expected output was generated with run-regression-test.sh and verified in a subsequent run.
    • Unit Test
    • Manual test (add detailed scripts or steps below)
      • Reproduced both examples above before replacing FE libraries and verified correct new writes into the same tables after replacement.
      • FE build and Checkstyle passed using DISABLE_BUILD_UI=ON ./build.sh --fe; the test FE used be_exec_version=13 to match the existing BE.
      • An additional boolean-chain Stream Load check hit a BE column-type mismatch with both the original and patched FE; that pre-existing failure is not addressed here.
    • No need to test or manual test. Explain why:
  • Behavior changed:

    • No.
    • Yes. Dependent generated columns use values converted to the referenced columns' declared types.
  • 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?

@morrySnow morrySnow changed the title [fix](fe) Preserve declared types in generated column dependencies [fix](load) Preserve declared types in generated column dependencies Sep 10, 2026
@morrySnow

Copy link
Copy Markdown
Contributor

run buildall

### What problem does this PR solve?

Problem Summary: Generated column expressions are substituted into dependent
columns before conversion to their declared types. For c BOOLEAN AS (a) and
d INT AS (c + 1), inserting a=2 stores c=1 but d=3. Cast each generated
expression before registering it for dependent columns so d uses the stored
value of c. Cover boolean and numeric chains, nulls, and insert paths.

### Release note

Fix incorrect values in generated columns that reference generated columns
with a different expression type from their declared type.

### Check List (For Author)

- Test: Manual test reproduced the incorrect result on the existing FE;
    regression tests added, execution pending remote FE build.
- Behavior changed: Yes, dependent generated columns use declared-type values.
- Does this need documentation: No
### What problem does this PR solve?

Problem Summary: Add generated expected results for declared-type dependency
chains and cover numeric chains through Stream Load using existing input data.
The tests compare generated values with expressions evaluated from stored
columns, including nulls, positive and negative values, INSERT VALUES,
INSERT SELECT, and INSERT OVERWRITE.

### Release note

None

### Check List (For Author)

- Test: Regression test - test_generated_column_declared_type,
    test_generated_column, and test_generated_column_update all passed on dev.
    Expected output generated by run-regression-test.sh. FE build and
    Checkstyle passed with DISABLE_BUILD_UI=ON; be_exec_version=13 matched BE.
    Manual test verified both reported examples on pre-existing tables.
- Behavior changed: No
- Does this need documentation: No
@feiniaofeiafei
feiniaofeiafei force-pushed the codex/fix-generated-column-declared-type branch from 220b9f4 to 536679d Compare September 11, 2026 02:40
@feiniaofeiafei

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 0.00% (0/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17593	3129	3091	3091
q2	2092	269	225	225
q3	10250	985	516	516
q4	4672	245	210	210
q5	7672	543	387	387
q6	137	114	94	94
q7	516	517	391	391
q8	9236	866	883	866
q9	3485	2396	2346	2346
q10	6551	848	719	719
q11	387	196	177	177
q12	619	275	195	195
q13	18104	1546	1166	1166
q14	165	147	143	143
q15	q16	440	396	372	372
q17	1296	819	808	808
q18	3104	2258	2211	2211
q19	1267	893	787	787
q20	395	289	203	203
q21	5660	1731	1864	1731
q22	337	265	228	228
Total cold run time: 93978 ms
Total hot run time: 16866 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3475	3424	3398	3398
q2	508	402	402	402
q3	2221	2280	2223	2223
q4	1174	1154	890	890
q5	2167	2095	2113	2095
q6	168	118	89	89
q7	1031	895	839	839
q8	1592	1399	1397	1397
q9	3108	3077	3073	3073
q10	1873	1796	1626	1626
q11	362	267	250	250
q12	462	425	340	340
q13	1482	1523	1165	1165
q14	180	169	162	162
q15	q16	387	397	376	376
q17	3527	3214	3224	3214
q18	4746	4367	4698	4367
q19	855	875	868	868
q20	1023	966	834	834
q21	3842	3125	3250	3125
q22	386	344	324	324
Total cold run time: 34569 ms
Total hot run time: 31057 ms

@hello-stephen

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

query5	4240	406	342	342
query6	388	133	123	123
query7	4951	391	230	230
query8	290	124	114	114
query9	8693	2890	2893	2890
query10	397	224	186	186
query11	5377	1035	938	938
query12	116	72	70	70
query13	1200	454	319	319
query14	6165	2201	2076	2076
query14_1	1972	1949	1960	1949
query15	175	121	111	111
query16	905	374	347	347
query17	794	461	369	369
query18	2327	327	233	233
query19	170	139	110	110
query20	84	69	69	69
query21	212	105	88	88
query22	5456	5251	5292	5251
query23	6749	6250	6060	6060
query23_1	6097	6008	6134	6008
query24	7258	1100	763	763
query24_1	771	748	740	740
query25	441	302	273	273
query26	1228	235	131	131
query27	2784	415	249	249
query28	4669	1499	1499	1499
query29	939	432	352	352
query30	247	155	130	130
query31	829	403	331	331
query32	136	75	80	75
query33	477	224	176	176
query34	1001	808	477	477
query35	405	397	354	354
query36	568	553	557	553
query37	123	81	69	69
query38	1006	843	809	809
query39	508	481	493	481
query39_1	452	457	448	448
query40	204	93	79	79
query41	60	55	54	54
query42	74	72	72	72
query43	245	247	212	212
query44	1013	528	547	528
query45	115	107	99	99
query46	754	832	522	522
query47	764	744	702	702
query48	318	327	269	269
query49	526	228	181	181
query50	754	257	192	192
query51	8072	7892	7913	7892
query52	69	65	63	63
query53	193	201	153	153
query54	207	167	142	142
query55	80	57	54	54
query56	186	168	194	168
query57	694	668	711	668
query58	198	150	160	150
query59	1239	1208	1124	1124
query60	241	173	173	173
query61	109	112	130	112
query62	379	218	181	181
query63	171	143	139	139
query64	2642	661	573	573
query65	1611	1605	1593	1593
query66	1876	290	207	207
query67	9789	9648	9559	9559
query68	2994	1188	734	734
query69	343	231	206	206
query70	683	653	611	611
query71	260	172	168	168
query72	2281	1626	1508	1508
query73	657	621	350	350
query74	2004	1240	1132	1132
query75	1166	1097	954	954
query76	2359	712	536	536
query77	256	243	208	208
query78	3810	3623	3154	3154
query79	2827	833	574	574
query80	1612	323	259	259
query81	537	154	135	135
query82	984	128	102	102
query83	276	217	197	197
query84	305	114	85	85
query85	821	336	290	290
query86	479	178	165	165
query87	1021	979	893	893
query88	2887	2121	2106	2106
query89	294	197	177	177
query90	2069	136	123	123
query91	134	116	96	96
query92	92	66	74	66
query93	2156	1038	664	664
query94	643	263	226	226
query95	525	311	226	226
query96	782	548	290	290
query97	1044	1049	1020	1020
query98	164	132	133	132
query99	425	338	300	300
Total cold run time: 179498 ms
Total hot run time: 81493 ms

@hello-stephen

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

query1	0.00	0.00	0.01
query2	0.07	0.03	0.03
query3	0.25	0.11	0.11
query4	1.60	0.10	0.10
query5	0.18	0.16	0.16
query6	1.24	0.71	0.66
query7	0.03	0.01	0.00
query8	0.04	0.03	0.03
query9	0.29	0.22	0.24
query10	0.37	0.34	0.38
query11	0.16	0.12	0.11
query12	0.15	0.12	0.12
query13	0.31	0.31	0.30
query14	0.44	0.45	0.45
query15	0.35	0.35	0.36
query16	0.23	0.22	0.20
query17	0.67	0.73	0.68
query18	0.18	0.16	0.16
query19	1.21	1.17	1.18
query20	0.02	0.01	0.01
query21	15.48	0.15	0.11
query22	5.09	0.04	0.04
query23	16.18	0.26	0.11
query24	2.99	0.33	0.22
query25	0.11	0.04	0.04
query26	0.75	0.16	0.12
query27	0.04	0.02	0.03
query28	3.50	0.54	0.28
query29	12.47	3.18	2.58
query30	0.26	0.11	0.12
query31	2.75	0.37	0.18
query32	3.53	0.32	0.23
query33	1.49	1.46	1.53
query34	15.36	2.15	1.77
query35	1.75	1.78	1.74
query36	0.46	0.30	0.29
query37	0.06	0.04	0.04
query38	0.05	0.03	0.03
query39	0.03	0.02	0.02
query40	0.12	0.08	0.07
query41	0.08	0.02	0.03
query42	0.03	0.03	0.02
query43	0.03	0.03	0.02
Total cold run time: 90.4 s
Total hot run time: 14.72 s

@feiniaofeiafei

Copy link
Copy Markdown
Collaborator Author

run cloud_p0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants