Search in sources :

Example 1 with HazelcastRelOptTable

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

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

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

the class IndexResolver method createFullIndexScan.

/**
 * Creates an index scan without any filter.
 *
 * @param scan              the original scan operator
 * @param index             available indexes
 * @param ascs              the collation of index fields
 * @param nonEmptyCollation whether to filter out full index scan with no collation
 * @return index scan or {@code null}
 */
private static RelNode createFullIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<Boolean> ascs, boolean nonEmptyCollation) {
    assert isIndexSupported(index);
    RexNode scanFilter = OptUtils.extractHazelcastTable(scan).getFilter();
    RelTraitSet traitSet = OptUtils.toPhysicalConvention(scan.getTraitSet());
    RelCollation relCollation = buildCollationTrait(scan, index, ascs);
    if (nonEmptyCollation && relCollation.getFieldCollations().size() == 0) {
        // Don't make a full scan with empty collation
        return null;
    }
    traitSet = OptUtils.traitPlus(traitSet, relCollation);
    HazelcastRelOptTable originalRelTable = (HazelcastRelOptTable) scan.getTable();
    HazelcastTable originalHazelcastTable = OptUtils.extractHazelcastTable(scan);
    RelOptTable newRelTable = createRelTable(originalRelTable.getDelegate().getQualifiedName(), originalHazelcastTable.withFilter(null), scan.getCluster().getTypeFactory());
    return new IndexScanMapPhysicalRel(scan.getCluster(), traitSet, newRelTable, index, null, null, scanFilter);
}
Also used : IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) RelCollation(org.apache.calcite.rel.RelCollation) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptTable(org.apache.calcite.plan.RelOptTable) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode)

Example 4 with HazelcastRelOptTable

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

the class IndexResolver method createIndexScan.

private static IndexScanMapPhysicalRel createIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<RexNode> conjunctions, List<IndexComponentFilter> filterDescriptors, List<Boolean> ascs) {
    // Collect filters and relevant expressions
    List<IndexFilter> filters = new ArrayList<>(filterDescriptors.size());
    Set<RexNode> exps = new HashSet<>();
    for (IndexComponentFilter filterDescriptor : filterDescriptors) {
        filters.add(filterDescriptor.getFilter());
        exps.addAll(filterDescriptor.getExpressions());
    }
    // Construct Calcite expressions.
    RexBuilder rexBuilder = scan.getCluster().getRexBuilder();
    RexNode exp = RexUtil.composeConjunction(rexBuilder, exps);
    List<RexNode> remainderConjunctiveExps = excludeNodes(conjunctions, exps);
    RexNode remainderExp = remainderConjunctiveExps.isEmpty() ? null : RexUtil.composeConjunction(rexBuilder, remainderConjunctiveExps);
    // Prepare traits
    RelTraitSet traitSet = scan.getTraitSet();
    // Make a collation trait
    RelCollation relCollation = buildCollationTrait(scan, index, ascs);
    traitSet = OptUtils.traitPlus(traitSet, relCollation);
    // Prepare table
    HazelcastRelOptTable originalRelTable = (HazelcastRelOptTable) scan.getTable();
    HazelcastTable originalHazelcastTable = OptUtils.extractHazelcastTable(scan);
    RelOptTable newRelTable = createRelTable(originalRelTable, originalHazelcastTable.withFilter(null), scan.getCluster().getTypeFactory());
    // Try composing the final filter out of the isolated component filters if possible
    IndexFilter filter = composeFilter(filters, index.getType(), index.getComponentsCount());
    if (filter == null) {
        return null;
    }
    // Construct the scan
    return new IndexScanMapPhysicalRel(scan.getCluster(), OptUtils.toPhysicalConvention(traitSet), newRelTable, index, filter, exp, remainderExp);
}
Also used : ArrayList(java.util.ArrayList) RelTraitSet(org.apache.calcite.plan.RelTraitSet) IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) RelCollation(org.apache.calcite.rel.RelCollation) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) RexBuilder(org.apache.calcite.rex.RexBuilder) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) RelOptTable(org.apache.calcite.plan.RelOptTable) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode) HashSet(java.util.HashSet)

Example 5 with HazelcastRelOptTable

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

the class OptUtils method createRelTable.

public static HazelcastRelOptTable createRelTable(List<String> names, HazelcastTable hazelcastTable, RelDataTypeFactory typeFactory) {
    RelDataType rowType = hazelcastTable.getRowType(typeFactory);
    RelOptTableImpl relTable = RelOptTableImpl.create(null, rowType, names, hazelcastTable, null);
    return new HazelcastRelOptTable(relTable);
}
Also used : HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) RelOptTableImpl(org.apache.calcite.prepare.RelOptTableImpl) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

HazelcastRelOptTable (com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable)7 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)4 RexNode (org.apache.calcite.rex.RexNode)4 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)2 RelOptTable (org.apache.calcite.plan.RelOptTable)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 RelCollation (org.apache.calcite.rel.RelCollation)2 JetTable (com.hazelcast.jet.sql.impl.schema.JetTable)1 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 RelOptTableImpl (org.apache.calcite.prepare.RelOptTableImpl)1 Filter (org.apache.calcite.rel.core.Filter)1 Project (org.apache.calcite.rel.core.Project)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1