Search in sources :

Example 6 with Interpreter

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

the class InterpreterTest method testAggregateGroupFilter.

@Test
public void testAggregateGroupFilter() throws Exception {
    rootSchema.add("beatles", new ScannableTableTest.BeatlesTable());
    final String sql = "select \"j\",\n" + "  count(*) filter (where char_length(\"j\") > 4)\n" + "from \"beatles\" group by \"j\"";
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRowsUnordered(interpreter, "[George, 1]", "[Paul, 0]", "[John, 0]", "[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 7 with Interpreter

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

the class InterpreterTest method testInterpretOrder.

/**
 * Tests a plan where the sort field is projected away.
 */
@Test
public void testInterpretOrder() throws Exception {
    final String sql = "select y\n" + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n" + "order by -x";
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).project();
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[c]", "[b]", "[a]");
}
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 8 with Interpreter

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

the class InterpreterTest method testInterpretTable.

/**
 * Tests executing a simple plan using an interpreter.
 */
@Test
public void testInterpretTable() throws Exception {
    SqlNode parse = planner.parse("select * from \"hr\".\"emps\" order by \"empid\"");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[100, 10, Bill, 10000.0, 1000]", "[110, 10, Theodore, 11500.0, 250]", "[150, 10, Sebastian, 7000.0, null]", "[200, 20, Eric, 8000.0, 500]");
}
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 9 with Interpreter

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

the class InterpreterTest method testInterpretScannableTable.

/**
 * Tests executing a plan on a
 * {@link org.apache.calcite.schema.ScannableTable} using an interpreter.
 */
@Test
public void testInterpretScannableTable() throws Exception {
    rootSchema.add("beatles", new ScannableTableTest.BeatlesTable());
    SqlNode parse = planner.parse("select * from \"beatles\" order by \"i\"");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[4, John]", "[4, Paul]", "[5, Ringo]", "[6, George]");
}
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 10 with Interpreter

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

the class InterpreterTest method testInterpretSimpleScannableTable.

/**
 * Tests executing a plan on a single-column
 * {@link org.apache.calcite.schema.ScannableTable} using an interpreter.
 */
@Test
public void testInterpretSimpleScannableTable() throws Exception {
    rootSchema.add("simple", new ScannableTableTest.SimpleTable());
    SqlNode parse = planner.parse("select * from \"simple\" limit 2");
    SqlNode validate = planner.validate(parse);
    RelNode convert = planner.rel(validate).rel;
    final Interpreter interpreter = new Interpreter(dataContext, convert);
    assertRows(interpreter, "[0]", "[10]");
}
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)12 RelNode (org.apache.calcite.rel.RelNode)11 SqlNode (org.apache.calcite.sql.SqlNode)11 Test (org.junit.Test)11 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Schema (org.apache.avro.Schema)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)1 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 Expression (org.apache.calcite.linq4j.tree.Expression)1 RelRoot (org.apache.calcite.rel.RelRoot)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 SqlParser (org.apache.calcite.sql.parser.SqlParser)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1 Planner (org.apache.calcite.tools.Planner)1 GenericRecordBuilder (org.spf4j.avro.GenericRecordBuilder)1 PrintLogs (org.spf4j.test.log.annotations.PrintLogs)1