use of org.apache.calcite.rel.logical.LogicalFilter in project calcite by apache.
the class FilterToCalcRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final LogicalFilter filter = call.rel(0);
final RelNode rel = filter.getInput();
// Create a program containing a filter.
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final RelDataType inputRowType = rel.getRowType();
final RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder);
programBuilder.addIdentity();
programBuilder.addCondition(filter.getCondition());
final RexProgram program = programBuilder.getProgram();
final LogicalCalc calc = LogicalCalc.create(rel, program);
call.transformTo(calc);
}
use of org.apache.calcite.rel.logical.LogicalFilter 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));
}
use of org.apache.calcite.rel.logical.LogicalFilter in project calcite by apache.
the class SplunkPushDownRule method onMatch.
// ~ Methods --------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
LOGGER.debug(description);
int relLength = call.rels.length;
SplunkTableScan splunkRel = (SplunkTableScan) call.rels[relLength - 1];
LogicalFilter filter;
LogicalProject topProj = null;
LogicalProject bottomProj = null;
RelDataType topRow = splunkRel.getRowType();
int filterIdx = 2;
if (call.rels[relLength - 2] instanceof LogicalProject) {
bottomProj = (LogicalProject) call.rels[relLength - 2];
filterIdx = 3;
// bottom projection will change the field count/order
topRow = bottomProj.getRowType();
}
String filterString;
if (filterIdx <= relLength && call.rels[relLength - filterIdx] instanceof LogicalFilter) {
filter = (LogicalFilter) call.rels[relLength - filterIdx];
int topProjIdx = filterIdx + 1;
if (topProjIdx <= relLength && call.rels[relLength - topProjIdx] instanceof LogicalProject) {
topProj = (LogicalProject) call.rels[relLength - topProjIdx];
}
RexCall filterCall = (RexCall) filter.getCondition();
SqlOperator op = filterCall.getOperator();
List<RexNode> operands = filterCall.getOperands();
LOGGER.debug("fieldNames: {}", getFieldsString(topRow));
final StringBuilder buf = new StringBuilder();
if (getFilter(op, operands, buf, topRow.getFieldNames())) {
filterString = buf.toString();
} else {
// can't handle
return;
}
} else {
filterString = "";
}
// top projection will change the field count/order
if (topProj != null) {
topRow = topProj.getRowType();
}
LOGGER.debug("pre transformTo fieldNames: {}", getFieldsString(topRow));
call.transformTo(appendSearchString(filterString, splunkRel, topProj, bottomProj, topRow, null));
}
Aggregations