zhaorongsheng opened a new pull request, #64007:
URL: https://github.com/apache/doris/pull/64007
## Problem
When querying a Doris view built with `SELECT *` over an external-catalog
table (e.g. Hive), after the underlying table gains new columns via `ALTER
TABLE ADD COLUMNS` + `REFRESH TABLE <base_table>`, the query crashes with:
```
errCode = 2, detailMessage = Index 3 out of bounds for length 3
```
**Root cause** (`LogicalView.computeOutput()`):
The view body is re-analyzed against the refreshed base-table schema (4
columns), producing `childOutput` with 4 slots. But `view.getFullSchema()`
still returns 3 columns (the schema stored at view-creation time in the Hive
metastore – not yet refreshed). The loop runs `i = 0..3` and calls
`view.getFullSchema().get(3)`, crashing.
The `CollectionUtils.isEmpty()` guard added in #40715 handles the
`null`/empty case but not the under-sized case.
## Fix
Promote `view.getFullSchema()` to a local variable to avoid repeated calls,
then extend the guard to `i >= fullSchema.size()`:
```java
List<Column> fullSchema = view.getFullSchema();
if (CollectionUtils.isEmpty(fullSchema) || i >= fullSchema.size()) {
qualified = originSlot.withQualifier(fullQualifiers); // same as
existing null-guard path
} else {
qualified = originSlot
.withOneLevelTableAndColumnAndQualifier(view, fullSchema.get(i),
fullQualifiers);
}
```
Extra slots (columns added after view creation) fall back to
`withQualifier()`, preserving the correct column name/type from the child slot
(which is already resolved against the refreshed catalog). No behavioral change
for non-drifted views.
## Files Changed
| File | Change |
|------|--------|
|
`fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalView.java`
| Fix + import `Column` |
|
`regression-test/suites/external_table_p0/hive/test_hive_view_schema_drift.groovy`
| New regression test |
## Test Plan
- [x] New regression test `test_hive_view_schema_drift` (suite
`p0,external,hive_docker`):
- Creates a 3-column Hive table + Doris view (`SELECT *`)
- Verifies view query succeeds before schema drift
- Adds a 4th column via `ALTER TABLE ADD COLUMNS`
- Refreshes the base table (`REFRESH TABLE`)
- Asserts the view query does **not** throw (regression guard)
- [ ] Existing `test_hive_view` suite — no regressions expected
## Issue
Fixes: #64006
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]