...
Page properties |
---|
...
|
...
|
...
...
|
...
|
POC Demo: https://asciinema.org/a/446247?speed=3.0jira/browse/FLINK-XXXX)
Released: <Flink Version>
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
...
- line numbers + editing query consuming more than screen space
- autopairing[6] for single quote, sql identifier quote, square and round brackets could be turn on/off via property
(requires update at least till 3.13.3) - Enabling/Disabling description for completion candidates via property. An example how it looks like is here [7]
Prompts
Prompts should be configured via property: both left and right prompts.
Implementation Details
Parsing
The main idea is to extend existing org.apache.flink.table.client.cli.SqlMultiLineParser . => No need to use Flink SQL parser
It should check the input if all quotes, comments, hints, brackets (square and round) are closed otherwise it throws new EOFError - normal behavior in jline in case input should be continued on a new line.
During parsing need to keep track of cursor states if it is a comment, keyword, quoted string.
...
This track could be used to answer a question at what state parser by the end of a query.
Also such track , if there is with recorded state for every cursor position , could be used to do highlighting.
...
The first one allows to build completers for commands consisting of several words e.g. "BEGIN STATEMENT SET;" and the second one allows to unite them all together.
Cross dialect
Since there are at least 2 dialects in Flink (HIVE and DEFAULT). There could be a builtin dialect enum containing required info.
Taking current dialect it's possible to retrieve required info from that enum about quotes, comments and etc for parsing, highlighting and completion.
Code Block | ||||
---|---|---|---|---|
| ||||
public enum BuiltInDialect implements Dialect { DEFAULT("FlinkSQLDefaultDialect", () -> SqlAbstractParserImpl.getSql92ReservedWordskeywords(), '`', '\'', "\"", Pair.of("/*", "*/"), Pair.of("/*+", "*/"), "--"); private final Supplier<Set<String>> keywords; private final char quote; private final char sqlIdentifierQuote; private final Pair<String, String> blockComments; private final Pair<String, String> hints; private final String lineComments; ... } |
So that means that adding a new dialect should be relatively simple.
Summary
After this FLIP finishes, the sql client will have the options.
Supported options in sql client
...
'no'
...
Determine the color schema for syntax highlighting.
Will contain names of available color schemas
...
Determine whether autopairing is enabled or not.
...
Determine whether prompt shows hints about current input issue.
For more detailed about prompt values see Supported prompt hint values in sql client
...
Prompts
LineReader#readLine among other arguments has prompt and right prompt value.
Widgets
Jline allows to define widgets implementing org.jline.reader.Widget and bind them to key strokes.
Within a widget it is possible to define an action e.g. changing a property and invoke redisplay - this is how toggle of line numbers or switching highlight schema could be done
Summary
After this FLIP finishes, the sql client will have the options.
Supported options in sql client
Option | Default | Type | Description |
---|---|---|---|
sql-client.color-schema |
| Enum | Determine the color schema for syntax highlighting. Will contain names of available color schemas |
sql-client.autopairing | `true` | boolean | Determine whether autopairing is enabled or not. |
sql-client.completion-description | `false` | boolean | Determine whether description for completion candidates is enabled or not. |
sql-client.prompt.show-hint | `false` | boolean | Determine whether prompt shows hints about current input issue. For more detailed about prompt values see Supported prompt hint values in sql client |
sql-client.prompt.show-line-numbers | `false` | boolean | Determine whether prompt shows line numbers for multiline query. |
sql-client.prompt.mask | `default` | String | Determine a mask to build left prompt |
sql-client.rightprompt.mask | `default` | String | Determine a mask to build right prompt |
Supported prompt hint values in sql client
Prompt | Meaning |
---|---|
;> | Waiting for the next line of multi-line query, waiting for completion of query with semicolon (;) |
'> | Waiting for the next line, waiting for a completion of string that began with a single quote (') |
`> | Waiting for the next line, waiting for a completion of string that began with a back tick (`) |
*\> | Waiting for the next line, waiting for completion of a multi-line comment that began with (/*) |
)> | Waiting for the next line, waiting for completion of a string that began with a round bracket ( |
]> | Waiting for the next line, waiting for completion of a string that began with a square bracket [ |
extra )> | There is an extra round bracket ), that is not opened with ( |
extra ]> | There is an extra square bracket ], that is not opened with [ |
extra *\> | There is an extra closing of multi-line comment *\, that is not opened with \* |
Supported prompt options (both for left and right prompts)
Option | Description |
---|---|
\c | Current catalog |
\d | Current database |
\:property_name : | The value of Flink property_name property |
\[ ... \] | Prompts can contain terminal control characters which, for example, change the color, background, or style of the prompt text. These non-printing control characters must be designated as invisible by surrounding them with \[ and \]. Multiple pairs of these can occur within the prompt. |
\{...\} | Datetime pattern to convert current datetime. Compatible with Java’s SimpleDateFormat. |
\D | The full current date (yyyy-MM-dd HH:mm:ss.SSS) |
\m | Minutes of the current time |
\O | The current month in three-letter format (Jan, Feb, …) |
\o | The current month in numeric format |
\P | am/pm |
\R | The current time, in 24-hour military time (0–23) |
\r | The current time, standard 12-hour time (1–12) |
\s | Seconds of the current time |
\w | The current day of the week in three-letter format (Mon, Tue, …) |
\Y | The current year, four digits |
\y | The current year, two digits |
\\ | A literal \ backslash character |
\x |
|
Supported prompt hint values in sql client
Prompt | Meaning |
---|---|
;> | Waiting for the next line of multi-line query, waiting for completion of query with semicolon (;) |
'> | Waiting for the next line, waiting for a completion of string that began with a single quote (') |
`> | Waiting for the next line, waiting for a completion of string that began with a back tick (`) |
*\> | Waiting for the next line, waiting for completion of a multi-line comment that began with (/*) |
)> | Waiting for the next line, waiting for completion of a string that began with a round bracket ( |
]> | Waiting for the next line, waiting for completion of a string that began with a square bracket [ |
extra )> | There is an extra round bracket ), that is not opened with ( |
extra ]> | There is an extra square bracket ], that is not opened with [ |
extra *\> | There is an extra closing of multi-line comment *\, that is not opened with \*
Compatibility, Deprecation, and Migration Plan
...