Search in sources :

Example 1 with Employee

use of org.apache.calcite.test.JdbcTest.Employee in project calcite by apache.

the class ReflectiveSchemaTest method testQueryProviderSingleColumn.

@Test
public void testQueryProviderSingleColumn() throws Exception {
    Connection connection = CalciteAssert.that(CalciteAssert.Config.REGULAR).connect();
    QueryProvider queryProvider = connection.unwrap(QueryProvider.class);
    ParameterExpression e = Expressions.parameter(Employee.class, "e");
    // "Enumerable<T> asEnumerable(final T[] ts)"
    List<Integer> list = queryProvider.createQuery(Expressions.call(Expressions.call(Types.of(Enumerable.class, Employee.class), null, LINQ4J_AS_ENUMERABLE_METHOD, Expressions.constant(new JdbcTest.HrSchema().emps)), "asQueryable"), Employee.class).select(Expressions.<Function1<Employee, Integer>>lambda(Expressions.field(e, "empid"), e)).toList();
    assertEquals(Arrays.asList(100, 200, 150, 110), list);
}
Also used : QueryProvider(org.apache.calcite.linq4j.QueryProvider) Employee(org.apache.calcite.test.JdbcTest.Employee) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) Function1(org.apache.calcite.linq4j.function.Function1) Enumerable(org.apache.calcite.linq4j.Enumerable) Test(org.junit.Test)

Example 2 with Employee

use of org.apache.calcite.test.JdbcTest.Employee in project calcite by apache.

the class ReflectiveSchemaTest method testQueryProvider.

/**
 * Test that uses a JDBC connection as a linq4j
 * {@link org.apache.calcite.linq4j.QueryProvider}.
 *
 * @throws Exception on error
 */
@Test
public void testQueryProvider() throws Exception {
    Connection connection = CalciteAssert.that(CalciteAssert.Config.REGULAR).connect();
    QueryProvider queryProvider = connection.unwrap(QueryProvider.class);
    ParameterExpression e = Expressions.parameter(Employee.class, "e");
    // "Enumerable<T> asEnumerable(final T[] ts)"
    List<Object[]> list = queryProvider.createQuery(Expressions.call(Expressions.call(Types.of(Enumerable.class, Employee.class), null, LINQ4J_AS_ENUMERABLE_METHOD, Expressions.constant(new JdbcTest.HrSchema().emps)), "asQueryable"), Employee.class).where(Expressions.<Predicate1<Employee>>lambda(Expressions.lessThan(Expressions.field(e, "empid"), Expressions.constant(160)), e)).where(Expressions.<Predicate1<Employee>>lambda(Expressions.greaterThan(Expressions.field(e, "empid"), Expressions.constant(140)), e)).select(Expressions.<Function1<Employee, Object[]>>lambda(Expressions.new_(Object[].class, Expressions.field(e, "empid"), Expressions.call(Expressions.field(e, "name"), "toUpperCase")), e)).toList();
    assertEquals(1, list.size());
    assertEquals(2, list.get(0).length);
    assertEquals(150, list.get(0)[0]);
    assertEquals("SEBASTIAN", list.get(0)[1]);
}
Also used : QueryProvider(org.apache.calcite.linq4j.QueryProvider) Employee(org.apache.calcite.test.JdbcTest.Employee) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) Function1(org.apache.calcite.linq4j.function.Function1) Enumerable(org.apache.calcite.linq4j.Enumerable) Predicate1(org.apache.calcite.linq4j.function.Predicate1) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)2 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)2 Enumerable (org.apache.calcite.linq4j.Enumerable)2 QueryProvider (org.apache.calcite.linq4j.QueryProvider)2 Function1 (org.apache.calcite.linq4j.function.Function1)2 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)2 Employee (org.apache.calcite.test.JdbcTest.Employee)2 Test (org.junit.Test)2 Predicate1 (org.apache.calcite.linq4j.function.Predicate1)1