anthonylouis
anthonylouis

Reputation: 55

Problems with planner and ddl statements in Apache Calcite

When I try to validate a sql statement that contains "CREATE TABLE" it throws a error:

java.lang.AssertionError: Was not expecting value 'CREATE_TABLE' for enumeration 'org.apache.calcite.sql.SqlKind' in this context

    at org.apache.calcite.util.Util.unexpected(Util.java:1773)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(SqlValidatorImpl.java:2715)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(SqlValidatorImpl.java:2381)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:927)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:633)
    at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:188)

I would like to know if is possible to validate a query using ddl statements in calcite?

Upvotes: 1

Views: 749

Answers (1)

zabetak
zabetak

Reputation: 467

From the stacktrace it seems that you are using the Planner interface. At the moment this interface does not support validation of statements that include DDL elements since it creates always an instance of CalciteSqlValidator.

In order to validate statements with DDL nodes you have to obtain an instance of ContextSqlValidator but currently there is no high-level API to use this service.

Statements that are executed via a Calcite connection pass through the ContextSqlValidator so you can get ideas on how to instantiate this class by debugging a test case in ServerTest.

Upvotes: 1

Related Questions