Search in sources :

Example 6 with IndexInFilter

use of com.hazelcast.sql.impl.exec.scan.index.IndexInFilter in project hazelcast by hazelcast.

the class SqlDataSerializerHook method createFactory.

@SuppressWarnings("unchecked")
@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[QUERY_DATA_TYPE] = arg -> new QueryDataType();
    constructors[QUERY_ID] = arg -> new QueryId();
    constructors[ROW_HEAP] = arg -> new HeapRow();
    constructors[ROW_EMPTY] = arg -> EmptyRow.INSTANCE;
    constructors[LAZY_TARGET] = arg -> new LazyTarget();
    constructors[INDEX_FILTER_VALUE] = arg -> new IndexFilterValue();
    constructors[INDEX_FILTER_EQUALS] = arg -> new IndexEqualsFilter();
    constructors[INDEX_FILTER_RANGE] = arg -> new IndexRangeFilter();
    constructors[INDEX_FILTER_IN] = arg -> new IndexInFilter();
    constructors[EXPRESSION_COLUMN] = arg -> new ColumnExpression<>();
    constructors[EXPRESSION_IS_NULL] = arg -> new IsNullPredicate();
    constructors[TARGET_DESCRIPTOR_GENERIC] = arg -> GenericQueryTargetDescriptor.DEFAULT;
    constructors[QUERY_PATH] = arg -> new QueryPath();
    constructors[EXPRESSION_CONSTANT] = arg -> new ConstantExpression<>();
    constructors[EXPRESSION_PARAMETER] = arg -> new ParameterExpression<>();
    constructors[EXPRESSION_CAST] = arg -> new CastExpression<>();
    constructors[EXPRESSION_DIVIDE] = arg -> new DivideFunction<>();
    constructors[EXPRESSION_MINUS] = arg -> new MinusFunction<>();
    constructors[EXPRESSION_MULTIPLY] = arg -> new MultiplyFunction<>();
    constructors[EXPRESSION_PLUS] = arg -> new PlusFunction<>();
    constructors[EXPRESSION_UNARY_MINUS] = arg -> new UnaryMinusFunction<>();
    constructors[EXPRESSION_AND] = arg -> new AndPredicate();
    constructors[EXPRESSION_OR] = arg -> new OrPredicate();
    constructors[EXPRESSION_NOT] = arg -> new NotPredicate();
    constructors[EXPRESSION_COMPARISON] = arg -> new ComparisonPredicate();
    constructors[EXPRESSION_IS_TRUE] = arg -> new IsTruePredicate();
    constructors[EXPRESSION_IS_NOT_TRUE] = arg -> new IsNotTruePredicate();
    constructors[EXPRESSION_IS_FALSE] = arg -> new IsFalsePredicate();
    constructors[EXPRESSION_IS_NOT_FALSE] = arg -> new IsNotFalsePredicate();
    constructors[EXPRESSION_IS_NOT_NULL] = arg -> new IsNotNullPredicate();
    constructors[EXPRESSION_ABS] = arg -> new AbsFunction<>();
    constructors[EXPRESSION_SIGN] = arg -> new SignFunction<>();
    constructors[EXPRESSION_RAND] = arg -> new RandFunction();
    constructors[EXPRESSION_DOUBLE] = arg -> new DoubleFunction();
    constructors[EXPRESSION_FLOOR_CEIL] = arg -> new FloorCeilFunction<>();
    constructors[EXPRESSION_ROUND_TRUNCATE] = arg -> new RoundTruncateFunction<>();
    constructors[INTERVAL_YEAR_MONTH] = arg -> new SqlYearMonthInterval();
    constructors[INTERVAL_DAY_SECOND] = arg -> new SqlDaySecondInterval();
    constructors[EXPRESSION_ASCII] = arg -> new AsciiFunction();
    constructors[EXPRESSION_CHAR_LENGTH] = arg -> new CharLengthFunction();
    constructors[EXPRESSION_INITCAP] = arg -> new InitcapFunction();
    constructors[EXPRESSION_LOWER] = arg -> new LowerFunction();
    constructors[EXPRESSION_UPPER] = arg -> new UpperFunction();
    constructors[EXPRESSION_CONCAT] = arg -> new ConcatFunction();
    constructors[EXPRESSION_LIKE] = arg -> new LikeFunction();
    constructors[EXPRESSION_SUBSTRING] = arg -> new SubstringFunction();
    constructors[EXPRESSION_TRIM] = arg -> new TrimFunction();
    constructors[EXPRESSION_REPLACE] = arg -> new ReplaceFunction();
    constructors[EXPRESSION_POSITION] = arg -> new PositionFunction();
    constructors[EXPRESSION_REMAINDER] = arg -> new RemainderFunction<>();
    constructors[EXPRESSION_CONCAT_WS] = arg -> new ConcatWSFunction();
    constructors[EXPRESSION_CASE] = arg -> new CaseExpression<>();
    constructors[EXPRESSION_EXTRACT] = arg -> new ExtractFunction();
    constructors[EXPRESSION_DOUBLE_DOUBLE] = arg -> new DoubleBiFunction();
    constructors[EXPRESSION_TO_TIMESTAMP_TZ] = arg -> new ToTimestampTzFunction();
    constructors[EXPRESSION_TO_EPOCH_MILLIS] = arg -> new ToEpochMillisFunction();
    constructors[MAPPING] = arg -> new Mapping();
    constructors[MAPPING_FIELD] = arg -> new MappingField();
    constructors[EXPRESSION_SEARCHABLE] = arg -> new SearchableExpression<>();
    constructors[EXPRESSION_SEARCH] = arg -> new SearchPredicate();
    constructors[VIEW] = arg -> new View();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : ConcatWSFunction(com.hazelcast.sql.impl.expression.string.ConcatWSFunction) LowerFunction(com.hazelcast.sql.impl.expression.string.LowerFunction) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IsFalsePredicate(com.hazelcast.sql.impl.expression.predicate.IsFalsePredicate) Mapping(com.hazelcast.sql.impl.schema.Mapping) HeapRow(com.hazelcast.sql.impl.row.HeapRow) SearchPredicate(com.hazelcast.sql.impl.expression.predicate.SearchPredicate) PositionFunction(com.hazelcast.sql.impl.expression.string.PositionFunction) ConcatFunction(com.hazelcast.sql.impl.expression.string.ConcatFunction) IsNotTruePredicate(com.hazelcast.sql.impl.expression.predicate.IsNotTruePredicate) OrPredicate(com.hazelcast.sql.impl.expression.predicate.OrPredicate) ExtractFunction(com.hazelcast.sql.impl.expression.datetime.ExtractFunction) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) IsNullPredicate(com.hazelcast.sql.impl.expression.predicate.IsNullPredicate) UpperFunction(com.hazelcast.sql.impl.expression.string.UpperFunction) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField) DoubleBiFunction(com.hazelcast.sql.impl.expression.math.DoubleBiFunction) TrimFunction(com.hazelcast.sql.impl.expression.string.TrimFunction) ToEpochMillisFunction(com.hazelcast.sql.impl.expression.datetime.ToEpochMillisFunction) RandFunction(com.hazelcast.sql.impl.expression.math.RandFunction) CharLengthFunction(com.hazelcast.sql.impl.expression.string.CharLengthFunction) SqlYearMonthInterval(com.hazelcast.sql.impl.type.SqlYearMonthInterval) LikeFunction(com.hazelcast.sql.impl.expression.string.LikeFunction) ReplaceFunction(com.hazelcast.sql.impl.expression.string.ReplaceFunction) IsNotFalsePredicate(com.hazelcast.sql.impl.expression.predicate.IsNotFalsePredicate) ComparisonPredicate(com.hazelcast.sql.impl.expression.predicate.ComparisonPredicate) SubstringFunction(com.hazelcast.sql.impl.expression.string.SubstringFunction) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) ToTimestampTzFunction(com.hazelcast.sql.impl.expression.datetime.ToTimestampTzFunction) InitcapFunction(com.hazelcast.sql.impl.expression.string.InitcapFunction) AndPredicate(com.hazelcast.sql.impl.expression.predicate.AndPredicate) IndexInFilter(com.hazelcast.sql.impl.exec.scan.index.IndexInFilter) SqlDaySecondInterval(com.hazelcast.sql.impl.type.SqlDaySecondInterval) NotPredicate(com.hazelcast.sql.impl.expression.predicate.NotPredicate) View(com.hazelcast.sql.impl.schema.view.View) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) IsNotNullPredicate(com.hazelcast.sql.impl.expression.predicate.IsNotNullPredicate) DoubleFunction(com.hazelcast.sql.impl.expression.math.DoubleFunction) AsciiFunction(com.hazelcast.sql.impl.expression.string.AsciiFunction) IsTruePredicate(com.hazelcast.sql.impl.expression.predicate.IsTruePredicate) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)

