Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Expose tableProperty #391

Open
ekazakas opened this issue Jan 24, 2025 · 1 comment
Open

[Feature Request]: Expose tableProperty #391

ekazakas opened this issue Jan 24, 2025 · 1 comment

Comments

@ekazakas
Copy link

ekazakas commented Jan 24, 2025

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
   [[Prototype]] = Array(0)
  [[Prototype]] = Object
 length = 1
 [[Prototype]] = 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'.

@JackWang032
Copy link
Collaborator

When the antlr4-c3 engine collects rule context, if it matches a rule defined by 'preferredRules', it will directly return it.
So you need to remove FlinkSqlParser.RULE_tablePropertyList and FlinkSqlParser.RULE_tableProperty, they will include in ruleList when c3 collect RULE_tablePropertyKey .

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants