【问题标题】:Apache Calcite | HSQLDB - Table Not Found Exception阿帕奇方解石 | HSQLDB - 未找到表异常
【发布时间】:2018-06-05 21:25:58
【问题描述】:

我正在尝试按照RelBuilderExample 学习Apache Calcite,存储层是HSQLDB。 不幸的是,当我调用 Apache Calcite 的 builder.scan(tableName) API 时,我不断收到“找不到表异常”。当我直接使用ResultSet rs = statement.executeQuery("SELECT * from file"); 查询 HSQL 中的数据时,我就能够检索数据。以下是相关代码:

//I create an instance of RelBuilder using the Config defined below
RelBuilder builder = RelBuilder.create(config().build());
//This line throws me exception: org.apache.calcite.runtime.CalciteException: Table 'file' not found

            builder = builder.scan("file");

/**
  Building the configuration backed by HSQLDB
*/
public static Frameworks.ConfigBuilder config() throws Exception{

            //Getting the ConnectionSpec for the in memory HSQLDB
            //FileHSQLDB.URI = "jdbc:hsqldb:mem:intel"
            //FileHSQLDB.USER = "user"
            //FileHSQLDB.PASSWORD = "password"
            final ConnectionSpec cs = new ConnectionSpec(FileHSQLDB.URI, FileHSQLDB.USER, FileHSQLDB.PASSWORD, "org.hsqldb.jdbcDriver", "intel");

            //cs.url = "jdbc:hsqldb:mem:intel"
            //cs.driver = "org.hsqldb.jdbcDriver"
            //cs.username = "user"
            //cs.password = "password"
            DataSource dataSource = JdbcSchema.dataSource(cs.url, cs.driver, cs.username, cs.password);
            Connection connection = dataSource.getConnection();
            Statement statement = connection.createStatement();
            //This returns me 3 results
            ResultSet rs = statement.executeQuery("SELECT * from file");
            while(rs.next()) {
                String id = rs.getString("file_id");
                System.out.println(id);
            }
            // Next I create the rootSchema
            SchemaPlus rootSchema = Frameworks.createRootSchema(true);

            //I suspect that there is some issue in the below line. I think I 
            //am not using Apache Calcite APIs properly, but not sure what I 
            //am doing wrong.
            rootSchema.add("intel", JdbcSchema.create(rootSchema, "intel", dataSource, cs.catalog, cs.schema));
return Frameworks.newConfigBuilder().defaultSchema(rootSchema);

有人可以帮我解决我可能做错的事情吗?

【问题讨论】:

    标签: hsqldb apache-calcite


    【解决方案1】:

    如果您的表是file(小写),请确保在查询中引用表名,即"SELECT * from \"file\""

    【讨论】:

    • 所以我使用statement.executeQuery 直接从 HSQL 检索数据没有问题,但我无法使用 Apache Calcite API 获取它。更新了我的问题以清楚地反映这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多