org.apache.calcite.test.LinqFrontJdbcBackTest
/**
* Tests for a linq4j front-end and JDBC back-end.
*/
public class LinqFrontJdbcBackTest {
@Test public void testTableWhere() throws SQLException,
ClassNotFoundException {
final Connection connection =
CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect();
final CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
final SchemaPlus rootSchema = calciteConnection.getRootSchema();
ParameterExpression c =
Expressions.parameter(JdbcTest.Customer.class, "c");
String s =
Schemas.queryable(Schemas.createDataContext(connection, rootSchema),
rootSchema.getSubSchema("foodmart"),
JdbcTest.Customer.class, "customer")
.where(
Expressions.lambda(
Expressions.lessThan(
Expressions.field(c, "customer_id"),
Expressions.constant(5)),
c))
.toList()
.toString();
Util.discard(s);
}
}
本质上是获取
QueryableTable table = (QueryableTable) schema.getTable(tableName);
return table.asQueryable(root.getQueryProvider(), schema, tableName);
QueryableTable 就是自定义的table实现