ade*_*ood 3 java apache-calcite
我正在尝试用方解石做一些基本的事情来理解框架。我设置了一个简单的示例,应该从 2 个 json 文件中读取。我的模型看起来像
{
version: '1.0',
defaultSchema: 'PEOPLE',
schemas: [
{
name: 'PEOPLE',
type: 'custom',
factory: 'demo.JsonSchemaFactory',
operand: {
directory: '/..../calcite-json/src/test/resources/files'
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中,模型似乎加载得很好,因为当我提取数据库元数据信息时,我可以看到我的文件正在作为 PEOPLE 模式下的表加载。但是在该语句之后,我尝试select *从该表中执行操作,但收到一条错误,表示未找到表。
Run Code Online (Sandbox Code Playgroud)> -- 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();
}
Run Code Online (Sandbox Code Playgroud)
为什么我无法在加载的表上进行选择,有什么想法吗?
我注意到的另一件有趣的事情是,对于 1 个文件,Schema.getTableMap被调用 4 次。
小智 5
问题是区分大小写。因为您没有将表名括在双引号中,所以 Calcite 的 SQL 解析器将其转换为大写。由于该文件名为“a.json”,因此该表也称为“a”,而您的查询正在查找名为“A”的表。
解决方案是将您的查询编写如下:
select _MAP['name'] from "a"
Run Code Online (Sandbox Code Playgroud)
这变成:
stat.execute("select _MAP['name'] from \"a\"");
Run Code Online (Sandbox Code Playgroud)
当你把它嵌入到Java中时。
| 归档时间: |
|
| 查看次数: |
4642 次 |
| 最近记录: |