use of org.apache.calcite.schema.Table in project calcite by apache.
the class ScannableTableTest method testProjectableFilterableNonCooperative.
@Test
public void testProjectableFilterableNonCooperative() throws Exception {
final StringBuilder buf = new StringBuilder();
final Table table = new BeatlesProjectableFilterableTable(buf, false);
final String explain = "PLAN=" + "EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles2]], filters=[[=($0, 4)]], projects=[[1]]";
CalciteAssert.that().with(newSchema("s", "beatles2", table)).query("select \"j\" from \"s\".\"beatles2\" where \"i\" = 4").explainContains(explain).returnsUnordered("j=John", "j=Paul");
assertThat(buf.toString(), is("returnCount=4, projects=[1, 0]"));
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class ScannableTableTest method testPFTableRefusesFilterSingleColumn.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-458">[CALCITE-458]
* ArrayIndexOutOfBoundsException when using just a single column in
* interpreter</a>.
*/
@Test
public void testPFTableRefusesFilterSingleColumn() throws Exception {
final StringBuilder buf = new StringBuilder();
final Table table = new BeatlesProjectableFilterableTable(buf, false);
final String explain = "PLAN=" + "EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles2]], filters=[[>($2, 1941)]], projects=[[2]])";
CalciteAssert.that().with(newSchema("s", "beatles2", table)).query("select \"k\" from \"s\".\"beatles2\" where \"k\" > 1941").explainContains(explain).returnsUnordered("k=1942", "k=1943");
assertThat(buf.toString(), is("returnCount=4, projects=[2]"));
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class ScannableTableTest method testPFPushDownProjectFilterInAggregateNoGroup.
@Test
public void testPFPushDownProjectFilterInAggregateNoGroup() {
final StringBuilder buf = new StringBuilder();
final Table table = new BeatlesProjectableFilterableTable(buf, false);
final String explain = "PLAN=EnumerableAggregate(group=[{}], M=[MAX($0)])\n" + " EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles]], filters=[[>($0, 1)]], projects=[[2]])";
CalciteAssert.that().with(newSchema("s", "beatles", table)).query("select max(\"k\") as m from \"s\".\"beatles\" where \"i\" > 1").explainContains(explain).returnsUnordered("M=1943");
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class FrameworksTest method testOptimize.
@Test
public void testOptimize() {
RelNode x = Frameworks.withPlanner(new Frameworks.PlannerAction<RelNode>() {
public RelNode apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
final RelDataTypeFactory typeFactory = cluster.getTypeFactory();
final Table table = new AbstractTable() {
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
final RelDataType stringType = typeFactory.createJavaType(String.class);
final RelDataType integerType = typeFactory.createJavaType(Integer.class);
return typeFactory.builder().add("s", stringType).add("i", integerType).build();
}
};
// "SELECT * FROM myTable"
final RelOptAbstractTable relOptTable = new RelOptAbstractTable(relOptSchema, "myTable", table.getRowType(typeFactory)) {
};
final EnumerableTableScan tableRel = EnumerableTableScan.create(cluster, relOptTable);
// "WHERE i > 1"
final RexBuilder rexBuilder = cluster.getRexBuilder();
final RexNode condition = rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN, rexBuilder.makeFieldAccess(rexBuilder.makeRangeReference(tableRel), "i", true), rexBuilder.makeExactLiteral(BigDecimal.ONE));
final LogicalFilter filter = LogicalFilter.create(tableRel, condition);
// Specify that the result should be in Enumerable convention.
final RelNode rootRel = filter;
final RelOptPlanner planner = cluster.getPlanner();
RelTraitSet desiredTraits = cluster.traitSet().replace(EnumerableConvention.INSTANCE);
final RelNode rootRel2 = planner.changeTraits(rootRel, desiredTraits);
planner.setRoot(rootRel2);
// Now, plan.
return planner.findBestExp();
}
});
String s = RelOptUtil.dumpPlan("", x, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES);
assertThat(Util.toLinux(s), equalTo("EnumerableFilter(condition=[>($1, 1)])\n" + " EnumerableTableScan(table=[[myTable]])\n"));
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class FrameworksTest method testUpdate.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2039">[CALCITE-2039]
* AssertionError when pushing project to ProjectableFilterableTable</a>
* using UPDATE via {@link Frameworks}.
*/
@Test
public void testUpdate() throws Exception {
Table table = new TableImpl();
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
SchemaPlus schema = rootSchema.add("x", new AbstractSchema());
schema.add("MYTABLE", table);
List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelDistributionTraitDef.INSTANCE);
SqlParser.Config parserConfig = SqlParser.configBuilder(SqlParser.Config.DEFAULT).setCaseSensitive(false).build();
final FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(parserConfig).defaultSchema(schema).traitDefs(traitDefs).ruleSets(RuleSets.ofList(AbstractConverter.ExpandConversionRule.INSTANCE)).programs(Programs.ofRules(Programs.RULE_SET)).build();
executeQuery(config, " UPDATE MYTABLE set id=7 where id=1", CalcitePrepareImpl.DEBUG);
}
Aggregations