Search in sources :

Example 1 with JoinLogicalRel

use of com.hazelcast.jet.sql.impl.opt.logical.JoinLogicalRel in project hazelcast by hazelcast.

the class JoinPhysicalRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    JoinLogicalRel logicalJoin = call.rel(0);
    JoinRelType joinType = logicalJoin.getJoinType();
    if (joinType != JoinRelType.INNER && joinType != JoinRelType.LEFT) {
        throw new RuntimeException("Unexpected joinType: " + joinType);
    }
    RelNode leftInput = call.rel(1);
    RelNode rightInput = call.rel(2);
    if (OptUtils.isUnbounded(rightInput)) {
        // can be on the left side.
        return;
    }
    RelNode leftInputConverted = RelRule.convert(leftInput, leftInput.getTraitSet().replace(PHYSICAL));
    RelNode rightInputConverted = RelRule.convert(rightInput, rightInput.getTraitSet().replace(PHYSICAL));
    // we don't use hash join for unbounded left input because it doesn't refresh the right side
    if (OptUtils.isBounded(leftInput)) {
        RelNode rel = new JoinHashPhysicalRel(logicalJoin.getCluster(), logicalJoin.getTraitSet().replace(PHYSICAL), leftInputConverted, rightInputConverted, logicalJoin.getCondition(), logicalJoin.getJoinType());
        call.transformTo(rel);
    }
    if (rightInput instanceof TableScan) {
        HazelcastTable rightHzTable = rightInput.getTable().unwrap(HazelcastTable.class);
        if (SqlConnectorUtil.getJetSqlConnector(rightHzTable.getTarget()).isNestedLoopReaderSupported()) {
            RelNode rel2 = new JoinNestedLoopPhysicalRel(logicalJoin.getCluster(), OptUtils.toPhysicalConvention(logicalJoin.getTraitSet()), leftInputConverted, rightInputConverted, logicalJoin.getCondition(), logicalJoin.getJoinType());
            call.transformTo(rel2);
        }
    }
}
Also used : JoinRelType(org.apache.calcite.rel.core.JoinRelType) TableScan(org.apache.calcite.rel.core.TableScan) RelNode(org.apache.calcite.rel.RelNode) JoinLogicalRel(com.hazelcast.jet.sql.impl.opt.logical.JoinLogicalRel) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Aggregations

JoinLogicalRel (com.hazelcast.jet.sql.impl.opt.logical.JoinLogicalRel)1 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)1 RelNode (org.apache.calcite.rel.RelNode)1 JoinRelType (org.apache.calcite.rel.core.JoinRelType)1 TableScan (org.apache.calcite.rel.core.TableScan)1