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