Following is the configuration that I'm using to parse MySQL statements. I am able to parse and process DML statements fine but I can't seem to parse any DDL statements (CREATE TABLE, ALTER TABLE, DROP TABLE, etc.).
public static SqlNode parse(String query) {
SqlParser.Config sqlParserConfig = SqlParser.configBuilder()
.setConformance(SqlConformanceEnum.MYSQL_5)
.setLex(Lex.MYSQL)
.build();
SqlParser parser = SqlParser.create(query, sqlParserConfig);
try {
return parser.parseStmt();
} catch (SqlParseException e) {
lastErrorMessage = e.getMessage();
return null;
}
}
When I try to parse a CREATE TABLE
statement, it gives me the following error message.
Encountered "ALTER TABLE" at line 1, column 1.
Was expecting one of:
"SET" ...
"RESET" ...
"ALTER" "SYSTEM" ...
"ALTER" "SESSION" ...
"WITH" ...
"+" ...
"-" ...
"NOT" ...
"EXISTS" ...
<UNSIGNED_INTEGER_LITERAL> ...
<DECIMAL_NUMERIC_LITERAL> ...
<APPROX_NUMERIC_LITERAL> ...
<BINARY_STRING_LITERAL> ...
<PREFIXED_STRING_LITERAL> ...
<QUOTED_STRING> ...
<UNICODE_STRING_LITERAL> ...
...
I can see classes like SqlAlter
, SqlCreate
,SqlDrop
in the library. Is there a different way to parse DDLs?
I'm using 1.17.0
version.