use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexResolver method createIndexScan.
/**
* Create index scan for the given index if possible.
*
* @param scan the original map scan
* @param index index to be considered
* @param conjunctions CNF components of the original map filter
* @param candidates resolved candidates
* @param ascs a list of index field collations
* @return index scan or {@code null}.
*/
public static RelNode createIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<RexNode> conjunctions, Map<Integer, List<IndexComponentCandidate>> candidates, List<Boolean> ascs) {
List<IndexComponentFilter> filters = new ArrayList<>(index.getFieldOrdinals().size());
// Iterate over every index component from the beginning and try to form a filter to it
for (int i = 0; i < index.getFieldOrdinals().size(); i++) {
int fieldOrdinal = index.getFieldOrdinals().get(i);
QueryDataType fieldConverterType = index.getFieldConverterTypes().get(i);
List<IndexComponentCandidate> fieldCandidates = candidates.get(fieldOrdinal);
if (fieldCandidates == null) {
// used for index filter.
break;
}
// Create the filter for the given index component if possible.
// Separate candidates are possibly merged into a single complex filter at this stage.
// Consider the index {a}, and the condition "WHERE a>1 AND a<5". In this case two distinct range candidates
// {>1} and {<5} are combined into a single RANGE filter {>1 AND <5}
IndexComponentFilter filter = selectComponentFilter(index.getType(), fieldCandidates, fieldConverterType);
if (filter == null) {
// Cannot create a filter for the given candidates, stop.
break;
}
filters.add(filter);
if (!(filter.getFilter() instanceof IndexEqualsFilter)) {
// {a>1} filter.
break;
}
}
if (filters.isEmpty()) {
// Failed to build any filters. The index cannot be used.
return null;
}
// Now as filters are determined, construct the physical entity.
return createIndexScan(scan, index, conjunctions, filters, ascs);
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexResolver method prepareSingleColumnCandidateIsNull.
/**
* Try creating a candidate filter for the "IS NULL" expression.
* <p>
* Returns the filter EQUALS(null) with "allowNulls-true".
*
* @param exp original expression, e.g. {col IS NULL}
* @param operand operand, e.g. {col}; CAST must be unwrapped before the method is invoked
* @return candidate or {@code null}
*/
private static IndexComponentCandidate prepareSingleColumnCandidateIsNull(RexNode exp, RexNode operand) {
if (operand.getKind() != SqlKind.INPUT_REF) {
// The operand is not a column, e.g. {'literal' IS NULL}, index cannot be used
return null;
}
int columnIndex = ((RexInputRef) operand).getIndex();
QueryDataType type = HazelcastTypeUtils.toHazelcastType(operand.getType());
// Create a value with "allowNulls=true"
IndexFilterValue filterValue = new IndexFilterValue(singletonList(ConstantExpression.create(null, type)), singletonList(true));
IndexFilter filter = new IndexEqualsFilter(filterValue);
return new IndexComponentCandidate(exp, columnIndex, filter);
}
Aggregations