Example 7 with IndexInFilter

use of com.hazelcast.sql.impl.exec.scan.index.IndexInFilter in project hazelcast by hazelcast.

the class IndexInFilterTest method testEquals.

@Test
public void testEquals() {
    IndexInFilter filter = new IndexInFilter(Collections.singletonList(new IndexEqualsFilter(intValue(1))));
    checkEquals(filter, new IndexInFilter(Collections.singletonList(new IndexEqualsFilter(intValue(1)))), true);
    checkEquals(filter, new IndexInFilter(Collections.singletonList(new IndexEqualsFilter(intValue(2)))), false);
}
Also used : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexInFilter(com.hazelcast.sql.impl.exec.scan.index.IndexInFilter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with IndexInFilter

use of com.hazelcast.sql.impl.exec.scan.index.IndexInFilter in project hazelcast by hazelcast.

the class IndexInFilterTest method testSerialization.

@Test
public void testSerialization() {
    IndexInFilter original = new IndexInFilter(Collections.singletonList(new IndexEqualsFilter(intValue(1))));
    IndexInFilter restored = serializeAndCheck(original, SqlDataSerializerHook.INDEX_FILTER_IN);
    checkEquals(original, restored, true);
}
Also used : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexInFilter(com.hazelcast.sql.impl.exec.scan.index.IndexInFilter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with IndexInFilter

use of com.hazelcast.sql.impl.exec.scan.index.IndexInFilter 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)

Example 10 with IndexInFilter

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

Aggregations

IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)10 IndexInFilter (com.hazelcast.sql.impl.exec.scan.index.IndexInFilter)10 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)6 IndexFilterValue (com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue)4 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)4 ArrayList (java.util.ArrayList)4 RexNode (org.apache.calcite.rex.RexNode)3 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 RexInputRef (org.apache.calcite.rex.RexInputRef)2 Test (org.junit.Test)2 BoundType (com.google.common.collect.BoundType)1 Iterables (com.google.common.collect.Iterables)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 IndexType (com.hazelcast.config.IndexType)1 HASH (com.hazelcast.config.IndexType.HASH)1 SORTED (com.hazelcast.config.IndexType.SORTED)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1