Skip to content

[fix](fe) pass Hive view column aliases so outer query can resolve view columns#66042

Open
Baymine wants to merge 1 commit into
apache:masterfrom
Baymine:fix/hive-view-column-aliases
Open

[fix](fe) pass Hive view column aliases so outer query can resolve view columns#66042
Baymine wants to merge 1 commit into
apache:masterfrom
Baymine:fix/hive-view-column-aliases

Conversation

@Baymine

@Baymine Baymine commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #66041

Problem Summary: When querying a Hive view through the Nereids optimizer, the
outer query could fail with a "find no column" error whenever the view's
declared column schema diverged from the slot names produced by the parsed
view body. The root cause is in BindRelation.bindRelation for the
HMS_EXTERNAL_TABLE case: the resulting LogicalSubQueryAlias was built
with the 2-arg constructor, which leaves columnAliases empty. Its
computeOutput() then fell back to the child (view-body) slot names instead
of the view's declared schema, so an outer query that referenced the view
columns by their declared names could not resolve them.

The fix passes the view's declared schema (from HMSExternalTable.getFullSchema())
as columnAliases to the 3-arg LogicalSubQueryAlias constructor.
computeOutput() already honors columnAliases to rename the output slots,
so the outer query now resolves view columns by the view definition.

This is a hand-port of an internal fix; JD-only helpers (an internal auth
context and a view-SQL transformer) were intentionally dropped.

Release note

Fixed a "find no column" error when querying certain Hive views whose declared column names differ from the view body slot names.

Check List (For Author)

  • Test: Unit Test
    • Added BindRelationTest.bindHiveViewPropagatesColumnAliases: drives the
      real BindRelation rule over a spied HMSExternalTable view whose
      declared schema (col1,col2) deliberately differs from the view body
      slot names (a,b), and asserts the resulting LogicalSubQueryAlias
      carries the schema as columnAliases and that computeOutput() slot
      names equal [col1,col2].
    • Ran run-fe-ut.sh --run BindRelationTest: 7 tests run, 0 failures,
      0 errors, 0 skipped (locally green).
  • Behavior changed: Yes — Hive view output columns are now renamed to match
    the view's declared schema (previously kept the view-body slot names).
  • Does this need documentation: No

…ew columns

### What problem does this PR solve?

Issue Number: close apache#66041

Problem Summary: When querying a Hive view through the Nereids optimizer, the
outer query could fail with a "find no column" error whenever the view's
declared column schema diverged from the slot names produced by the parsed
view body. The root cause is in `BindRelation.bindRelation` for the
`HMS_EXTERNAL_TABLE` case: the resulting `LogicalSubQueryAlias` was built
with the 2-arg constructor, which leaves `columnAliases` empty. Its
`computeOutput()` then fell back to the child (view-body) slot names instead
of the view's declared schema, so an outer query that referenced the view
columns by their declared names could not resolve them.

The fix passes the view's declared schema (from `HMSExternalTable.getFullSchema()`)
as `columnAliases` to the 3-arg `LogicalSubQueryAlias` constructor.
`computeOutput()` already honors `columnAliases` to rename the output slots,
so the outer query now resolves view columns by the view definition.

This is a hand-port of an internal fix; JD-only helpers (an internal auth
context and a view-SQL transformer) were intentionally dropped.

### Release note

Fixed a "find no column" error when querying certain Hive views whose declared column names differ from the view body slot names.

### Check List (For Author)

- Test: Unit Test
    - Added `BindRelationTest.bindHiveViewPropagatesColumnAliases`: drives the
      real `BindRelation` rule over a spied `HMSExternalTable` view whose
      declared schema (`col1,col2`) deliberately differs from the view body
      slot names (`a,b`), and asserts the resulting `LogicalSubQueryAlias`
      carries the schema as `columnAliases` and that `computeOutput()` slot
      names equal `[col1,col2]`.
    - Ran `run-fe-ut.sh --run BindRelationTest`: 7 tests run, 0 failures,
      0 errors, 0 skipped (locally green).
- Behavior changed: Yes — Hive view output columns are now renamed to match
  the view's declared schema (previously kept the view-body slot names).
- Does this need documentation: No
@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?

@Baymine

Baymine commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17678	4048	4024	4024
q2	2032	323	204	204
q3	10322	1429	800	800
q4	4715	468	335	335
q5	7794	826	560	560
q6	211	167	137	137
q7	763	792	595	595
q8	10254	1332	1512	1332
q9	5896	4315	4316	4315
q10	6781	1733	1471	1471
q11	525	348	313	313
q12	729	583	442	442
q13	18192	3327	2756	2756
q14	272	259	233	233
q15	q16	777	769	707	707
q17	1062	993	930	930
q18	7016	5624	5688	5624
q19	1746	1366	1097	1097
q20	754	683	580	580
q21	5912	2565	2336	2336
q22	426	353	292	292
Total cold run time: 103857 ms
Total hot run time: 29083 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4381	4273	4283	4273
q2	279	322	216	216
q3	4560	4969	4400	4400
q4	2086	2148	1361	1361
q5	4357	4252	4280	4252
q6	233	176	125	125
q7	1729	2092	1623	1623
q8	2470	2162	2038	2038
q9	7774	7817	7719	7719
q10	4693	4757	4226	4226
q11	592	412	387	387
q12	740	762	537	537
q13	3285	3540	2930	2930
q14	315	313	292	292
q15	q16	735	754	656	656
q17	1403	1298	1296	1296
q18	8015	7297	7119	7119
q19	1088	1054	1109	1054
q20	2225	2209	1919	1919
q21	5182	4521	4411	4411
q22	516	467	412	412
Total cold run time: 56658 ms
Total hot run time: 51246 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 177449 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 9732b1957812bfab160a38c9911a608b7795845a, data reload: false

