Search in sources :

Example 1 with IndexScanMapPhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel 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 2 with IndexScanMapPhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel in project hazelcast by hazelcast.

the class SqlIndexFromSearchFilterTest method when_selectWithRange_then_properPlanAndIndex.

@Test
public void when_selectWithRange_then_properPlanAndIndex() {
    String sql = "SELECT * FROM  \n" + mapName + " WHERE field1 >= 100\n" + " AND field1 <= 10000 \n";
    Result optimizePhysical = optimizePhysical(sql, parameterTypes(), table());
    assertPlan(optimizePhysical.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    assertPlan(optimizePhysical.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
    IndexScanMapPhysicalRel rel = (IndexScanMapPhysicalRel) optimizePhysical.getPhysical();
    assertEquals(F_1_INDEX, rel.getIndex().getName());
}
Also used : IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with IndexScanMapPhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel in project hazelcast by hazelcast.

the class SqlIndexFromSearchFilterTest method when_selectWithTwoRanges_then_properPlanAndIndex.

@Test
// https://github.com/hazelcast/hazelcast/issues/20748
@Ignore
public void when_selectWithTwoRanges_then_properPlanAndIndex() {
    String sql = "SELECT * FROM  \n" + mapName + " WHERE (field1 >= 100 AND field1 <= 10000) \n" + " OR (field1 >= 10100 AND field1 <= 20000) \n";
    Result optimizePhysical = optimizePhysical(sql, parameterTypes(), table());
    assertPlan(optimizePhysical.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    assertPlan(optimizePhysical.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
    IndexScanMapPhysicalRel rel = (IndexScanMapPhysicalRel) optimizePhysical.getPhysical();
    assertEquals(F_1_INDEX, rel.getIndex().getName());
}
Also used : IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with IndexScanMapPhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel in project hazelcast by hazelcast.

the class SqlIndexFromSearchFilterTest method when_selectWithRangeAndOrderBy_then_properPlanAndIndex.

@Test
public void when_selectWithRangeAndOrderBy_then_properPlanAndIndex() {
    String sql = "SELECT * FROM  \n" + mapName + " WHERE field1 >= 100\n" + " AND field1 <= 10000 \n" + " ORDER BY field2 ASC LIMIT 20 OFFSET 0";
    Result optimizePhysical = optimizePhysical(sql, parameterTypes(), table());
    assertPlan(optimizePhysical.getLogical(), plan(planRow(0, SortLogicalRel.class), planRow(1, FullScanLogicalRel.class)));
    assertPlan(optimizePhysical.getPhysical(), plan(planRow(0, SortPhysicalRel.class), planRow(1, IndexScanMapPhysicalRel.class)));
    IndexScanMapPhysicalRel rel = (IndexScanMapPhysicalRel) optimizePhysical.getPhysical().getInput(0);
    assertEquals(F_2_INDEX, rel.getIndex().getName());
}
Also used : IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with IndexScanMapPhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel 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)

Aggregations

IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 HazelcastRelOptTable (com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable)2 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)2 RelOptTable (org.apache.calcite.plan.RelOptTable)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 RelCollation (org.apache.calcite.rel.RelCollation)2 RexNode (org.apache.calcite.rex.RexNode)2 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 Ignore (org.junit.Ignore)1