[Bug] "find no column" error when querying a Hive view whose declared column names differ from the view body
Search before asking
- [x] I had searched in the issues and found no similar issues.
Version
master / 4.0
What's Wrong?
When querying a Hive view through the Nereids optimizer (with enable_query_hive_views = true), the outer query can fail with a "find no column" error whenever the view's declared column schema diverges from the slot names produced by the parsed view body.
Root cause: in BindRelation.bindRelation for the HMS_EXTERNAL_TABLE case, the resulting LogicalSubQueryAlias is built with the 2-arg constructor, which leaves columnAliases empty. Its computeOutput() then falls back to the child (view-body) slot names instead of the view's declared schema, so an outer query that references the view columns by their declared names cannot resolve them.
What You Expected?
Querying a Hive view should resolve columns by the view's declared schema, regardless of the slot names used inside the view body.
How to Reproduce?
- Create a Hive view whose declared column names differ from the aliases in the view's
SELECTbody (e.g. the view is declared with columnscol1, col2but its body isSELECT 1 AS a, 2 AS b). - With
enable_query_hive_views = true, query the view from Doris:SELECT col1, col2 FROM hms_catalog.db.view_name. - Observe a "find no column" error.
Anything Else?
Fix: pass the view's declared schema (HMSExternalTable.getFullSchema()) as columnAliases to the 3-arg LogicalSubQueryAlias constructor. computeOutput() already honors columnAliases to rename the output slots, so the outer query then resolves view columns by the view definition.
Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Breakwater-GitHub-Analysis-Slot: slot_5d2be5e6b388
Initial assessment
Confirmed as a genuine FE/Nereids column-binding bug. The reported mechanism is present in both current master and branch-4.0.
The relevant path is:
BindRelationparses an enabled Hive view into aLogicalView, then wraps it innew LogicalSubQueryAlias<>(qualifiedTableName, hiveViewPlan).LogicalView.computeOutput()attaches the declared view column as one-level metadata, butSlotReference.withOneLevelTableAndColumnAndQualifier()deliberately preserves the slot's existingname. Thus a body such asSELECT 1 AS a, 2 AS bstill exposes slot namesa, bat this point even when the HMS schema iscol1, col2.- The two-argument
LogicalSubQueryAliasconstructor leavescolumnAliasesempty.computeOutputInternal()consequently falls back to those child names, so the outer binder cannot resolvecol1orcol2.
This is deterministic and does not require runtime logs or a query profile to establish. The impact is an analysis failure for HMS views whose declared names differ from their view-body output names; SELECT * can mask the binding failure, while explicit references to the declared names fail. There is no indication of data corruption.
The issue currently has no labels. Suggested triage is an FE/Nereids external-catalog correctness bug.
Fix assessment
The implementation direction in #66042 is correct: derive the aliases positionally from HMSExternalTable.getFullSchema() and pass them to the three-argument LogicalSubQueryAlias constructor. That constructor already preserves the child expression IDs and types while replacing the exposed names, which restores the Hive view's declared output contract.
One edge case should be handled deliberately before merge: HMSExternalTable.getFullSchema() can return null when the schema cache has no value, and LogicalView.computeOutput() currently tolerates null/empty schemas. Calling .stream() unconditionally in the new path would turn that condition into an NPE. Please preserve the existing fallback behavior or emit an intentional user-facing analysis error.
Missing information
No additional reporter information is required to confirm the root cause. For release/backport tracking only, the exact affected 4.0 maintenance build or commit would be useful.
I did not independently run the FE unit test locally because the repository's required thirdparty/installed/bin/protoc executable is absent; the conclusion above is based on direct inspection of the affected code on both branches. The PR reports a focused BindRelationTest passing locally.
Recommended next steps
- Review #66042 with the null/empty-schema case addressed.
- Keep the focused alias-output assertion and add an analyzer-level assertion for
SELECT col1, col2 FROM ...; also verify thatSELECT a, b FROM ...is rejected so the declared schema remains the sole public contract. - Verify
SELECT *exposescol1, col2and retains the expected view column metadata. - After the master fix is validated, backport it to the supported 4.0 branch.
- Audit the Iceberg-view branch in the same
BindRelationswitch: it also wrapsparseAndAnalyzeExternalView(...)with the two-argumentLogicalSubQueryAliasconstructor and may have the same issue if Iceberg declared view names can diverge from body slot names.