def test_querying_over_values_with_hazelcast_json_value(self):
        json_value = HazelcastJsonValue({"a": 1})
        json_value2 = HazelcastJsonValue({"a": 3})

        self.map.put(1, json_value)
        self.map.put(2, json_value2)

        results = self.map.values(is_greater_than("a", 2))

        self.assertEqual(1, len(results))
        self.assertEqual(json_value2.to_string(), results[0].to_string())
    def test_querying_over_keys_with_hazelcast_json_value(self):
        json_value = HazelcastJsonValue({"a": 1})
        json_value2 = HazelcastJsonValue({"a": 3})

        self.map.put(json_value, 1)
        self.map.put(json_value2, 2)

        results = self.map.key_set(is_greater_than("__key.a", 2))

        self.assertEqual(1, len(results))
        self.assertEqual(json_value2.to_string(), results[0].to_string())
Exemplo n.º 3
0
import hazelcast

from hazelcast.core import HazelcastJsonValue
from hazelcast.serialization.predicate import and_, is_greater_than, sql

client = hazelcast.HazelcastClient()
employees_map = client.get_map("employees").blocking()

alice = "{\"name\": \"Alice\", \"age\": 35}"
andy = "{\"name\": \"Andy\", \"age\": 22}"
bob = {"name": "Bob", "age": 37}

# HazelcastJsonValue can be constructed from JSON strings
employees_map.put(0, HazelcastJsonValue(alice))
employees_map.put(1, HazelcastJsonValue(andy))

# or from JSON serializable objects
employees_map.put(2, HazelcastJsonValue(bob))

# Employees whose name starts with 'A' and age is greater than 30
predicate = and_(sql("name like A%"), is_greater_than("age", 30))

values = employees_map.values(predicate)

for value in values:
    print(value.to_string())  # As JSON string
    print(value.loads())  # As Python object

client.shutdown()
Exemplo n.º 4
0
 def test_greater_than(self):
     self._fill_map_numeric()
     predicate = is_greater_than("this", 10)
     self.assertItemsEqual(self.map.key_set(predicate), range(11, 100))
Exemplo n.º 5
0
 def test_greater_than(self):
     self._fill_map_numeric()
     predicate = is_greater_than("this", 10)
     six.assertCountEqual(self, self.map.key_set(predicate),
                          list(range(11, 100)))
 def test_greater_than(self):
     self._fill_map_numeric()
     predicate = is_greater_than("this", 10)
     self.assertItemsEqual(self.map.key_set(predicate), range(11, 100))