import hazelcast from hazelcast.serialization.predicate import is_between client = hazelcast.HazelcastClient() predicate_map = client.get_map("predicate-map") for i in range(10): predicate_map.put("key" + str(i), i) predicate = is_between("this", 3, 5) entry_set = predicate_map.entry_set(predicate).result() for key, value in entry_set: print("{} -> {}".format(key, value)) client.shutdown()
def test_between(self): predicate = is_between("this", 1, 20) self.assertEqual(str(predicate), "BetweenPredicate(attribute='this', from=1, to=20)")
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_between(self): self._fill_map_numeric() predicate = is_between("this", 1, 20) self.assertItemsEqual(self.map.key_set(predicate), range(1, 21))
def test_between(self): self._fill_map_numeric() predicate = is_between("this", 1, 20) six.assertCountEqual(self, self.map.key_set(predicate), list(range(1, 21)))
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)) config = ClientConfig() portable_factory = {User.CLASS_ID: User} config.serialization.add_portable_factory(User.FACTORY_ID, portable_factory) # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 hz = hazelcast.HazelcastClient(config) # Get a Distributed Map called "users" users = hz.get_map("users").blocking() # Add some users to the Distributed Map generate_users(users) # 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_(is_equal_to("active", True), is_between("age", 18, 21)) # Get result collections using the two different Predicates result1 = users.values(sql_query) result2 = users.values(criteria_query) # Print out the results print(result1) print(result2) # Shutdown this Hazelcast Client hz.shutdown()