1

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?

anthonylouis
  • 45
  • 1
  • 2
  • 6
  • Your question would be easier to understand if you provided the complete query and the code snippet that calls the planner API. – zabetak Dec 17 '19 at 16:43

1 Answers1

1

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.

Community
  • 1
  • 1
zabetak
  • 412
  • 4
  • 13