def test_or(self): predicate = or_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertEqual( str(predicate), "OrPredicate(EqualPredicate(attribute='this', value=value-1)," " EqualPredicate(attribute='this', value=value-2))")
def test_or(self): predicate = or_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertEqual( str(predicate), "OrPredicate(EqualPredicate(attribute='this', value=value-1)," " EqualPredicate(attribute='this', value=value-2))", )
def test_querying_nested_attr_over_keys_with_hazelcast_json_value(self): json_value = HazelcastJsonValue({"a": 1, "b": {"c": "d"}}) json_value2 = HazelcastJsonValue({"a": 2, "b": {"c": "e"}}) self.map.put(json_value, 1) self.map.put(json_value2, 2) results = self.map.key_set(is_equal_to("__key.b.c", "d")) self.assertEqual(1, len(results)) self.assertEqual(json_value.to_string(), results[0].to_string())
def test_not(self): predicate = not_(is_equal_to("this", "value-1")) self.assertEqual(str(predicate), "NotPredicate(predicate=EqualPredicate(attribute='this', value=value-1))")
def test_not(self): predicate = not_(is_equal_to("this", "value-1")) self.assertEqual( str(predicate), "NotPredicate(predicate=EqualPredicate(attribute='this', value=value-1))" )
def test_equal_str(self): predicate = is_equal_to("this", "value-1") self.assertEqual(str(predicate), "EqualPredicate(attribute='this', value=value-1)")
def test_equal(self): self._fill_map() predicate = is_equal_to("this", "value-1") self.assertItemsEqual(self.map.key_set(predicate), ["key-1"])
def test_not(self): self._fill_map(count=3) predicate = not_(is_equal_to("this", "value-1")) self.assertItemsEqual(self.map.key_set(predicate), ["key-0", "key-2"])
def test_or(self): self._fill_map() predicate = or_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertItemsEqual(self.map.key_set(predicate), ["key-1", "key-2"])
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), [])
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()
def test_equal_str(self): predicate = is_equal_to("this", "value-1") self.assertEqual(str(predicate), "EqualPredicate(attribute='this', value=value-1)")
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_equal(self): self._fill_map() predicate = is_equal_to("this", "value-1") self.assertItemsEqual(self.map.key_set(predicate), ["key-1"])
def test_not(self): self._fill_map(count=3) predicate = not_(is_equal_to("this", "value-1")) self.assertItemsEqual(self.map.key_set(predicate), ["key-0", "key-2"])
def test_or(self): self._fill_map() predicate = or_(is_equal_to("this", "value-1"), is_equal_to("this", "value-2")) self.assertItemsEqual(self.map.key_set(predicate), ["key-1", "key-2"])
def test_single_attribute_query_portable_predicates(self): predicate = is_equal_to("limb.name", "hand") values = self.map.values(predicate) self.assertEqual(1, len(values)) self.assertEqual("body1", values[0].name)
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), [])