Search in sources :

Example 11 with IndexEqualsFilter

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

the class MapIndexScanPTest method test_pointLookup_hashed.

// We also don't test full hash index scan, because such plan aren't allowed to be created.
@Test
public void test_pointLookup_hashed() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
    }
    expected.add(jetRow((5), "value-5", 5));
    IndexConfig indexConfig = new IndexConfig(IndexType.HASH, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexEqualsFilter(intValue(5));
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, -1, 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 : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) 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 IndexEqualsFilter

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

the class IndexEqualsFilterIterationTest method checkIteratorSimple.

private void checkIteratorSimple(IndexType indexType) {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(indexType).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(1)).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(1, new Value(1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(1)).getEntries(index, descendingDirection, evalContext), 1);
    // Check multiple values.
    map.put(2, new Value(1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(1)).getEntries(index, descendingDirection, evalContext), 1, 2);
    // Check null value.
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, true)).getEntries(index, descendingDirection, evalContext));
    map.put(3, new Value(null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, true)).getEntries(index, descendingDirection, evalContext), 3);
    map.put(4, new Value(null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, true)).getEntries(index, descendingDirection, evalContext), 3, 4);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

Example 13 with IndexEqualsFilter

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

the class IndexEqualsFilterIterationTest method checkIteratorComposite.

private void checkIteratorComposite(IndexType indexType) {
    HazelcastInstance instance = factory.newHazelcastInstance();
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(indexType).addAttribute("value1").addAttribute("value2"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext));
    map.put(1, new Value(1, 1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext));
    map.put(2, new Value(2, 1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(3, new Value(1, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext), 3);
    // Check multiple values.
    map.put(4, new Value(1, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext), 3, 4);
    // Check null values (first).
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, 2, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, 2, false)).getEntries(index, descendingDirection, evalContext));
    map.put(5, new Value(null, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, 2, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, 2, false)).getEntries(index, descendingDirection, evalContext), 5);
    map.put(6, new Value(null, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, 2, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, 2, false)).getEntries(index, descendingDirection, evalContext), 5, 6);
    // Check null values (last).
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, true)).getEntries(index, descendingDirection, evalContext));
    map.put(7, new Value(1, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, true)).getEntries(index, descendingDirection, evalContext), 7);
    map.put(8, new Value(1, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, true)).getEntries(index, descendingDirection, evalContext), 7, 8);
    // Check null values (both).
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, true)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, true)).getEntries(index, descendingDirection, evalContext));
    map.put(9, new Value(null, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, true)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, true)).getEntries(index, descendingDirection, evalContext), 9);
    map.put(10, new Value(null, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, true)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, true)).getEntries(index, descendingDirection, evalContext), 9, 10);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

Example 14 with IndexEqualsFilter

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

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

Aggregations

IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)22 IndexFilterValue (com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue)9 IndexInFilter (com.hazelcast.sql.impl.exec.scan.index.IndexInFilter)9 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)8 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)6 ArrayList (java.util.ArrayList)6 IndexConfig (com.hazelcast.config.IndexConfig)3 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)3 RexInputRef (org.apache.calcite.rex.RexInputRef)3 RexNode (org.apache.calcite.rex.RexNode)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 InternalIndex (com.hazelcast.query.impl.InternalIndex)2 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)2 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 JobConfig (com.hazelcast.jet.config.JobConfig)1 RexToExpression (com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpression)1