[英]table not found with 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'
}
}
]
}
在我的測試中,似乎可以很好地加載模型,因為當我提取數據庫元數據信息時,可以看到我的文件正在作為表加載到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上找到
問題是區分大小寫。 因為您沒有將表名括在雙引號中,所以Calcite的SQL解析器將其轉換為大寫。 因為文件名為“ a.json”,所以表也稱為“ a”,而您的查詢正在尋找名為“ A”的表。
解決方案是按如下方式編寫查詢:
select _MAP['name'] from "a"
變成:
stat.execute("select _MAP['name'] from \"a\"");
當您將其嵌入Java中時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.