Search in sources :

Example 1 with Interpreter

use of org.apache.calcite.interpreter.Interpreter in project calcite by apache.

the class InterpreterTest method testInterpretUnionAll.

/**
 * Tests executing a UNION ALL query using an interpreter.
 */
@Test
public void testInterpretUnionAll() throws Exception {
    rootSchema.add("simple", new ScannableTableTest.SimpleTable());
    SqlNode parse = planner.parse("select * from \"simple\"\n" + "union all\n" + "select * from \"simple\"\n");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[0]", "[10]", "[20]", "[30]", "[0]", "[10]", "[20]", "[30]");
}
Also used : Interpreter(org.apache.calcite.interpreter.Interpreter) RelNode(org.apache.calcite.rel.RelNode) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 2 with Interpreter

use of org.apache.calcite.interpreter.Interpreter in project calcite by apache.

the class InterpreterTest method testAggregateGroup.

@Test
public void testAggregateGroup() throws Exception {
    rootSchema.add("beatles", new ScannableTableTest.BeatlesTable());
    SqlNode parse = planner.parse("select \"j\", count(*) from \"beatles\" group by \"j\"");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRowsUnordered(interpreter, "[George, 1]", "[Paul, 1]", "[John, 1]", "[Ringo, 1]");
}
Also used : Interpreter(org.apache.calcite.interpreter.Interpreter) RelNode(org.apache.calcite.rel.RelNode) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 3 with Interpreter

use of org.apache.calcite.interpreter.Interpreter in project calcite by apache.

the class InterpreterTest method testAggregate.

@Test
public void testAggregate() throws Exception {
    rootSchema.add("beatles", new ScannableTableTest.BeatlesTable());
    SqlNode parse = planner.parse("select  count(*) from \"beatles\"");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[4]");
}
Also used : Interpreter(org.apache.calcite.interpreter.Interpreter) RelNode(org.apache.calcite.rel.RelNode) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 4 with Interpreter

use of org.apache.calcite.interpreter.Interpreter in project calcite by apache.

the class EnumerableInterpreter method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final JavaTypeFactory typeFactory = implementor.getTypeFactory();
    final BlockBuilder builder = new BlockBuilder();
    final PhysType physType = PhysTypeImpl.of(typeFactory, getRowType(), JavaRowFormat.ARRAY);
    final Expression interpreter_ = builder.append("interpreter", Expressions.new_(Interpreter.class, implementor.getRootExpression(), implementor.stash(getInput(), RelNode.class)));
    final Expression sliced_ = getRowType().getFieldCount() == 1 ? Expressions.call(BuiltInMethod.SLICE0.method, interpreter_) : interpreter_;
    builder.add(sliced_);
    return implementor.result(physType, builder.toBlock());
}
Also used : Interpreter(org.apache.calcite.interpreter.Interpreter) Expression(org.apache.calcite.linq4j.tree.Expression) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 5 with Interpreter

use of org.apache.calcite.interpreter.Interpreter in project calcite by apache.

the class InterpreterTest method testInterpretUnion.

/**
 * Tests executing a UNION query using an interpreter.
 */
@Test
public void testInterpretUnion() throws Exception {
    rootSchema.add("simple", new ScannableTableTest.SimpleTable());
    SqlNode parse = planner.parse("select * from \"simple\"\n" + "union\n" + "select * from \"simple\"\n");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[0]", "[10]", "[20]", "[30]");
}
Also used : Interpreter(org.apache.calcite.interpreter.Interpreter) RelNode(org.apache.calcite.rel.RelNode) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Aggregations

Interpreter (org.apache.calcite.interpreter.Interpreter)11 RelNode (org.apache.calcite.rel.RelNode)10 SqlNode (org.apache.calcite.sql.SqlNode)10 Test (org.junit.Test)10 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 Expression (org.apache.calcite.linq4j.tree.Expression)1