我正在尝试使用 Calcite 连接到 SQL 服务器。尝试运行非常简单的示例来从人员表中提取数据。
这是我正在使用架构的代码:
public static class PersonSchema
{
public final Person[] persons;
public PersonSchema(Person[] persons)
{
this.persons = persons;
}
public PersonSchema(){
persons=null;
}
}
public static class Person {
public final int personId;
public final String firstName;
public final String lastName;
public Person(int personId, String firstName, String lastName) {
this.personId = personId;
this.firstName = firstName;
this.lastName = lastName;
}
}
}
这是主要代码
@Test public void testRealSqlServerData_MI() throws Exception {
Class.forName("org.apache.calcite.jdbc.Driver");
Properties info = new Properties();
info.setProperty("lex", "SQL_SERVER");
info.setProperty("UserName", "USER_XXX");
info.setProperty("Password", "XXXXXXX");
Connection connection = DriverManager.getConnection
("jdbc:calcite://SPG;databaseName=Dept", info);
CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("PersonSchema",
new ReflectiveSchema(new PersonSchema()));
Statement statement = calciteConnection.createStatement();
ResultSet resultSet = statement.executeQuery(
"select e.personid, e.firstname, e.lastname \n"
+ "from person_tbl as e\n");
resultSet.close();
statement.close();
connection.close();
}
sql server 设置是这样的。服务器 - SPG DB - 部门架构 - dbo
问题:
- 我找不到表,所以看起来它没有读取架构。
- 我想了解在方解石上创建模式,因为实时 sql 会因许多连接而变得更加复杂。
- 什么是连接到 sql server 的最佳方法。上面的代码方向正确。
提前致谢。
理士