Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. line numbers + editing query consuming more than screen space
  2. 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) 
  3. Enabling/Disabling description for completion candidates via property. An example how it looks like is here [7]

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 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 recorded state for every cursor position, could be used to do highlighting.

Highlighting

To do highlighting it is necessary to implement  org.jline.reader.impl.DefaultHighlighter.
From parser it could receive a track of state for each position and do highlighting.
Colors for different states are going to be defined in a separate SyntaxHighlightStyle class.

...

Code Block
java
java
public enum BuiltInStyle {
        DEFAULT(null, null, null, null, null, null, null, null),
        DARK(BOLD_BLUE, WHITE, ITALIC_GREEN, ITALIC_GREEN, BOLD_GREEN, YELLOW, RED, MAGENTA),
        LIGHT(BOLD_RED, WHITE, ITALIC_CYAN, ITALIC_CYAN, BOLD_CYAN, YELLOW, GREEN, MAGENTA);
        private final SyntaxHighlightStyle style;

        BuiltInStyle(
                AttributedStyle keywordStyle,
                AttributedStyle defaultStyle,
                AttributedStyle blockCommentStyle,
                AttributedStyle lineCommentStyle,
                AttributedStyle hintStyle,
                AttributedStyle numberStyle,
                AttributedStyle singleQuotedStyle,
                AttributedStyle sqlIdentifierStyle) {
            style =
                    new SyntaxHighlightStyle(
                            blockCommentStyle,
                            lineCommentStyle,
                            hintStyle,
                            defaultStyle,
                            keywordStyle,
                            numberStyle,
                            singleQuotedStyle,
                            sqlIdentifierStyle);
        }

Cross dialect

Since there are at least 2 dialects in Flink (HIVE and DEFAULT). There could be a builtin dialect enum containing required info

Code Block
java
java
public enum BuiltInDialect implements Dialect {
  DEFAULT("FlinkSQLDefaultDialect", () -> SqlAbstractParserImpl.getSql92ReservedWords(), '`', '\'', "\"", 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.

...