Skip to content

[Feature Request]: Expose tableProperty #391

Closed
@ekazakas

Description

@ekazakas
Contributor

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'.

Activity

JackWang032

JackWang032 commented on Jan 24, 2025

@JackWang032
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
ekazakas

ekazakas commented on Jan 27, 2025

@ekazakas
ContributorAuthor

Thanks for the suggestions @JackWang032 I have made a PR to improve Flink suggestions: #392

mumiao

mumiao commented on May 16, 2025

@mumiao
Collaborator

released: v4.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @ekazakas@mumiao@JackWang032

      Issue actions

        [Feature Request]: Expose tableProperty · Issue #391 · DTStack/dt-sql-parser