use of org.apache.calcite.rel.logical.LogicalFilter in project flink by apache.
the class FlinkSemiAntiJoinFilterTransposeRule method onMatch.
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
LogicalJoin join = call.rel(0);
LogicalFilter filter = call.rel(1);
RelNode newJoin = LogicalJoin.create(filter.getInput(), join.getRight(), join.getHints(), join.getCondition(), join.getVariablesSet(), join.getJoinType());
final RelFactories.FilterFactory factory = RelFactories.DEFAULT_FILTER_FACTORY;
RelNode newFilter = factory.createFilter(newJoin, filter.getCondition());
call.transformTo(newFilter);
}
use of org.apache.calcite.rel.logical.LogicalFilter in project streamline by hortonworks.
the class TestRelNodeCompiler method testFilter.
@Test
public void testFilter() throws Exception {
String sql = "SELECT ID + 1 FROM FOO WHERE ID > 3";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
LogicalProject project = (LogicalProject) state.tree();
LogicalFilter filter = (LogicalFilter) project.getInput();
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
// standalone mode doesn't use inputstreams argument
compiler.visitFilter(filter, Collections.EMPTY_LIST);
pw.flush();
Assert.assertThat(sw.toString(), containsString("> 3"));
}
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
// standalone mode doesn't use inputstreams argument
compiler.visitProject(project, Collections.EMPTY_LIST);
pw.flush();
Assert.assertThat(sw.toString(), containsString(" + 1"));
}
}
use of org.apache.calcite.rel.logical.LogicalFilter in project hazelcast by hazelcast.
the class QueryConverter method hasNestedExists.
private static boolean hasNestedExists(RelNode root) {
class NestedExistsFinder extends RelVisitor {
private boolean found;
private int depth;
@Override
public void visit(RelNode node, int ordinal, @Nullable RelNode parent) {
if (node instanceof LogicalFilter) {
RexSubQuery exists = getExists((LogicalFilter) node);
if (exists != null) {
found |= depth > 0;
depth++;
go(exists.rel);
depth--;
}
}
super.visit(node, ordinal, parent);
}
private boolean find() {
go(root);
return found;
}
private RexSubQuery getExists(LogicalFilter filter) {
RexSubQuery[] existsSubQuery = { null };
filter.getCondition().accept(new RexVisitorImpl<Void>(true) {
@Override
public Void visitSubQuery(RexSubQuery subQuery) {
if (subQuery.getKind() == SqlKind.EXISTS) {
existsSubQuery[0] = subQuery;
}
return super.visitSubQuery(subQuery);
}
});
return existsSubQuery[0];
}
}
return new NestedExistsFinder().find();
}
use of org.apache.calcite.rel.logical.LogicalFilter in project samza by apache.
the class TestQueryPlanner method testRemoteJoinWithFilterHelper.
void testRemoteJoinWithFilterHelper(boolean enableOptimizer) throws SamzaSqlValidatorException {
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(1);
String sql = "Insert into testavro.enrichedPageViewTopic " + "select pv.pageKey as __key__, pv.pageKey as pageKey, coalesce(null, 'N/A') as companyName," + " p.name as profileName, p.address as profileAddress " + "from testavro.PAGEVIEW as pv " + "join testRemoteStore.Profile.`$table` as p " + " on p.__key__ = pv.profileId" + " where p.name = pv.pageKey AND p.name = 'Mike' AND pv.profileId = 1";
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMT, sql);
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_ENABLE_PLAN_OPTIMIZER, Boolean.toString(enableOptimizer));
Config samzaConfig = new MapConfig(staticConfigs);
DslConverter dslConverter = new SamzaSqlDslConverterFactory().create(samzaConfig);
Collection<RelRoot> relRoots = dslConverter.convertDsl(sql);
/*
Query plan without optimization:
LogicalProject(__key__=[$1], pageKey=[$1], companyName=['N/A'], profileName=[$5], profileAddress=[$7])
LogicalFilter(condition=[AND(=($5, $1), =($5, 'Mike'), =($2, 1))])
LogicalJoin(condition=[=($3, $2)], joinType=[inner])
LogicalTableScan(table=[[testavro, PAGEVIEW]])
LogicalTableScan(table=[[testRemoteStore, Profile, $table]])
Query plan with optimization:
LogicalProject(__key__=[$1], pageKey=[$1], companyName=['N/A'], profileName=[$5], profileAddress=[$7])
LogicalFilter(condition=[AND(=($5, $1), =($5, 'Mike'))])
LogicalJoin(condition=[=($3, $2)], joinType=[inner])
LogicalFilter(condition=[=($2, 1)])
LogicalTableScan(table=[[testavro, PAGEVIEW]])
LogicalTableScan(table=[[testRemoteStore, Profile, $table]])
*/
assertEquals(1, relRoots.size());
RelRoot relRoot = relRoots.iterator().next();
RelNode relNode = relRoot.rel;
assertTrue(relNode instanceof LogicalProject);
relNode = relNode.getInput(0);
assertTrue(relNode instanceof LogicalFilter);
if (enableOptimizer) {
assertEquals("AND(=($1, $5), =($5, 'Mike'))", ((LogicalFilter) relNode).getCondition().toString());
} else {
assertEquals("AND(=(1, $2), =($1, $5), =($5, 'Mike'))", ((LogicalFilter) relNode).getCondition().toString());
}
relNode = relNode.getInput(0);
assertTrue(relNode instanceof LogicalJoin);
assertEquals(2, relNode.getInputs().size());
LogicalJoin join = (LogicalJoin) relNode;
RelNode left = join.getLeft();
RelNode right = join.getRight();
assertTrue(right instanceof LogicalTableScan);
if (enableOptimizer) {
assertTrue(left instanceof LogicalFilter);
assertEquals("=(1, $2)", ((LogicalFilter) left).getCondition().toString());
assertTrue(left.getInput(0) instanceof LogicalTableScan);
} else {
assertTrue(left instanceof LogicalTableScan);
}
}
use of org.apache.calcite.rel.logical.LogicalFilter in project samza by apache.
the class JoinTranslator method isValidRemoteJoinRef.
/**
* Helper method to check if the join condition can be evaluated by the remote table.
* It does follow single path using the index ref path checking if it is a simple reference all the way to table scan.
* In case any RexCall is encountered will stop an return null as a marker otherwise will return Column Name.
*
* @param inputRexIndex rex ref index
* @param relNode current Rel Node
* @return false if any Relational Expression is encountered on the path, true if is simple ref to __key__ column.
*/
private static boolean isValidRemoteJoinRef(int inputRexIndex, RelNode relNode) {
if (relNode instanceof TableScan) {
return relNode.getRowType().getFieldList().get(inputRexIndex).getName().equals(SamzaSqlRelMessage.KEY_NAME);
}
// has to be a single rel kind filter/project/table scan
Preconditions.checkState(relNode.getInputs().size() == 1, "Has to be single input RelNode and got " + relNode.getDigest());
if (relNode instanceof LogicalFilter) {
return isValidRemoteJoinRef(inputRexIndex, relNode.getInput(0));
}
RexNode inputRef = ((LogicalProject) relNode).getProjects().get(inputRexIndex);
if (inputRef instanceof RexCall) {
// we can not push any expression as of now stop and return null.
return false;
}
return isValidRemoteJoinRef(((RexInputRef) inputRef).getIndex(), relNode.getInput(0));
}
Aggregations