seawinde opened a new pull request, #62907:
URL: https://github.com/apache/doris/pull/62907
### What problem does this PR solve?
Issue Number: N/A (internal JIRA OPENSOURCE-318)
Related PR: N/A
Problem Summary:
`CREATE VIEW` with Nereids could persist wrong SQL when the view definition
used dotted `VARIANT` subfield access such as `event_value.video_id`. The buggy
persisted SQL replaced the whole subfield expression with the base column
`event_value`, so querying the view could return `0` rows while the same CTE
queried directly returned `1` row.
Reproduction steps:
1. Create an `events` table with `event_value VARIANT<'video_id':largeint,
'duration':bigint>` and `user_connect_info VARIANT<'user_client':text>`.
2. Insert one `watch_time` row where `event_value.video_id = 100`,
`event_value.duration = 15000`, and `user_connect_info.user_client = 'ios'`.
3. Create a view with a CTE that projects `CAST(event_value.video_id AS
LARGEINT)`, `TRY_CAST(event_value.duration AS INT)`, joins `video_meta`, and
aggregates the result.
4. Query the view with `SELECT COUNT(*) FROM v_bug` and `SELECT COUNT(*)
FROM v_bug WHERE event_day >= '2026-04-20'`.
5. On a buggy build both view queries return `0`; on the fixed build both
return `1`. `SHOW CREATE VIEW` also keeps ``event_value`.`video_id`` instead of
losing the subfield path.
Root cause: In `ExpressionAnalyzer.bindExpressionByColumn()` and the
qualified variants (`bindExpressionByTableColumn()`,
`bindExpressionByDbTableColumn()`, `bindExpressionByCatalogDbTableColumn()`),
the analyzer attached SQL-index rewrite metadata to the base `SlotReference`
before `bindNestedFields()` handled the dotted subfield path. After binding
`event_value.video_id` into `ElementAt(SlotReference(event_value),
'video_id')`, the base slot still owned the original SQL span for the whole
`event_value.video_id` text. The create-view SQL rewrite later replaced that
span with the fully qualified base column only, changing the view definition
semantics.
| File | Change Description |
|------|-------------------|
|
`fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java`
| Delays `addSqlIndexInfo()` until the analyzer knows the reference is an
ordinary slot path. For successfully bound nested fields, records a fully
qualified dotted replacement that includes the base column and all nested field
names. |
|
`regression-test/suites/ddl_p0/create_view_nereids/test_create_view_variant_nested_field.groovy`
| Adds regression coverage for `CREATE VIEW`, `ALTER VIEW`, bracket-style
access, and the CTE/join/aggregation shape from the JIRA reproduction. The test
queries the created view directly and verifies the row count remains `1`. |
Design rationale: This is fixed in expression analysis instead of
`BaseViewInfo.SlotDealer` because `ExpressionAnalyzer` is where the dotted name
is resolved into a nested-field expression and where the original SQL span is
still available with semantic context. `SlotDealer` only sees later slot
references during view SQL rewrite, so fixing it there would require guessing
whether a base slot originated from a nested-field path. Delaying base-slot
rewrite metadata and adding explicit nested-field rewrite metadata keeps
ordinary column behavior unchanged while preserving `VARIANT` subfield
semantics in view definitions.
### Release note
Fixed an issue where `CREATE VIEW` or `ALTER VIEW` could lose dotted
`VARIANT` subfield paths in persisted view SQL, causing later queries on the
view to return incorrect results.
### Check List (For Author)
- Test
- [x] Regression test
- [ ] Unit Test
- [x] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
Manual test:
```bash
./run-regression-test.sh --run -f
regression-test/suites/ddl_p0/create_view_nereids/test_create_view_variant_nested_field.groovy
mysql -h 127.0.0.1 -P 9030 -u root --table <
codex_jira_analysis_outputs/OPENSOURCE-318/min-repro.sql
```
Manual result:
```text
direct_cte cnt = 1
view_all cnt = 1
view_filtered cnt = 1
```
- Behavior changed:
- [x] No.
- [ ] Yes.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]