apache / apache/doris

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

Open
#66,041 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
15.9k
Forks
3.9k
Avg merge
2d 23h
Merged PRs (30d)
520

Description

### Search before asking

- [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) 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

- [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)

Contributor guide

Open the contributing guide

Research direction

Start at BindRelation.bindRelation in the HMS_EXTERNAL_TABLE case and inspect how LogicalSubQueryAlias is constructed, then read HMSExternalTable.getFullSchema() and LogicalSubQueryAlias.computeOutput(). Reproduce the Hive view query with declared columns col1 and col2 but body aliases a and b; done means the outer query resolves the declared names without a "find no column" error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.