方解石 MySql,尝试将 id 列转换为 bigint

Calcite over MySql, tries to convert the id column to bigint

我正在尝试使用 Calcite 在同一查询中查询 MySql 和 Vertica:

MySql table: CREATE TABLE tableA (id INT(11), name VARCHAR(5), PRIMARY KEY(id));

垂直table:CREATE TABLE tableB (id INTEGER NOT NULL, name VARCHAR(20), PRIMARY KEY (id));

当运行以下查询使用方解石时:

statement.executeQuery(
            "SELECT a.\"name\", b.\"name\" " +
            "FROM \"mysqlschema\".\"tableA\" as a " +
            "INNER JOIN \"verticaschema\".\"tableB\" as b ON a.\"id\" = b.\"id\" " +
            "WHERE a.\"id\" = 1 "))

我得到:

    Exception in thread "main" java.sql.SQLException: Error while executing SQL "SELECT a."name", b."name" FROM "mysqlschema"."tableA" as a INNER JOIN "verticaschema"."tableB" as b ON a."id" = b."id" WHERE a."id" = 1 ": while executing SQL [SELECT `id`, `name`, CAST(`id` AS BIGINT) AS `id0`
FROM `mysqlschema`.`tableA`
WHERE `id` = 1]
    at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
    at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
    at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
    at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
    at com.test.TestCalcite.main(TestCalcite.java:73)
Caused by: java.lang.RuntimeException: while executing SQL [SELECT `id`, `name`, CAST(`id` AS BIGINT) AS `id0`
FROM `mysqlschema`.`tableA`
WHERE `id` = 1]
    at org.apache.calcite.runtime.ResultSetEnumerable.enumerator(ResultSetEnumerable.java:153)
    at org.apache.calcite.linq4j.EnumerableDefaults.<init>(EnumerableDefaults.java:1100)
    at org.apache.calcite.linq4j.EnumerableDefaults.enumerator(EnumerableDefaults.java:1099)
    at Baz.<init>(Unknown Source)
    at Baz.enumerator(Unknown Source)
    at org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)
    at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:90)
    at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:206)
    at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:67)
    at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:44)
    at org.apache.calcite.avatica.AvaticaConnection.execute(AvaticaConnection.java:630)
    at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:607)
    at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
    at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
    ... 2 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BIGINT) AS `id0`
FROM `mysqlschema`.`tableA`
WHERE `id` = 1' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505)
    at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:840)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:740)
    at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    at org.apache.calcite.runtime.ResultSetEnumerable.enumerator(ResultSetEnumerable.java:143)

转换 MySql table 中的 id 列可以解决问题,但我无法转换,因为我正在处理无法更改的现有 tables。

关于如何解决这个问题有什么想法吗?

谢谢

通过在 B 中转换 id 解决:

ON a."id" = CAST(b."b" AS INT)