use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testJsonPredicateOnKey.
@Test
public void testJsonPredicateOnKey() {
JsonValue array1 = Json.array();
array1.asArray().add(createNameAgeOnDuty("a", 50, false)).add(createNameAgeOnDuty("b", 30, true)).add(createNameAgeOnDuty("c", 32, true)).add(createNameAgeOnDuty("d", 17, false));
JsonValue array2 = Json.array();
array2.asArray().add(createNameAgeOnDuty("e", 10, false)).add(createNameAgeOnDuty("f", 20, true)).add(createNameAgeOnDuty("g", 30, true)).add(createNameAgeOnDuty("h", 40, false));
JsonValue array3 = Json.array();
array3.asArray().add(createNameAgeOnDuty("i", 26, false)).add(createNameAgeOnDuty("j", 24, true)).add(createNameAgeOnDuty("k", 1, true)).add(createNameAgeOnDuty("l", 90, false));
JsonObject obj1 = Json.object();
obj1.add("arr", array1);
JsonObject obj2 = Json.object();
obj2.add("arr", array2);
JsonObject obj3 = Json.object();
obj3.add("arr", array3);
HazelcastJsonValue p1 = new HazelcastJsonValue(obj1.toString());
HazelcastJsonValue p2 = new HazelcastJsonValue(obj2.toString());
HazelcastJsonValue p3 = new HazelcastJsonValue(obj3.toString());
IMap<HazelcastJsonValue, String> map = instance.getMap(randomMapName());
map.put(p1, "one");
map.put(p2, "two");
map.put(p3, "three");
Collection<String> vals = map.values(Predicates.greaterEqual("__key.arr[2].age", 20));
assertEquals(2, vals.size());
assertTrue(vals.contains("one"));
assertTrue(vals.contains("two"));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testQueryOnBooleanProperty.
@Test
public void testQueryOnBooleanProperty() {
IMap<String, JsonValue> map = instance.getMap(randomMapName());
HazelcastJsonValue p1 = putJsonString(map, "a", 30, true);
HazelcastJsonValue p2 = putJsonString(map, "b", 20, false);
HazelcastJsonValue p3 = putJsonString(map, "c", 10, true);
Collection<JsonValue> vals = map.values(Predicates.equal("onDuty", true));
assertEquals(2, vals.size());
assertTrue(vals.contains(p1));
assertTrue(vals.contains(p3));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testSkipsNestedArraysInAnyQuery.
@Test
public void testSkipsNestedArraysInAnyQuery() {
JsonObject value1 = Json.object();
JsonObject value2 = Json.object();
JsonObject value3 = Json.object();
JsonArray innerArray1 = Json.array(new int[] { 1001, 1002 });
JsonArray array1 = Json.array();
array1.add(1).add(2).add(innerArray1).add(3).add(4).add(20);
JsonArray array2 = Json.array(new int[] { 10, 20, 30 });
JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400 });
value1.add("numbers", array1);
value2.add("numbers", array2);
value3.add("numbers", array3);
IMap<String, JsonValue> map = instance.getMap(randomMapName());
putJsonString(map, "one", value1);
HazelcastJsonValue p2 = putJsonString(map, "two", value2);
HazelcastJsonValue p3 = putJsonString(map, "three", value3);
Collection<JsonValue> vals = map.values(Predicates.greaterThan("numbers[any]", 20));
assertEquals(2, vals.size());
assertTrue(vals.contains(p2));
assertTrue(vals.contains(p3));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testNestedQueryInArray_whenAnyMatchesMultipleNestedObjects_shouldReturnAllMatching.
@Test
public void testNestedQueryInArray_whenAnyMatchesMultipleNestedObjects_shouldReturnAllMatching() {
JsonValue array1 = Json.array();
array1.asArray().add(createNameAgeOnDuty("a", 50, false)).add(createNameAgeOnDuty("b", 30, true)).add(createNameAgeOnDuty("c", 32, true)).add(createNameAgeOnDuty("d", 17, false));
JsonValue array2 = Json.array();
array2.asArray().add(createNameAgeOnDuty("e", 10, false)).add(createNameAgeOnDuty("f", 20, true)).add(createNameAgeOnDuty("g", 30, true)).add(createNameAgeOnDuty("h", 40, false));
JsonValue array3 = Json.array();
array3.asArray().add(createNameAgeOnDuty("i", 26, false)).add(createNameAgeOnDuty("j", 24, true)).add(createNameAgeOnDuty("k", 1, true)).add(createNameAgeOnDuty("l", 90, false));
JsonObject obj1 = Json.object();
obj1.add("arr", array1);
JsonObject obj2 = Json.object();
obj2.add("arr", array2);
JsonObject obj3 = Json.object();
obj3.add("arr", array3);
IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
HazelcastJsonValue p1 = putJsonString(map, "one", obj1);
HazelcastJsonValue p2 = putJsonString(map, "two", obj2);
HazelcastJsonValue p3 = putJsonString(map, "three", obj3);
Collection<HazelcastJsonValue> vals = map.values(Predicates.greaterThan("arr[any].age", 40));
assertEquals(2, vals.size());
assertTrue(vals.contains(p1));
assertTrue(vals.contains(p3));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testQueryOnArrayIndexOnKey.
@Test
public void testQueryOnArrayIndexOnKey() {
JsonObject value1 = Json.object();
JsonObject value2 = Json.object();
JsonObject value3 = Json.object();
JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5 });
JsonArray array2 = Json.array(new int[] { 10, 20, 30, 40, 50 });
JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400, 500 });
value1.add("numbers", array1);
value2.add("numbers", array2);
value3.add("numbers", array3);
IMap<JsonValue, String> map = instance.getMap(randomMapName());
String p1 = putWithJsonStringKey(map, value1, "one");
String p2 = putWithJsonStringKey(map, value2, "two");
String p3 = putWithJsonStringKey(map, value3, "three");
Collection<String> vals = map.values(Predicates.greaterEqual("__key.numbers[1]", 20));
assertEquals(2, vals.size());
assertTrue(vals.contains(p2));
assertTrue(vals.contains(p3));
}
Aggregations