[Bug] The better implementation of StatementParser
- Dominant language
- Java
- Stars
- 147
- Forks
- 63
- PR merge metrics
- No merged PRs in 30d
Description
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/paimon-webui/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?
- [X] I'm willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.