use of org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan in project ignite-3 by apache.
the class ExposeIndexRule method onMatch.
/**
* {@inheritDoc}
*/
@Override
public void onMatch(RelOptRuleCall call) {
IgniteLogicalTableScan scan = call.rel(0);
RelOptCluster cluster = scan.getCluster();
RelOptTable optTable = scan.getTable();
InternalIgniteTable igniteTable = optTable.unwrap(InternalIgniteTable.class);
List<RexNode> proj = scan.projects();
RexNode condition = scan.condition();
ImmutableBitSet requiredCols = scan.requiredColumns();
List<IgniteLogicalIndexScan> indexes = igniteTable.indexes().keySet().stream().map(idxName -> igniteTable.toRel(cluster, optTable, idxName, proj, condition, requiredCols)).collect(Collectors.toList());
if (indexes.isEmpty()) {
return;
}
Map<RelNode, RelNode> equivMap = new HashMap<>(indexes.size());
for (int i = 1; i < indexes.size(); i++) {
equivMap.put(indexes.get(i), scan);
}
call.transformTo(indexes.get(0), equivMap);
}
use of org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan in project ignite-3 by apache.
the class LogicalOrToUnionRule method buildInput.
private void buildInput(RelBuilder relBldr, RelNode input, RexNode condition) {
IgniteLogicalTableScan scan = (IgniteLogicalTableScan) input;
// Set default traits, real traits will be calculated for physical node.
RelTraitSet trait = scan.getCluster().traitSet();
relBldr.push(IgniteLogicalTableScan.create(scan.getCluster(), trait, scan.getTable(), scan.projects(), condition, scan.requiredColumns()));
}
use of org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan in project ignite-3 by apache.
the class LogicalOrToUnionRule method idxCollationCheck.
/**
* Compares intersection (currently beginning position) of condition and index fields.
* This rule need to be triggered only if appropriate indexes will be found otherwise it`s not applicable.
*
* @param call Set of appropriate RelNode.
* @param operands Operands from OR expression.
*/
private boolean idxCollationCheck(RelOptRuleCall call, List<RexNode> operands) {
final IgniteLogicalTableScan scan = call.rel(0);
InternalIgniteTable tbl = scan.getTable().unwrap(InternalIgniteTable.class);
IgniteTypeFactory typeFactory = Commons.typeFactory(scan.getCluster());
int fieldCnt = tbl.getRowType(typeFactory).getFieldCount();
BitSet idxsFirstFields = new BitSet(fieldCnt);
for (IgniteIndex idx : tbl.indexes().values()) {
List<RelFieldCollation> fieldCollations = idx.collation().getFieldCollations();
if (!CollectionUtils.nullOrEmpty(fieldCollations)) {
idxsFirstFields.set(fieldCollations.get(0).getFieldIndex());
}
}
Mappings.TargetMapping mapping = scan.requiredColumns() == null ? null : Commons.inverseMapping(scan.requiredColumns(), fieldCnt);
for (RexNode op : operands) {
BitSet conditionFields = new BitSet(fieldCnt);
new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef inputRef) {
conditionFields.set(mapping == null ? inputRef.getIndex() : mapping.getSourceOpt(inputRef.getIndex()));
return inputRef;
}
}.apply(op);
if (!conditionFields.intersects(idxsFirstFields)) {
return false;
}
}
return true;
}
Aggregations