apache方解石找不到表 [英] table not found with apache calcite
问题描述
我正在尝试使用方解石做一些基本的事情,以了解框架.我设置了一个简单的示例,该示例应该从2个json文件中读取.我的模型看起来像
I am trying to do some basic things with calcite to understand the framework. I have setup a simple example that is supposed to read from 2 json files. My model looks like
{
version: '1.0',
defaultSchema: 'PEOPLE',
schemas: [
{
name: 'PEOPLE',
type: 'custom',
factory: 'demo.JsonSchemaFactory',
operand: {
directory: '/..../calcite-json/src/test/resources/files'
}
}
]
}
在我的测试中,似乎可以很好地加载模型,因为当我提取数据库元数据信息时,可以看到文件正在作为PEOPLE模式下的表加载.但是在那条语句之后,我正尝试从该表中执行select *
,但收到一条错误消息,即未找到该表.
In my test, it seems that the model is being loaded fine because when I pull the database metadata information, I can see that my file is being loaded as a table under PEOPLE schema. But then right after that statement I am trying to do a select *
from that table and I get an error that table was not found.
> --
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".
The first line in the output shows the tables from database metadata "-- null PEOPLE a TABLE -->". This shows that a table "a" is present under schema "people" and is of the type "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();
}
有什么想法为什么我无法在已加载的表格上进行选择?
Any ideas why I am not able to do a select on the loaded table?
我注意到的另一件有趣的事情是,对于1个文件,Schema.getTableMap
被调用了4次.
Another interesting thing I noticed is that for 1 file, Schema.getTableMap
is being called 4 times.
可以在github上的找到完整的项目代码
The complete code for the project can be found on github
推荐答案
问题是区分大小写.由于您没有将表名括在双引号中,因此Calcite的SQL解析器将其转换为大写.因为该文件名为"a.json",所以该表也称为"a",而您的查询正在寻找一个名为"A"的表.
The problem is case-sensitivity. Because you did not enclose the table name in double-quotes, Calcite's SQL parser converted it to upper case. Because the file is called 'a.json', the table is also called 'a', whereas your query is looking for a table called 'A'.
解决方案是按如下方式编写查询:
The solution is to write your query as follows:
select _MAP['name'] from "a"
它变成:
stat.execute("select _MAP['name'] from \"a\"");
当您将其嵌入Java中时.
when you embed it in Java.
这篇关于apache方解石找不到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!