use of com.hazelcast.config.IndexType.SORTED in project hazelcast by hazelcast.
the class IndexResolver method buildCollationTrait.
/**
* Builds a collation with collation fields re-mapped according to the table projections.
*
* @param scan the logical map scan
* @param index the index
* @param ascs the collation of index fields
* @return the new collation trait
*/
private static RelCollation buildCollationTrait(FullScanLogicalRel scan, MapTableIndex index, List<Boolean> ascs) {
if (index.getType() != SORTED) {
return RelCollations.of(Collections.emptyList());
}
List<RelFieldCollation> fields = new ArrayList<>(index.getFieldOrdinals().size());
HazelcastTable table = OptUtils.extractHazelcastTable(scan);
// Extract those projections that are direct input field references. Only those can be used
// for index access
List<Integer> fieldProjects = table.getProjects().stream().filter(expr -> expr instanceof RexInputRef).map(inputRef -> ((RexInputRef) inputRef).getIndex()).collect(Collectors.toList());
for (int i = 0; i < index.getFieldOrdinals().size(); ++i) {
Integer indexFieldOrdinal = index.getFieldOrdinals().get(i);
int remappedIndexFieldOrdinal = fieldProjects.indexOf(indexFieldOrdinal);
if (remappedIndexFieldOrdinal == -1) {
// The field is not used in the query
break;
}
Direction direction = ascs.get(i) ? ASCENDING : DESCENDING;
RelFieldCollation fieldCollation = new RelFieldCollation(remappedIndexFieldOrdinal, direction);
fields.add(fieldCollation);
}
return RelCollations.of(fields);
}
use of com.hazelcast.config.IndexType.SORTED in project hazelcast by hazelcast.
the class IndexResolver method prepareSingleColumnCandidates.
/**
* Creates a map from the scan column ordinal to expressions that could be potentially used by indexes created over
* this column.
*
* @param expressions CNF nodes
* @param allIndexedFieldOrdinals ordinals of all columns that have some indexes. Helps to filter out candidates that
* definitely cannot be used earlier.
*/
private static Map<Integer, List<IndexComponentCandidate>> prepareSingleColumnCandidates(List<RexNode> expressions, QueryParameterMetadata parameterMetadata, Set<Integer> allIndexedFieldOrdinals) {
Map<Integer, List<IndexComponentCandidate>> res = new HashMap<>();
// Iterate over each CNF component of the expression.
for (RexNode expression : expressions) {
// Try creating a candidate for the expression. The candidate is created iff the expression could be used
// by some index implementation (SORTED, HASH)
IndexComponentCandidate candidate = prepareSingleColumnCandidate(expression, parameterMetadata);
if (candidate == null) {
// Expression cannot be used by any index implementation, skip
continue;
}
if (!allIndexedFieldOrdinals.contains(candidate.getColumnIndex())) {
// Therefore, the expression could not be used, skip
continue;
}
// Group candidates by column. E.g. {a>1 AND a<3} is grouped into a single map entry: a->{>1},{<3}
res.computeIfAbsent(candidate.getColumnIndex(), (k) -> new ArrayList<>()).add(candidate);
}
return res;
}
Aggregations