use of org.apache.calcite.adapter.java.ReflectiveSchema in project calcite by apache.
the class PlannerTest method testOrderByNonSelectColumn.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-569">[CALCITE-569]
* ArrayIndexOutOfBoundsException when deducing collation</a>.
*/
@Test
public void testOrderByNonSelectColumn() throws Exception {
final SchemaPlus schema = Frameworks.createRootSchema(true).add("tpch", new ReflectiveSchema(new TpchSchema()));
String query = "select t.psPartkey from \n" + "(select ps.psPartkey from `tpch`.`partsupp` ps \n" + "order by ps.psPartkey, ps.psSupplyCost) t \n" + "order by t.psPartkey";
List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
final SqlParser.Config parserConfig = SqlParser.configBuilder().setLex(Lex.MYSQL).build();
FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(parserConfig).defaultSchema(schema).traitDefs(traitDefs).programs(Programs.ofRules(Programs.RULE_SET)).build();
String plan;
try (Planner p = Frameworks.getPlanner(config)) {
SqlNode n = p.parse(query);
n = p.validate(n);
RelNode r = p.rel(n).project();
plan = RelOptUtil.toString(r);
plan = Util.toLinux(plan);
}
assertThat(plan, equalTo("LogicalSort(sort0=[$0], dir0=[ASC])\n" + " LogicalProject(psPartkey=[$0])\n" + " LogicalProject(psPartkey=[$0])\n" + " LogicalSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC])\n" + " LogicalProject(psPartkey=[$0], psSupplyCost=[$1])\n" + " EnumerableTableScan(table=[[tpch, partsupp]])\n"));
}
use of org.apache.calcite.adapter.java.ReflectiveSchema in project calcite by apache.
the class RelWriterTest method testWriter.
/**
* Unit test for {@link org.apache.calcite.rel.externalize.RelJsonWriter} on
* a simple tree of relational expressions, consisting of a table, a filter
* and an aggregate node.
*/
@Test
public void testWriter() {
String s = Frameworks.withPlanner(new Frameworks.PlannerAction<String>() {
public String apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
LogicalTableScan scan = LogicalTableScan.create(cluster, relOptSchema.getTableForMember(Arrays.asList("hr", "emps")));
final RexBuilder rexBuilder = cluster.getRexBuilder();
LogicalFilter filter = LogicalFilter.create(scan, rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, rexBuilder.makeFieldAccess(rexBuilder.makeRangeReference(scan), "deptno", true), rexBuilder.makeExactLiteral(BigDecimal.TEN)));
final RelJsonWriter writer = new RelJsonWriter();
final RelDataType bigIntType = cluster.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
LogicalAggregate aggregate = LogicalAggregate.create(filter, ImmutableBitSet.of(0), null, ImmutableList.of(AggregateCall.create(SqlStdOperatorTable.COUNT, true, false, ImmutableList.of(1), -1, bigIntType, "c"), AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, ImmutableList.<Integer>of(), -1, bigIntType, "d")));
aggregate.explain(writer);
return writer.asString();
}
});
assertThat(s, is(XX));
}
Aggregations