use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable 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