use of com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue in project hazelcast by hazelcast.
the class IndexFilterValueTest method testEquals.
@Test
public void testEquals() {
IndexFilterValue value = new IndexFilterValue(singletonList(constant(1, QueryDataType.INT)), singletonList(true));
checkEquals(value, new IndexFilterValue(singletonList(constant(1, QueryDataType.INT)), singletonList(true)), true);
checkEquals(value, new IndexFilterValue(singletonList(constant(1, QueryDataType.BIGINT)), singletonList(true)), false);
checkEquals(value, new IndexFilterValue(singletonList(constant(1, QueryDataType.INT)), singletonList(false)), false);
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue in project hazelcast by hazelcast.
the class IndexFilterValueTest method testNonComparable.
@Test
public void testNonComparable() {
ExpressionEvalContext evalContext = createExpressionEvalContext();
IndexFilterValue value = new IndexFilterValue(singletonList(constant(new Object(), QueryDataType.OBJECT)), singletonList(true));
try {
value.getValue(evalContext);
fail("Must fail");
} catch (QueryException e) {
assertEquals(SqlErrorCode.DATA_EXCEPTION, e.getCode());
assertTrue(e.getMessage().contains("Values used in index lookups must be Comparable"));
}
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue in project hazelcast by hazelcast.
the class IndexRangeFilterTest method testContent.
@Test
public void testContent() {
IndexFilterValue from = intValue(1, true);
IndexFilterValue to = intValue(2, true);
IndexRangeFilter filter = new IndexRangeFilter(from, true, to, true);
assertSame(from, filter.getFrom());
assertTrue(filter.isFromInclusive());
assertSame(to, filter.getTo());
assertTrue(filter.isToInclusive());
}
use of com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue 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.IndexFilterValue 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;
}
Aggregations