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

[Bug] The better implementation of StatementParser #193

Open
2 tasks done
smm321 opened this issue Apr 23, 2024 · 0 comments
Open
2 tasks done

[Bug] The better implementation of StatementParser #193

smm321 opened this issue Apr 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@smm321
Copy link

smm321 commented Apr 23, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Paimon UI version

main

Compute Engine

Flink

Minimal reproduce step

Currently,org.apache.paimon.web.engine.flink.common.parser.StatementParser processes input strings in a 'split line Separator' way. It can't handle the statements which contain a line separator itself.

What doesn't meet your expectations?

In my option, a more graceful way to solve this issue is that we create a Calcite Sql Parser with a FlinkSqlParser Factory.

/**
 * CustomSqlParser to parse Sql list.
 */
public class CustomSqlParser {

    private static final SqlParser.Config config;
    private SqlParser parser;
    static {
        config = SqlParser.configBuilder()
                .setParserFactory(FlinkSqlParserImpl.FACTORY)
                .setConformance(FlinkSqlConformance.DEFAULT)
                .setLex(Lex.JAVA)
                .setIdentifierMaxLength(256)
                .build();
    }

    public CustomSqlParser(String sql){
        parser = SqlParser.create(sql, config);
    }

    public SqlParser getParser(){
        return parser;
    }
}

Then sqlParser can parse kinds of statements and return a sqlNodeList. The last thing we need to do is get the sqlKind of every sqlNode such as

CustomSqlParser customSqlParser = new CustomSqlParser(statementSetString);
SqlNodeList sqlNodeList = customSqlParser.getParser().parseStmtList();
for (SqlNode sqlNode : sqlNodeList) {
     System.out.println(sqlNode.getKind());
}

We just use AST level of Apache Calcite that do not need to validate if the tables or columns are legal or not

Anything else?

no

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@smm321 smm321 added the bug Something isn't working label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant