2

我正在尝试用方解石做一些基本的事情来理解框架。我已经设置了一个应该从 2 个 json 文件中读取的简单示例。我的模型看起来像

{
  version: '1.0',
  defaultSchema: 'PEOPLE',
  schemas: [
    {
      name: 'PEOPLE',
      type: 'custom',
      factory: 'demo.JsonSchemaFactory',
      operand: {
        directory: '/..../calcite-json/src/test/resources/files'
      }
    }
  ]
}

在我的测试中,模型似乎加载正常,因为当我提取数据库元数据信息时,我可以看到我的文件正在作为 PEOPLE 模式下的表加载。但是在那个声明之后,我试图select *从那个表中做一个,我得到一个错误,即找不到表。

> --
null
PEOPLE
a
TABLE
-->
Jun 29, 2015 8:53:30 AM org.apache.calcite.sql.validate.SqlValidatorException <init>
SEVERE: org.apache.calcite.sql.validate.SqlValidatorException: Table 'A' not found
Jun 29, 2015 8:53:30 AM org.apache.calcite.runtime.CalciteException <init>
SEVERE: org.apache.calcite.runtime.CalciteContextException: At line 1, column 26: Table 'A' not found

输出中的第一行显示来自数据库元数据“-- null PEOPLE a TABLE -->”的表。这表明表“a”存在于模式“people”下,并且属于“table”类型。

我的测试代码看起来像这样

@Test
public void testModel() throws SQLException {
    Properties props = new Properties();
    props.put("model", getPath("/model.json"));
    System.out.println("model = " + props.get("model"));
    Connection conn = DriverManager.getConnection("jdbc:calcite:", props);

    DatabaseMetaData md = conn.getMetaData();
    ResultSet tables = md.getTables(null, "PEOPLE", "%", null);
    while (tables.next()) {
        System.out.println("--");
        System.out.println(tables.getString(1));
        System.out.println(tables.getString(2));
        System.out.println(tables.getString(3));
        System.out.println(tables.getString(4));
        System.out.println("-->");
    }

    Statement stat = conn.createStatement();
    stat.execute("select _MAP['name'] from a");

    stat.close();
    conn.close();
}

任何想法为什么我无法在加载的表格上进行选择?

我注意到的另一件有趣的事情是,对于 1 个文件,Schema.getTableMap它被调用了 4 次。

该项目的完整代码可以在github上找到

4

1 回答 1

4

问题是区分大小写。因为您没有将表名括在双引号中,所以 Calcite 的 SQL 解析器将其转换为大写。因为该文件名为“a.json”,所以该表也称为“a”,而您的查询正在寻找一个名为“A”的表。

解决方案是将查询编写如下:

select _MAP['name'] from "a"

这变成:

stat.execute("select _MAP['name'] from \"a\"");

当你将它嵌入Java时。

于 2015-07-06T21:34:43.273 回答