doris icon indicating copy to clipboard operation
doris copied to clipboard

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

Open Baymine opened this issue 4 months ago • 1 comments

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?

  1. Create a Hive view whose declared column names differ from the aliases in the view's SELECT body (e.g. the view is declared with columns col1, col2 but its body is SELECT 1 AS a, 2 AS b).
  2. With enable_query_hive_views = true, query the view from Doris: SELECT col1, col2 FROM hms_catalog.db.view_name.
  3. 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

Baymine avatar Jul 25 '26 08:07 Baymine

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:

  1. BindRelation parses an enabled Hive view into a LogicalView, then wraps it in new LogicalSubQueryAlias<>(qualifiedTableName, hiveViewPlan).
  2. LogicalView.computeOutput() attaches the declared view column as one-level metadata, but SlotReference.withOneLevelTableAndColumnAndQualifier() deliberately preserves the slot's existing name. Thus a body such as SELECT 1 AS a, 2 AS b still exposes slot names a, b at this point even when the HMS schema is col1, col2.
  3. The two-argument LogicalSubQueryAlias constructor leaves columnAliases empty. computeOutputInternal() consequently falls back to those child names, so the outer binder cannot resolve col1 or col2.

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

  1. Review #66042 with the null/empty-schema case addressed.
  2. Keep the focused alias-output assertion and add an analyzer-level assertion for SELECT col1, col2 FROM ...; also verify that SELECT a, b FROM ... is rejected so the declared schema remains the sole public contract.
  3. Verify SELECT * exposes col1, col2 and retains the expected view column metadata.
  4. After the master fix is validated, backport it to the supported 4.0 branch.
  5. Audit the Iceberg-view branch in the same BindRelation switch: it also wraps parseAndAnalyzeExternalView(...) with the two-argument LogicalSubQueryAlias constructor and may have the same issue if Iceberg declared view names can diverge from body slot names.

Doris-Breakwater avatar Jul 25 '26 08:07 Doris-Breakwater