query5	4325	635	476	476
query6	478	221	213	213
query7	4847	561	324	324
query8	331	190	165	165
query9	8776	4077	4089	4077
query10	487	360	323	323
query11	5931	2332	2179	2179
query12	177	113	102	102
query13	1314	578	427	427
query14	6280	5228	4876	4876
query14_1	4268	4242	4214	4214
query15	217	207	180	180
query16	1063	456	447	447
query17	1153	706	580	580
query18	2486	484	350	350
query19	217	192	154	154
query20	114	112	115	112
query21	234	163	136	136
query22	13627	13593	13379	13379
query23	17435	16457	16114	16114
query23_1	16283	16223	16243	16223
query24	7751	1720	1285	1285
query24_1	1305	1287	1274	1274
query25	572	465	394	394
query26	1338	361	218	218
query27	2576	592	372	372
query28	4964	2022	1995	1995
query29	1101	607	489	489
query30	349	260	224	224
query31	1112	1096	986	986
query32	106	64	65	64
query33	530	329	253	253
query34	1200	1121	645	645
query35	790	795	668	668
query36	1192	1221	1020	1020
query37	159	110	92	92
query38	1884	1714	1626	1626
query39	917	868	841	841
query39_1	855	845	839	839
query40	247	206	144	144
query41	66	63	68	63
query42	92	92	92	92
query43	323	339	276	276
query44	1404	762	763	762
query45	194	181	172	172
query46	1056	1178	714	714
query47	2183	2103	2027	2027
query48	411	384	274	274
query49	572	422	298	298
query50	1030	440	338	338
query51	10800	10653	10444	10444
query52	87	86	76	76
query53	254	274	200	200
query54	290	224	241	224
query55	74	68	64	64
query56	293	304	309	304
query57	1346	1315	1185	1185
query58	276	232	242	232
query59	1599	1664	1456	1456
query60	312	263	252	252
query61	158	151	151	151
query62	557	501	431	431
query63	238	196	199	196
query64	2799	1022	874	874
query65	4736	4627	4644	4627
query66	1850	517	375	375
query67	28523	29213	29131	29131
query68	3120	1514	970	970
query69	405	306	266	266
query70	1085	943	971	943
query71	381	343	302	302
query72	3018	2659	2340	2340
query73	876	767	435	435
query74	5065	4857	4691	4691
query75	2532	2506	2139	2139
query76	2345	1152	742	742
query77	354	395	290	290
query78	11965	11943	11369	11369
query79	1431	1183	776	776
query80	1305	555	475	475
query81	542	337	280	280
query82	682	156	118	118
query83	365	325	300	300
query84	280	154	130	130
query85	982	620	527	527
query86	429	290	285	285
query87	1843	1822	1755	1755
query88	3709	2772	2774	2772
query89	444	401	334	334
query90	1907	206	200	200
query91	202	191	167	167
query92	63	58	53	53
query93	1704	1564	969	969
query94	765	340	310	310
query95	786	487	451	451
query96	1108	865	348	348
query97	2655	2651	2520	2520
query98	214	207	201	201
query99	1092	1128	976	976
Total cold run time: 264557 ms
Total hot run time: 177449 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.05	0.04
query3	0.25	0.13	0.13
query4	1.61	0.13	0.13
query5	0.24	0.23	0.22
query6	1.27	1.05	1.07
query7	0.04	0.01	0.00
query8	0.06	0.04	0.04
query9	0.38	0.32	0.31
query10	0.57	0.54	0.52
query11	0.18	0.13	0.14
query12	0.19	0.15	0.14
query13	0.47	0.47	0.48
query14	1.00	1.00	1.01
query15	0.63	0.60	0.59
query16	0.33	0.31	0.34
query17	1.13	1.12	1.16
query18	0.24	0.21	0.21
query19	2.08	2.05	1.92
query20	0.02	0.01	0.01
query21	15.42	0.18	0.13
query22	4.95	0.05	0.05
query23	16.18	0.31	0.12
query24	2.84	0.39	0.32
query25	0.12	0.06	0.04
query26	0.72	0.21	0.16
query27	0.06	0.04	0.04
query28	3.53	0.97	0.53
query29	12.48	4.09	3.27
query30	0.27	0.16	0.16
query31	2.77	0.57	0.31
query32	3.23	0.60	0.49
query33	3.23	3.26	3.16
query34	15.53	4.18	3.52
query35	3.56	3.53	3.52
query36	0.58	0.44	0.46
query37	0.09	0.07	0.07
query38	0.06	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.17	0.16
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 96.81 s
Total hot run time: 24.99 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (5/5) 🎉
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.

[Bug] "find no column" error when querying a Hive view whose declared column names differ from the view body

2 participants