-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87606: sql: new heuristic-based completion engine r=rytaft,ZhouXing19 a=knz This PR extends the server-side completion logic available under SHOW COMPLETIONS. Fixes #37355. Intended for use together with #86457. The statement now returns 5 columns: completion, category, description, start, end. This change is backward-compatible with the CLI code in previous versions, which was not checking the number of columns. It works roughly as follows: 1. first the input is scanned into a token array. 2. then the token array is translated to a *sketch*: a string with the same length as the token array, where each character corresponds to an input token and an extra character indicating where the completion was requested. 3. then the completion rules are applied in sequence. Each rule inspects the sketch (and/or the token sequence) and decides whether to do nothing (skip to next rule), or to run some SQL which will return a batch of completion candidates. Each method operates exclusively on the token sequence, and does not require the overall SQL syntax to be valid or complete. Also, the completion engine executes in a streaming fashion, so that there is no need to accumulate all the completion candidates in RAM before returning them to the client. This prevents excessive memory usage server-side, and offers the client an option to cancel the search once enough suggestions have been received. Code organization: - new package `sql/compengine`: the core completion engine, also where sketches are computed. Suggested reading: `api.go` in the new package. - new package `sql/comprules`: the actual completion methods/heuristics, where sketches are mapped into SQL queries that provide the completion candidates. Suggested reading: the test cases under `testdata`. Some more words about sketches: For example, `SHOW COMPLETIONS AT OFFSET 10 FOR 'select myc from sc.mytable;'` produces the sketch `"ii'ii.i;"` where `i` indicates an identifier-like token and `'` indicates the cursor position. The purpose of the sketch is to simplify the pattern matching performed by the completion heuristics, and enables the application of regular expressions on the token sequence. For example, a heuristic to complete schema-qualified relations in the current database, or a database-qualified relation, would use the regexp `[^.;]i\.(['_]|i')`: an identifier not following a period or a semicolon, followed by a period, followed by the completion cursor (with the cursor either directly after the period or on an identifier after the period). Supersedes #45186. 93158: dev: fix bep temporary dir path r=rickystewart a=healthy-pod Release note: None Epic: none Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net> Co-authored-by: healthy-pod <ahmad@cockroachlabs.com>
- Loading branch information
Showing
64 changed files
with
3,869 additions
and
323 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.