use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalJoin in project flink by apache.
the class FlinkSemiAntiJoinProjectTransposeRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
LogicalJoin join = call.rel(0);
LogicalProject project = call.rel(1);
// only accept SEMI/ANTI join
JoinRelType joinType = join.getJoinType();
if (joinType != JoinRelType.SEMI && joinType != JoinRelType.ANTI) {
return false;
}
// all expressions in Project should be RexInputRef
for (RexNode p : project.getProjects()) {
if (!(p instanceof RexInputRef)) {
return false;
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalJoin 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.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalJoin in project flink by apache.
the class JoinTableFunctionScanToCorrelateRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
LogicalJoin join = call.rel(0);
RelNode leftInput = call.rel(1);
LogicalTableFunctionScan logicalTableFunctionScan = call.rel(2);
RelNode correlate = call.builder().push(leftInput).push(logicalTableFunctionScan).correlate(join.getJoinType(), join.getCluster().createCorrel()).build();
call.transformTo(correlate);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalJoin in project drill by axbaretto.
the class DrillJoinRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final LogicalJoin join = call.rel(0);
final RelNode left = join.getLeft();
final RelNode right = join.getRight();
final RelTraitSet traits = join.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
final RelNode convertedLeft = convert(left, left.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
final RelNode convertedRight = convert(right, right.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
List<Integer> leftKeys = Lists.newArrayList();
List<Integer> rightKeys = Lists.newArrayList();
List<Boolean> filterNulls = Lists.newArrayList();
boolean addFilter = false;
RexNode origJoinCondition = join.getCondition();
RexNode newJoinCondition = origJoinCondition;
RexNode remaining = RelOptUtil.splitJoinCondition(convertedLeft, convertedRight, origJoinCondition, leftKeys, rightKeys, filterNulls);
boolean hasEquijoins = leftKeys.size() == rightKeys.size() && leftKeys.size() > 0;
// For OUTER join, pulling up a non-eqivjoin filter will lead to incorrectly discarding qualified rows.
if (!remaining.isAlwaysTrue()) {
if (hasEquijoins && join.getJoinType() == JoinRelType.INNER) {
addFilter = true;
newJoinCondition = buildJoinCondition(convertedLeft, convertedRight, leftKeys, rightKeys, filterNulls, join.getCluster().getRexBuilder());
}
} else {
newJoinCondition = buildJoinCondition(convertedLeft, convertedRight, leftKeys, rightKeys, filterNulls, join.getCluster().getRexBuilder());
}
try {
if (!addFilter) {
RelNode joinRel = new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, newJoinCondition, join.getJoinType(), leftKeys, rightKeys);
call.transformTo(joinRel);
} else {
RelNode joinRel = new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, newJoinCondition, join.getJoinType(), leftKeys, rightKeys);
call.transformTo(new DrillFilterRel(join.getCluster(), traits, joinRel, remaining));
}
} catch (InvalidRelException e) {
tracer.warn(e.toString());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalJoin 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);
}
}
Aggregations