Add a scalar function that takes a unfinished SQL statements and returns completion suggestions
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 616
- Avg merge
- 14h 49m
- Merged PRs (30d)
- 206
Description
## Use case
Extending both the AdminUI and crash with semantic aware auto-completion, which
uses a server to suggest schemas, tables, functions and keywords.
This could be done on the client side, but doing it in CrateDB itself has the
advantage that not every client needs to re-implement the logic.
## Feature description
For editors there is the [Language server
protocol](https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/)
that specifies a protocol for how a server can communicate with a client to
provide rich features like autocomplete, goto definition and so on.
But for the use case described above adding a LSP implementation into CrateDB
seems overkill. For crash or AdminUI editing session there is no workspace with
files and so on.
An alternative could be a scalar function that takes a statement, line number
and column number and returns rows with completion candidates.
The line number and column number would be for cases where a user modifies a statement:
```sql
SELECT
foo,
bar.|
FROM
tbl
```
`|` indicates the cursor position.
## First step
This is what the estimate is about.
- [ ] Next keywords based on ANTLR4 grammar / tokenizer
## Follow ups
- [ ] Schema names
- [ ] Table names
- [ ] Column names
- [ ] Scalar functions
- [ ] Available settings in different contexts. (SET, WITH clauses)
## Resources
- https://github.com/oranoran/antlr4-autosuggest
- https://blog.rapid7.com/2015/06/29/how-to-implement-antlr4-autocomplete/
- https://tomassetti.me/autocompletion-editor-antlr/
- https://dev.to/bytebase/how-we-built-the-sql-autocomplete-framework-with-antlr4-a3p
Contributor guide
Assessment
This issue has not been assessed yet.