def test_and(self): predicate = and_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertEqual( str(predicate), "AndPredicate(EqualPredicate(attribute='this', value=value-1)," " EqualPredicate(attribute='this', value=value-2))")
def test_and(self): predicate = and_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertEqual( str(predicate), "AndPredicate(EqualPredicate(attribute='this', value=value-1)," " EqualPredicate(attribute='this', value=value-2))", )
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()
if __name__ == '__main__': # Configure logging logging.basicConfig( format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,") logging.getLogger().setLevel(logging.INFO) # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 config = ClientConfig() portable_factory = {User.CLASS_ID: User} config.serialization_config.add_portable_factory(User.FACTORY_ID, portable_factory) hz = hazelcast.HazelcastClient(config) # Get a Distributed Map called "users" users = hz.get_map("users") # Add some users to the Distributed Map generate_users(users) # Create a Predicate from a String (a SQL like Where clause) sqlQuery = SqlPredicate("active AND age BETWEEN 18 AND 21)") # Creating the same Predicate as above but with a builder criteriaQuery = and_(is_equal_to("active", True), is_between("age", 18, 21)) # Get result collections using the two different Predicates result1 = users.values(sqlQuery).result() result2 = users.values(criteriaQuery).result() # Print out the results print(result1) print(result2) # Shutdown this Hazelcast Client hz.shutdown()
def test_and(self): self._fill_map() predicate = and_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertItemsEqual(self.map.key_set(predicate), [])