Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.39.0
Description
When I was learning Calcite by browsing the official website, I found that the examples there couldn't run. I specifically wrote a demo to reproduce this issue.
// Some comments here public class PlayCalciteDdl { public static void main(String[] args) throws Exception { Class.forName("org.apache.calcite.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:calcite:parserFactory=org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl#FACTORY"); CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); SchemaPlus rootSchema = calciteConnection.getRootSchema(); Schema schema = new ReflectiveSchema(new HrSchema()); rootSchema.add("hr", schema); Statement statement = calciteConnection.createStatement(); statement.execute("CREATE TABLE t (i INTEGER, j VARCHAR(10))"); statement.execute("INSERT INTO t VALUES (1, 'a'), (2, 'bc')"); statement.execute("CREATE VIEW v AS SELECT * FROM t WHERE i > 1"); ResultSet resultSet = statement.executeQuery("SELECT count(*) as num FROM v"); while (resultSet.next()) { System.out.println(resultSet.getString("num")); } resultSet.close(); statement.close(); connection.close(); } public static class HrSchema { public final Employee[] emp = new Employee[]{ new Employee("1" , "A", "Tom"), new Employee("1", "B", "Lisa") }; public final Department[] dept = new Department[]{new Department("1")}; } public static class Employee { public final String deptNo; public final String empId; public final String empName; public Employee(String deptNo, String empId, String empName) { this.deptNo = deptNo; this.empId = empId; this.empName = empName; } } public static class Department { public final String deptNo; public Department(String deptNo) { this.deptNo = deptNo; } } }
it will throw an exception:
Caused by: java.lang.UnsupportedOperationException: DDL not supported: CREATE TABLE `T` (`I` INTEGER, `J` VARCHAR(10))
at org.apache.calcite.server.DdlExecutor.lambda$static$0(DdlExecutor.java:28)
at org.apache.calcite.prepare.CalcitePrepareImpl.executeDdl(CalcitePrepareImpl.java:370)
at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:635)
after debugging, the parameter values in the JDBC connection link provided on the official website are incorrect
//wrong value
parserFactory=org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl#FACTORY
The class SqlDdlParserImpl.FACTORY does not override the getDdlExecutor() method in the SqlParserImplFactory interface.
Therefore, the default logic defined in the interface is used during runtime, and the default logic will throw an exception.
The correct parameter value should be:
org.apache.calcite.server.ServerDdlExecutor#PARSER_FACTORY
After I replaced the parameter value in the JDBC connection with this one, it could run properly.
Attachments
Issue Links
- links to