Search in sources :

Example 16 with IndexFilterValue

use of com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue 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;
}
Also used : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue)

Example 17 with IndexFilterValue

use of com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue 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);
}
Also used : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) RexInputRef(org.apache.calcite.rex.RexInputRef) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter)

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