use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryIndexTest method testInnerIndex.
@Test(timeout = 1000 * 60)
public void testInnerIndex() {
HazelcastInstance instance = createTestHazelcastInstance();
IMap<String, SampleTestObjects.Value> map = instance.getMap("default");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.HASH, "type.typeName");
for (int i = 0; i < 10; i++) {
Value v = new Value("name" + i, i < 5 ? null : new ValueType("type" + i), i);
map.put("" + i, v);
}
Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("type.typeName").in("type8", "type6");
Collection<SampleTestObjects.Value> values = map.values(predicate);
assertEquals(2, values.size());
List<String> typeNames = new ArrayList<>();
for (Value configObject : values) {
typeNames.add(configObject.getType().getTypeName());
}
String[] array = typeNames.toArray(new String[0]);
Arrays.sort(array);
assertArrayEquals(typeNames.toString(), new String[] { "type6", "type8" }, array);
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryIndexTest method testInnerIndexSql.
@Test(timeout = 1000 * 60)
public void testInnerIndexSql() {
HazelcastInstance instance = createTestHazelcastInstance();
IMap<String, SampleTestObjects.Value> map = instance.getMap("default");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.HASH, "type.typeName");
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i, new ValueType("type" + i), i);
map.put("" + i, v);
}
Predicate predicate = Predicates.sql("type.typeName='type1'");
Collection<SampleTestObjects.Value> values = map.values(predicate);
assertEquals(1, values.size());
List<String> typeNames = new ArrayList<>();
for (Value configObject : values) {
typeNames.add(configObject.getType().getTypeName());
}
assertArrayEquals(typeNames.toString(), new String[] { "type1" }, typeNames.toArray(new String[0]));
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class PredicatesTest method testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed.
@Test
@Ignore("now will execute partition number of times")
public void testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed() {
final HazelcastInstance instance = createHazelcastInstance();
final IMap<Object, Object> map = instance.getMap("map");
map.addIndex(IndexType.HASH, "name");
String name = randomString();
map.put("key", new Value(name));
final ShouldExecuteOncePredicate<?, ?> indexAwareNotIndexedPredicate = new ShouldExecuteOncePredicate<>();
final EqualPredicate equalPredicate = new EqualPredicate("name", name);
final AndPredicate andPredicate = new AndPredicate(indexAwareNotIndexedPredicate, equalPredicate);
map.values(andPredicate);
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class IndexesTest method testIndex2.
@Test
public void testIndex2() {
Indexes indexes = Indexes.newBuilder(serializationService, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
indexes.putEntry(new QueryEntry(serializationService, toData(1), new Value("abc"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(2), new Value("xyz"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(3), new Value("aaa"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(4), new Value("zzz"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(5), new Value("klm"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(6), new Value("prs"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(7), new Value("prs"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(8), new Value("def"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(9), new Value("qwx"), newExtractor()), null, Index.OperationSource.USER);
assertEquals(8, size(indexes.query(new SqlPredicate("name > 'aac'"), SKIP_PARTITIONS_COUNT_CHECK)));
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method testPredicateStringAttributesWithIndex.
/**
* Github issues 98 and 131
*/
@Test(timeout = 1000 * 90)
public void testPredicateStringAttributesWithIndex() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<Integer, Value> map = instance.getMap("testPredicateStringWithStringIndex");
map.addIndex(IndexType.HASH, "name");
testPredicateStringAttribute(map);
}
Aggregations