use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientMapBasicTest method testKeySet_withPredicate.
@Test
public void testKeySet_withPredicate() {
int max = 44;
IMap<Integer, String> map = client.getMap(randomString());
Set<Integer> expected = new TreeSet<Integer>();
for (int key = 0; key < max; key++) {
String value = key + "value";
map.put(key, value);
}
expected.add(4);
Set<Integer> keySet = map.keySet(new SqlPredicate("this == 4value"));
assertEquals(expected, keySet);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class MapMBean method values.
@ManagedAnnotation(value = "values", operation = true)
public String values(String query) {
Collection coll;
if (query != null && !query.isEmpty()) {
Predicate predicate = new SqlPredicate(query);
coll = managedObject.values(predicate);
} else {
coll = managedObject.values();
}
StringBuilder buf = new StringBuilder();
if (coll.size() == 0) {
buf.append("Empty");
} else {
buf.append("[");
for (Object obj : coll) {
buf.append(obj);
buf.append(", ");
}
buf.replace(buf.length() - 1, buf.length(), "]");
}
return buf.toString();
}
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 IndexesTest method shouldReturnNull_whenQueryingOnKeys.
private void shouldReturnNull_whenQueryingOnKeys(Indexes indexes) {
for (int i = 0; i < 50; i++) {
// passing null value to QueryEntry
indexes.saveEntryIndex(new QueryEntry(serializationService, toData(i), null, Extractors.empty()), null);
}
Set<QueryableEntry> query = indexes.query(new SqlPredicate("__key > 10 "));
assertNull("There should be no result", query);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class NestedPredicateTest method nestedAttributeQuery_distributedSql.
@Test
public void nestedAttributeQuery_distributedSql() throws Exception {
// GIVEN
map.put(1, new Body("body1", new Limb("hand")));
map.put(2, new Body("body2", new Limb("leg")));
// WHEN
Collection<Body> values = map.values(new SqlPredicate("limb.name == 'leg'"));
// THEN
assertEquals(1, values.size());
assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
Aggregations