Apache calcite DDL parser does not parse PRIMARY KEY constraint

23 Views Asked by At

I want to parse a few DDL statements for my use case. I am using SqlDDLParserImpl provided by Calcite Server for my use case. version : org.apache.calcite:calcite-server:1.36.0

I am able to parse the create statements who don't have any kind of constraints, however, few of the statements are failing with Primary Key constraints.

So I tried this code for parsing the DDL

SqlParser.Config sqlParserConfig = SqlParser.config()
              .withParserFactory(SqlDdlParserImpl.FACTORY)
              .withConformance(SqlConformanceEnum.MYSQL_5)
              .withLex(Lex.MYSQL);
SqlNode sqlNode = SqlParser.create(sql, sqlParserConfig).parseQuery();

This works fine

String sql = "CREATE TABLE employees (\n" +
"    employee_id INT NOT NULL,\n" +
"    first_name VARCHAR(50),\n" +
"    last_name VARCHAR(50),\n" +
"    email VARCHAR(100),\n" +
"    department_id INT," +
"    PRIMARY KEY (employee_id)" +
")";

But this does not

String sql = "CREATE TABLE employees (\n" +
"    employee_id INT NOT NULL PRIMARY KEY,\n" +
"    first_name VARCHAR(50),\n" +
"    last_name VARCHAR(50),\n" +
"    email VARCHAR(100),\n" +
"    department_id INT" +
")";

and I get this message from exception

Encountered "PRIMARY" at line 2, column 30.
Was expecting one of:
    "AS" ...
    "DEFAULT" ...
    "GENERATED" ...
    ")" ...
    "," ...

Am I missing something from the parser configuration or only the first one is currently supported by Apache Calcite?

0

There are 0 best solutions below