def test_and(self): predicate = and_(equal("this", "value-1"), equal("this", "value-2")) self.assertEqual( str(predicate), "AndPredicate(EqualPredicate(attribute='this', value=value-1)," " EqualPredicate(attribute='this', value=value-2))", )
def test_and(self): self.fill_map() predicate = and_(equal("this", "value-1"), equal("this", "value-2")) self.assertCountEqual(self.map.key_set(predicate), [])
"BetweenPredicate": predicate.between(_sql_string, REFERENCE_OBJECTS["Integer"], REFERENCE_OBJECTS["Integer"]), "LikePredicate": predicate.like(_sql_string, _sql_string), "ILikePredicate": predicate.ilike(_sql_string, _sql_string), "InPredicate": predicate.in_(_sql_string, REFERENCE_OBJECTS["Integer"], REFERENCE_OBJECTS["Integer"]), "RegexPredicate": predicate.regex(_sql_string, _sql_string), "AndPredicate": predicate.and_( predicate.sql(_sql_string), predicate.equal(_sql_string, REFERENCE_OBJECTS["Integer"]), predicate.not_equal(_sql_string, REFERENCE_OBJECTS["Integer"]), predicate.greater(_sql_string, REFERENCE_OBJECTS["Integer"]), predicate.greater_or_equal(_sql_string, REFERENCE_OBJECTS["Integer"])), "OrPredicate": predicate.or_( predicate.sql(_sql_string), predicate.equal(_sql_string, REFERENCE_OBJECTS["Integer"]), predicate.not_equal(_sql_string, REFERENCE_OBJECTS["Integer"]), predicate.greater(_sql_string, REFERENCE_OBJECTS["Integer"]), predicate.greater_or_equal(_sql_string, REFERENCE_OBJECTS["Integer"])), "InstanceOfPredicate": predicate.instance_of( "com.hazelcast.nio.serialization.compatibility.CustomStreamSerializable" ) })
self.age, self.active) def generate_users(users): users.put("Rod", User("Rod", 19, True)) users.put("Jane", User("Jane", 20, True)) users.put("Freddy", User("Freddy", 23, True)) # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 hz = hazelcast.HazelcastClient( portable_factories={User.FACTORY_ID: { User.CLASS_ID: User }}) # Get a Distributed Map called "users" users_map = hz.get_map("users").blocking() # Add some users to the Distributed Map generate_users(users_map) # Create a Predicate from a String (a SQL like Where clause) sql_query = sql("active AND age BETWEEN 18 AND 21)") # Creating the same Predicate as above but with a builder criteria_query = and_(equal("active", True), between("age", 18, 21)) # Get result collections using the two different Predicates result1 = users_map.values(sql_query) result2 = users_map.values(criteria_query) # Print out the results print(result1) print(result2) # Shutdown this Hazelcast Client hz.shutdown()
import hazelcast from hazelcast.core import HazelcastJsonValue from hazelcast.predicate import and_, greater, 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%"), greater("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()