[editor] Support autocomplete for CTE tables#4342
Open
alexandrefimov wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Fixes #3553.
This PR adds autocomplete support for columns exposed by common table expressions (CTEs), e.g.:
The autocomplete runtime can now resolve CTE relations and suggest projected columns from the CTE instead of treating the CTE name as an unresolved physical table.
Supported cases
WITH t1 AS (SELECT id, name FROM foo) SELECT | FROM t1WITH t1 AS (...) SELECT t1.| FROM t1SELECT *expansion from CTE source tablesWITH t1 AS (...), t2 AS (SELECT * FROM t1) SELECT | FROM t2WITH t1 (cte_id, cte_name) AS (...) SELECT | FROM t1VALUESCTEs with explicit column aliasesImplementation notes
The parser now surfaces CTE column alias metadata through
commonTableExpressions.The autocomplete runtime uses a shared CTE resolver in
cteAutocompleteUtils.ts, used by both:sql/autocompleteResults.jsAutocompleteResults.tsThe resolver handles CTE lookup, source column expansion, explicit alias replacement, chained CTEs, type filtering, and recursion protection.
Why is this PR relatively large?
Most of the diff is generated parser output. Hue keeps generated autocomplete/syntax parser files checked into the repository, so the
.jisongrammar changes regenerate parser files for:Generated parser files account for most of the changed lines. The main hand-written review surface is concentrated in:
desktop/core/src/desktop/js/parse/sql/generic/jison/select/cte_column_aliases.jisondesktop/core/src/desktop/js/parse/sql/hive/jison/sql_main.jisondesktop/core/src/desktop/js/sql/cteAutocompleteUtils.tsdesktop/core/src/desktop/js/sql/autocompleteResults.jsdesktop/core/src/desktop/js/apps/editor/components/aceEditor/autocomplete/AutocompleteResults.tsReviewers can focus primarily on the grammar changes, CTE resolver, runtime integration, and tests. The generated parser files are included to keep checked-in parser output in sync.
Test plan
npm run test -- \ desktop/core/src/desktop/js/sql/autocompleteResults.test.js \ desktop/core/src/desktop/js/apps/editor/components/aceEditor/autocomplete/AutocompleteResults.test.ts \ desktop/core/src/desktop/js/parse/sql/generic/genericAutocompleteParser.test.ts \ desktop/core/src/desktop/js/parse/sql/generic/genericSyntaxParser.test.js \ desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Select.test.js \ desktop/core/src/desktop/js/parse/sql/impala/test/impalaAutocompleteParser.Select.test.js \ --runInBandResult: 6 suites passed, 1716 tests passed, 8 skipped.