use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexEqualsFilterTest method testEquals.
@Test
public void testEquals() {
IndexEqualsFilter filter = new IndexEqualsFilter(intValue(1, true));
checkEquals(filter, new IndexEqualsFilter(intValue(1, true)), true);
checkEquals(filter, new IndexEqualsFilter(intValue(2, true)), false);
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexEqualsFilterTest method testContent.
@Test
public void testContent() {
IndexFilterValue value = intValue(1, true);
IndexEqualsFilter filter = new IndexEqualsFilter(value);
assertSame(value, filter.getValue());
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexResolver method selectComponentFilter.
/**
* This method selects the best expression to be used as index filter from the list of candidates.
*
* @param type type of the index (SORTED, HASH)
* @param candidates candidates that might be used as a filter
* @param converterType expected converter type for the given component of the index
* @return filter for the index component or {@code null} if no candidate could be applied
*/
@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity" })
private static IndexComponentFilter selectComponentFilter(IndexType type, List<IndexComponentCandidate> candidates, QueryDataType converterType) {
// First look for equality conditions, assuming that it is the most restrictive
for (IndexComponentCandidate candidate : candidates) {
if (candidate.getFilter() instanceof IndexEqualsFilter) {
return new IndexComponentFilter(candidate.getFilter(), singletonList(candidate.getExpression()), converterType);
}
}
// Next look for IN, as it is worse than equality on a single value, but better than range
for (IndexComponentCandidate candidate : candidates) {
if (candidate.getFilter() instanceof IndexInFilter) {
return new IndexComponentFilter(candidate.getFilter(), singletonList(candidate.getExpression()), converterType);
}
}
// Last, look for ranges
if (type == SORTED) {
IndexFilterValue from = null;
boolean fromInclusive = false;
IndexFilterValue to = null;
boolean toInclusive = false;
List<RexNode> expressions = new ArrayList<>(2);
for (IndexComponentCandidate candidate : candidates) {
if (!(candidate.getFilter() instanceof IndexRangeFilter)) {
continue;
}
IndexRangeFilter candidateFilter = (IndexRangeFilter) candidate.getFilter();
if (from == null && candidateFilter.getFrom() != null) {
from = candidateFilter.getFrom();
fromInclusive = candidateFilter.isFromInclusive();
expressions.add(candidate.getExpression());
}
if (to == null && candidateFilter.getTo() != null) {
to = candidateFilter.getTo();
toInclusive = candidateFilter.isToInclusive();
expressions.add(candidate.getExpression());
}
}
if (from != null || to != null) {
IndexRangeFilter filter = new IndexRangeFilter(from, fromInclusive, to, toInclusive);
return new IndexComponentFilter(filter, expressions, converterType);
}
}
// Cannot create an index request for the given candidates
return null;
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexResolver method fillNonTerminalComponents.
/**
* Given the list of column filters, flatten their expressions and allow-null flags.
* <p>
* The operation is performed for all filters except for the last one, because treatment of the last filter might differ
* depending on the total number of components in the index.
*
* @param filters column filters
* @param components expressions that would form the final filter
* @param allowNulls allow-null collection relevant to components
*/
private static void fillNonTerminalComponents(List<IndexFilter> filters, List<Expression> components, List<Boolean> allowNulls) {
for (int i = 0; i < filters.size() - 1; i++) {
IndexEqualsFilter filter0 = (IndexEqualsFilter) filters.get(i);
IndexFilterValue value = filter0.getValue();
assert value.getComponents().size() == 1;
components.add(value.getComponents().get(0));
allowNulls.add(value.getAllowNulls().get(0));
}
assert components.size() == filters.size() - 1;
assert allowNulls.size() == filters.size() - 1;
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter in project hazelcast by hazelcast.
the class IndexResolver method composeInFilter.
/**
* Create the final IN filter from the collection of per-column filters.
* <p>
* Consider the expression {@code {a=1 AND b IN (2,3)}}. After the conversion, the composite filter will be
* {@code {a,b} IN {{1, 2}, {1, 3}}}.
*
* @param filters per-column filters
* @param lastFilter the last IN filter
* @param indexComponentsCount the number of index components
* @return composite IN filter
*/
private static IndexFilter composeInFilter(List<IndexFilter> filters, IndexInFilter lastFilter, IndexType indexType, int indexComponentsCount) {
List<IndexFilter> newFilters = new ArrayList<>(lastFilter.getFilters().size());
for (IndexFilter filter : lastFilter.getFilters()) {
assert filter instanceof IndexEqualsFilter;
IndexFilter newFilter = composeEqualsFilter(filters, (IndexEqualsFilter) filter, indexType, indexComponentsCount);
if (newFilter == null) {
// Cannot create a filter for one of the values of the IN clause. Stop.
return null;
}
newFilters.add(newFilter);
}
return new IndexInFilter(newFilters);
}
Aggregations