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);
}
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);
}
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);
}
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);
}
}
}
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);
}
Aggregations