Search in sources :

Example 1 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class FilterIntoScanLogicalRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    Filter filter = call.rel(0);
    FullScanLogicalRel scan = call.rel(1);
    HazelcastTable table = OptUtils.extractHazelcastTable(scan);
    RexNode existingCondition = table.getFilter();
    // inline the table projections into the merged condition. For example, if we have this relexp:
    // Filter[$0=?]
    // Scan[projects=[$1 + $2]
    // The filter condition will be converted to:
    // [$1 + $2 = ?]
    RexNode convertedCondition = inlineExpression(table.getProjects(), filter.getCondition());
    if (existingCondition != null) {
        convertedCondition = RexUtil.composeConjunction(scan.getCluster().getRexBuilder(), Arrays.asList(existingCondition, convertedCondition), true);
    }
    HazelcastRelOptTable convertedTable = OptUtils.createRelTable((HazelcastRelOptTable) scan.getTable(), table.withFilter(convertedCondition), scan.getCluster().getTypeFactory());
    FullScanLogicalRel rel = new FullScanLogicalRel(scan.getCluster(), OptUtils.toLogicalConvention(scan.getTraitSet()), convertedTable, scan.eventTimePolicyProvider(), scan.watermarkedColumnIndex());
    call.transformTo(rel);
}
Also used : Filter(org.apache.calcite.rel.core.Filter) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode)

Example 2 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class ProjectIntoScanLogicalRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    Project project = call.rel(0);
    FullScanLogicalRel scan = call.rel(1);
    HazelcastTable originalTable = OptUtils.extractHazelcastTable(scan);
    List<RexNode> newProjects = inlineExpressions(originalTable.getProjects(), project.getProjects());
    HazelcastRelOptTable convertedTable = OptUtils.createRelTable((HazelcastRelOptTable) scan.getTable(), originalTable.withProject(newProjects, project.getRowType()), scan.getCluster().getTypeFactory());
    FullScanLogicalRel rel = new FullScanLogicalRel(scan.getCluster(), OptUtils.toLogicalConvention(scan.getTraitSet()), convertedTable, scan.eventTimePolicyProvider(), scan.watermarkedColumnIndex());
    call.transformTo(rel);
}
Also used : Project(org.apache.calcite.rel.core.Project) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class JoinNestedLoopPhysicalRel method joinInfo.

public JetJoinInfo joinInfo(QueryParameterMetadata parameterMetadata) {
    List<Integer> leftKeys = analyzeCondition().leftKeys.toIntegerList();
    List<Integer> rightKeys = analyzeCondition().rightKeys.toIntegerList();
    HazelcastTable table = OptUtils.extractHazelcastTable(getRight());
    RexBuilder rexBuilder = getCluster().getRexBuilder();
    List<RexNode> additionalNonEquiConditions = new ArrayList<>();
    for (int i = 0; i < rightKeys.size(); i++) {
        Integer rightKeyIndex = rightKeys.get(i);
        RexNode rightExpr = table.getProjects().get(rightKeyIndex);
        if (rightExpr instanceof RexInputRef) {
            rightKeys.set(i, ((RexInputRef) rightExpr).getIndex());
        } else {
            // offset the indices in rightExp by the width of left row
            rightExpr = rightExpr.accept(new RexShuttle() {

                @Override
                public RexNode visitInputRef(RexInputRef inputRef) {
                    return rexBuilder.makeInputRef(inputRef.getType(), inputRef.getIndex() + getLeft().getRowType().getFieldCount());
                }
            });
            additionalNonEquiConditions.add(rexBuilder.makeCall(HazelcastSqlOperatorTable.EQUALS, rexBuilder.makeInputRef(getLeft(), leftKeys.get(i)), rightExpr));
            leftKeys.remove(i);
            rightKeys.remove(i);
            i--;
        }
    }
    Expression<Boolean> nonEquiCondition = filter(schema(parameterMetadata), RexUtil.composeConjunction(rexBuilder, asList(analyzeCondition().getRemaining(rexBuilder), RexUtil.composeConjunction(rexBuilder, additionalNonEquiConditions))), parameterMetadata);
    Expression<Boolean> condition = filter(schema(parameterMetadata), getCondition(), parameterMetadata);
    return new JetJoinInfo(getJoinType(), toIntArray(leftKeys), toIntArray(rightKeys), nonEquiCondition, condition);
}
Also used : RexShuttle(org.apache.calcite.rex.RexShuttle) ArrayList(java.util.ArrayList) JetJoinInfo(com.hazelcast.jet.sql.impl.JetJoinInfo) RexBuilder(org.apache.calcite.rex.RexBuilder) RexInputRef(org.apache.calcite.rex.RexInputRef) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode)

Example 4 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable 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)

Example 5 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class FullScanPhysicalRel method projection.

public List<Expression<?>> projection(QueryParameterMetadata parameterMetadata) {
    PlanNodeSchema schema = OptUtils.schema(getTable());
    HazelcastTable table = getTable().unwrap(HazelcastTable.class);
    return project(schema, table.getProjects(), parameterMetadata);
}
Also used : PlanNodeSchema(com.hazelcast.sql.impl.plan.node.PlanNodeSchema) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Aggregations

HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)70 Test (org.junit.Test)48 TableField (com.hazelcast.sql.impl.schema.TableField)8 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)8 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)8 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)7 RexNode (org.apache.calcite.rex.RexNode)7 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)6 Parameters (junitparams.Parameters)6 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)5 HazelcastRelOptTable (com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable)5 ArrayList (java.util.ArrayList)5 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)4 RelOptTable (org.apache.calcite.plan.RelOptTable)4 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 RelCollation (org.apache.calcite.rel.RelCollation)3 RelNode (org.apache.calcite.rel.RelNode)3 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)3 SqlValidatorTable (org.apache.calcite.sql.validate.SqlValidatorTable)3 RexBuilder (org.apache.calcite.rex.RexBuilder)2