'Does the ReflectiveSchema support collections as tables?
the test code is :
public class HrSchema2{
public List<Employee> emps = new ArrayList<Employee>();
public HrSchema2() {
}
}
public final String sql = "select count(e.empid) from hr.emps as e";
Class.forName("org.apache.calcite.jdbc.Driver");
Properties info = new Properties();
info.setProperty("lex", "JAVA");
try {
Connection connection =
DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
Schema schema = new ReflectiveSchema(new HrSchema2());
rootSchema.add("hr", schema);
Statement statement = calciteConnection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
//print(resultSet);
resultSet.close();
statement.close();
connection.close();
}catch(Exception ex) {
ex.printStackTrace();
}
we got the following error:
java.sql.SQLException: Error while executing SQL "select count(e.empid) from hr.emps as e": From line 1, column 16 to line 1, column 20: Column 'empid' not found in table 'e'
goodbye from test runner
Solution 1:[1]
Use org.apache.calcite.adapter.java.Array annotation on List<Employee> emps member variable in HrSchema2
@Array(component = Employee.class)
public List<Employee> emps = new ArrayList<>();
Refer CALCITE-4708 to get your use-case working.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
