Search in sources :

Example 11 with IndexRangeFilter

use of com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter 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 12 with IndexRangeFilter

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

Example 13 with IndexRangeFilter

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

the class MapIndexScanPTest method test_whenFilterExistsWithoutSpecificProjection_sorted.

@Test
public void test_whenFilterExistsWithoutSpecificProjection_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, 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 14 with IndexRangeFilter

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

the class IndexRangeFilterIteratorTest method testIterator_composite.

/**
 * Test composite iterator. Note that parent components are always the same, therefore we do not test open bounds.
 */
@Test
public void testIterator_composite() {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1").addAttribute("value2"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    map.put(0, new Value(0, 0));
    map.put(1, new Value(0, 1));
    map.put(3, new Value(0, 3));
    map.put(4, new Value(0, 5));
    map.put(5, new Value(0, 6));
    map.put(6, new Value(2, 0));
    map.put(7, new Value(2, 1));
    map.put(8, new Value(2, 3));
    map.put(9, new Value(2, 5));
    map.put(10, new Value(2, 6));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext));
    map.put(11, new Value(1, 1));
    map.put(12, new Value(1, 1));
    map.put(13, new Value(1, 3));
    map.put(14, new Value(1, 3));
    map.put(15, new Value(1, 5));
    map.put(16, new Value(1, 5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext), 13, 14);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext), 13, 14, 15, 16);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext), 11, 12, 13, 14);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext), 11, 12, 13, 14, 15, 16);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with IndexRangeFilter

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

the class IndexRangeFilterIteratorTest method testIterator_simple_from.

@Test
public void testIterator_simple_from() {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    map.put(0, new Value(0));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, null, false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, null, false).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(1, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, null, false).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, null, false).getEntries(index, descendingDirection, evalContext));
    // Check multiple values.
    map.put(2, new Value(1));
    map.put(3, new Value(2));
    map.put(4, new Value(2));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, null, false).getEntries(index, descendingDirection, evalContext), 1, 2, 3, 4);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, null, false).getEntries(index, descendingDirection, evalContext), 3, 4);
    // Check null value.
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), true, null, false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, null, false).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 IndexConfig (com.hazelcast.config.IndexConfig)9 ArrayList (java.util.ArrayList)8 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)7 IndexFilterValue (com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue)7 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)6 JobConfig (com.hazelcast.jet.config.JobConfig)5 MapIndexScanMetadata (com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata)5 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)5 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 InternalIndex (com.hazelcast.query.impl.InternalIndex)4 IndexInFilter (com.hazelcast.sql.impl.exec.scan.index.IndexInFilter)3 RexToExpression (com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpression)2 ConstantExpression (com.hazelcast.sql.impl.expression.ConstantExpression)2 Expression (com.hazelcast.sql.impl.expression.Expression)2 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1