use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testPredicateStringAttribute.
private void testPredicateStringAttribute(IMap<Integer, Value> map) {
map.put(1, new Value("abc"));
map.put(2, new Value("xyz"));
map.put(3, new Value("aaa"));
map.put(4, new Value("zzz"));
map.put(5, new Value("klm"));
map.put(6, new Value("prs"));
map.put(7, new Value("prs"));
map.put(8, new Value("def"));
map.put(9, new Value("qwx"));
assertEquals(8, map.values(new SqlPredicate("name > 'aac'")).size());
assertEquals(9, map.values(new SqlPredicate("name between 'aaa' and 'zzz'")).size());
assertEquals(7, map.values(new SqlPredicate("name < 't'")).size());
assertEquals(6, map.values(new SqlPredicate("name >= 'gh'")).size());
assertEquals(8, map.values(new PredicateBuilder().getEntryObject().get("name").greaterThan("aac")).size());
assertEquals(9, map.values(new PredicateBuilder().getEntryObject().get("name").between("aaa", "zzz")).size());
assertEquals(7, map.values(new PredicateBuilder().getEntryObject().get("name").lessThan("t")).size());
assertEquals(6, map.values(new PredicateBuilder().getEntryObject().get("name").greaterEqual("gh")).size());
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testPredicateEnumAttribute.
private void testPredicateEnumAttribute(IMap<Integer, NodeType> map) {
map.put(1, NodeType.MEMBER);
map.put(2, NodeType.LITE_MEMBER);
map.put(3, NodeType.JAVA_CLIENT);
assertEquals(NodeType.MEMBER, map.values(new SqlPredicate("this=MEMBER")).iterator().next());
assertEquals(2, map.values(new SqlPredicate("this in (MEMBER, LITE_MEMBER)")).size());
assertEquals(NodeType.JAVA_CLIENT, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.JAVA_CLIENT)).iterator().next());
assertEquals(0, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.CSHARP_CLIENT)).size());
assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("this").in(NodeType.LITE_MEMBER, NodeType.MEMBER)).size());
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method queryWithThis.
@Test(timeout = 1000 * 60)
public void queryWithThis() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, String> map = instance.getMap("queryWithThis");
map.addIndex("this", false);
for (int i = 0; i < 1000; i++) {
map.put("" + i, "" + i);
}
Predicate predicate = new PredicateBuilder().getEntryObject().get("this").equal("10");
Collection<String> set = map.values(predicate);
assertEquals(1, set.size());
assertEquals(1, map.values(new SqlPredicate("this=15")).size());
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testInPredicate.
@Test(timeout = 1000 * 60)
public void testInPredicate() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, SampleObjects.ValueType> map = instance.getMap("testIteratorContract");
map.put("1", new ValueType("one"));
map.put("2", new ValueType("two"));
map.put("3", new ValueType("three"));
map.put("4", new ValueType("four"));
map.put("5", new ValueType("five"));
map.put("6", new ValueType("six"));
map.put("7", new ValueType("seven"));
Predicate predicate = new SqlPredicate("typeName in ('one','two')");
for (int i = 0; i < 10; i++) {
Collection<SampleObjects.ValueType> values = map.values(predicate);
assertEquals(2, values.size());
}
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class MapTransactionTest method testValues_shouldNotDeduplicateEntriesWhenGettingByPredicate.
@Test
public void testValues_shouldNotDeduplicateEntriesWhenGettingByPredicate() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName();
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap map = node.getMap(mapName);
final Employee emp = new Employee("name", 77, true, 10D);
map.put(1, emp);
node.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Integer, Employee> txMap = context.getMap(mapName);
txMap.put(2, emp);
Collection<Employee> coll = txMap.values(new SqlPredicate("age = 77"));
assertEquals(2, coll.size());
return true;
}
});
node.shutdown();
}
Aggregations