Search in sources :

Example 11 with IndexFilterValue

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);
}
Also used : IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with IndexFilterValue

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"));
    }
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryException(com.hazelcast.sql.impl.QueryException) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with IndexFilterValue

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());
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with IndexFilterValue

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());
}
Also used : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with IndexFilterValue

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;
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ArrayList(java.util.ArrayList) IndexInFilter(com.hazelcast.sql.impl.exec.scan.index.IndexInFilter) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

IndexFilterValue (com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue)17 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)7 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)3 IndexInFilter (com.hazelcast.sql.impl.exec.scan.index.IndexInFilter)3 Expression (com.hazelcast.sql.impl.expression.Expression)3 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)3 ArrayList (java.util.ArrayList)3 RexInputRef (org.apache.calcite.rex.RexInputRef)3 RexToExpression (com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpression)2 ConstantExpression (com.hazelcast.sql.impl.expression.ConstantExpression)2 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 QueryException (com.hazelcast.sql.impl.QueryException)1 ExtractFunction (com.hazelcast.sql.impl.expression.datetime.ExtractFunction)1 ToEpochMillisFunction (com.hazelcast.sql.impl.expression.datetime.ToEpochMillisFunction)1 ToTimestampTzFunction (com.hazelcast.sql.impl.expression.datetime.ToTimestampTzFunction)1