Skip to content

[Feature Request]: Expose tableProperty #391

Open
@ekazakas

Description

@ekazakas

Topic

Enhance existing features

Description

Greetings.

Current Flink parser has defined rules for:

  • tablePropertyList
  • tableProperty
  • tablePropertyKey
  • tablePropertyValue

Would it be possible to expose them as?

  • EntityContextType.TABLE_PROPERTY_LIST
  • EntityContextType.TABLE_PROPERTY
  • EntityContextType.TABLE_PROPERTY_KEY
  • EntityContextType.TABLE_PROPERTY_VALUE

============================

I have tried to modify the prefferedRules for FlinkSQL, e.g.:

    protected preferredRules = new Set([
<...>
        FlinkSqlParser.RULE_columnNameCreate,
        FlinkSqlParser.RULE_tablePropertyList,
        FlinkSqlParser.RULE_tableProperty,
        FlinkSqlParser.RULE_tablePropertyKey,
        FlinkSqlParser.RULE_tablePropertyValue,
    ]);

and then updated processCandidates with:

                case FlinkSqlParser.RULE_tablePropertyList: {
                    syntaxContextType = EntityContextType.TABLE_PROPERTY_LIST;
                    break;
                }
                case FlinkSqlParser.RULE_tableProperty: {
                    syntaxContextType = EntityContextType.TABLE_PROPERTY;
                    break;
                }
                case FlinkSqlParser.RULE_tablePropertyKey: {
                    syntaxContextType = EntityContextType.TABLE_PROPERTY_KEY;
                    break;
                }
                case FlinkSqlParser.RULE_tablePropertyValue: {
                    syntaxContextType = EntityContextType.TABLE_PROPERTY_VALUE;
                    break;
                }

Then ran a small test:

    test('Dummy', () => {
        const tokenSql = `CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');`;
        const pos: CaretPosition = {
            lineNumber: 1,
            column: 45,
        };

        const suggestion = flink.getSuggestionAtCaretPosition(tokenSql, pos);
        console.log(suggestion?.keywords);
        console.log(suggestion?.syntax);
    });

But for some reason getSuggestionAtCaretPosition returns only the RULE_tablePropertyList, even if the carret is on tablePropertyKey.

Debug output:

suggestion?.syntax = Array(1) [{…}]
 0 = Object {syntaxContextType: "tablePropertyList",
wordRanges: Array(2)}
  syntaxContextType = "tablePropertyList"
  wordRanges = Array(2) [{…},
{…}]
   0 = Object {text: "(",
line: 1,
startIndex: 38,
endIndex: 38,
startColumn: 39,
...}
   1 = Object {text: "'connector'",
line: 1,
startIndex: 39,
endIndex: 49,
startColumn: 40,
...}
   length = 2
   [[]] = Array(0)
  [[]] = Object
 length = 1
 [[]] = Array(0)
this = undefined

If someone could point me in the right direction why it suggests tablePropertyList instead of tablePropertyKey, I could make a PR contribution, so that the library will be able to provide contextual information about table properties. This can become very useful to implement custom suggestions later on in editors like monaco. E.g.: suggest list of Kafka topics from some external storage if tableProperyKey = 'topic'.

Metadata

Metadata

Labels

help wantedExtra attention is neededimprovementImprove existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions