Search in sources :

Example 6 with IndexFilter

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

the class IndexIterationPointer method createFromIndexFilterInt.

private static void createFromIndexFilterInt(IndexFilter indexFilter, boolean descending, ExpressionEvalContext evalContext, List<IndexIterationPointer> result) {
    if (indexFilter == null) {
        result.add(create(null, true, null, true, descending, null));
    }
    if (indexFilter instanceof IndexRangeFilter) {
        IndexRangeFilter rangeFilter = (IndexRangeFilter) indexFilter;
        Comparable<?> from = null;
        if (rangeFilter.getFrom() != null) {
            Comparable<?> fromValue = rangeFilter.getFrom().getValue(evalContext);
            // produces UNKNOWN result.
            if (fromValue == null) {
                return;
            }
            from = fromValue;
        }
        Comparable<?> to = null;
        if (rangeFilter.getTo() != null) {
            Comparable<?> toValue = rangeFilter.getTo().getValue(evalContext);
            // Same comment above for expressions like a < NULL.
            if (toValue == null) {
                return;
            }
            to = toValue;
        }
        result.add(create(from, rangeFilter.isFromInclusive(), to, rangeFilter.isToInclusive(), descending, null));
    } else if (indexFilter instanceof IndexEqualsFilter) {
        IndexEqualsFilter equalsFilter = (IndexEqualsFilter) indexFilter;
        Comparable<?> value = equalsFilter.getComparable(evalContext);
        result.add(create(value, true, value, true, descending, null));
    } else if (indexFilter instanceof IndexInFilter) {
        IndexInFilter inFilter = (IndexInFilter) indexFilter;
        for (IndexFilter filter : inFilter.getFilters()) {
            createFromIndexFilterInt(filter, descending, evalContext, result);
        }
    }
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexInFilter(com.hazelcast.sql.impl.exec.scan.index.IndexInFilter) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter)

Example 7 with IndexFilter

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

the class MapIndexScanPTest method test_whenBothFiltersAndSpecificProjectionExists_sorted.

@Test
public void test_whenBothFiltersAndSpecificProjectionExists_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
        if (i > count / 2) {
            if (i % 2 == 1) {
                expected.add(jetRow((count - i + 1), "value-" + (count - i + 1), (count - i + 1)));
            }
        }
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    Expression<Boolean> remainingFilter = new FunctionalPredicateExpression(row -> {
        int value = row.get(0);
        return value % 2 == 0;
    });
    IndexFilter filter = new IndexRangeFilter(intValue(0), true, intValue(count / 2), true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, remainingFilter, 0, false);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : ArrayList(java.util.ArrayList) JobConfig(com.hazelcast.jet.config.JobConfig) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) FunctionalPredicateExpression(com.hazelcast.sql.impl.expression.FunctionalPredicateExpression) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with IndexFilter

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

the class MapIndexScanPTest method test_whenFilterAndSpecificProjectionExists_sorted.

@Test
public void test_whenFilterAndSpecificProjectionExists_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
        if (i > count / 2) {
            expected.add(jetRow((count - i + 1), "value-" + (count - i + 1), (count - i + 1)));
        }
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexRangeFilter(intValue(0), true, intValue(count / 2), true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 0, false);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with IndexFilter

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

the class MapIndexScanPTest method test_fullScanAsc_sorted.

@Test
public void test_fullScanAsc_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
        expected.add(jetRow((count - i + 1), "value-" + (count - i + 1), (count - i + 1)));
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexRangeFilter(null, true, null, true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 2, false);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with IndexFilter

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

the class MapIndexScanPTest method test_fullScanDesc_sorted.

@Test
public void test_fullScanDesc_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = 0; i <= count; i++) {
        map.put(i, new Person("value-" + i, i));
        expected.add(jetRow((count - i), "value-" + (count - i), (count - i)));
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexRangeFilter(null, true, null, true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 2, true);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)15 ArrayList (java.util.ArrayList)10 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)9 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)8 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 IndexConfig (com.hazelcast.config.IndexConfig)6 JobConfig (com.hazelcast.jet.config.JobConfig)6 MapIndexScanMetadata (com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata)6 IndexInFilter (com.hazelcast.sql.impl.exec.scan.index.IndexInFilter)6 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 IndexFilterValue (com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue)4 RexInputRef (org.apache.calcite.rex.RexInputRef)4 RexNode (org.apache.calcite.rex.RexNode)4 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)2 HazelcastRelOptTable (com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable)2 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)2 BoundType (com.google.common.collect.BoundType)1 Iterables (com.google.common.collect.Iterables)1