Ejemplo n.º 1
0
 def test_or(self):
     predicate = or_(equal("this", "value-1"), equal("this", "value-2"))
     self.assertEqual(
         str(predicate),
         "OrPredicate(EqualPredicate(attribute='this', value=value-1),"
         " EqualPredicate(attribute='this', value=value-2))",
     )
Ejemplo n.º 2
0
    def test_querying_nested_attr_over_values_with_hazelcast_json_value(self):
        json_value = HazelcastJsonValue({"a": 1, "b": {"c": "d"}})
        json_value2 = HazelcastJsonValue({"a": 2, "b": {"c": "e"}})

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

        results = self.map.values(equal("b.c", "d"))

        self.assertEqual(1, len(results))
        self.assertEqual(json_value.to_string(), results[0].to_string())
Ejemplo n.º 3
0
 def test_equal(self):
     self.fill_map()
     predicate = equal("this", "value-1")
     self.assertCountEqual(self.map.key_set(predicate), ["key-1"])
Ejemplo n.º 4
0
 def test_not(self):
     self.fill_map(count=3)
     predicate = not_(equal("this", "value-1"))
     self.assertCountEqual(self.map.key_set(predicate), ["key-0", "key-2"])
Ejemplo n.º 5
0
 def test_or(self):
     self.fill_map()
     predicate = or_(equal("this", "value-1"), equal("this", "value-2"))
     self.assertCountEqual(self.map.key_set(predicate), ["key-1", "key-2"])
Ejemplo n.º 6
0
 def test_and(self):
     self.fill_map()
     predicate = and_(equal("this", "value-1"), equal("this", "value-2"))
     self.assertCountEqual(self.map.key_set(predicate), [])
Ejemplo n.º 7
0
    def test_single_attribute_query_portable_predicates(self):
        predicate = equal("limb.name", "hand")
        values = self.map.values(predicate)

        self.assertEqual(1, len(values))
        self.assertEqual("body1", values[0].name)
 "CustomByteArraySerializable":
 _custom_byte_array_serializable,
 "AnIdentifiedDataSerializable":
 _identified,
 "APortable":
 _portable,
 "ArrayList": [None, _non_null_list],
 "LinkedList": [None, _non_null_list],
 "TruePredicate":
 predicate.true(),
 "FalsePredicate":
 predicate.false(),
 "SqlPredicate":
 predicate.sql(_sql_string),
 "EqualPredicate":
 predicate.equal(_sql_string, REFERENCE_OBJECTS["Integer"]),
 "NotEqualPredicate":
 predicate.not_equal(_sql_string, REFERENCE_OBJECTS["Integer"]),
 "GreaterLessPredicate":
 predicate.greater(_sql_string, REFERENCE_OBJECTS["Integer"]),
 "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":
Ejemplo n.º 9
0
                                                         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()
Ejemplo n.º 10
0
 def test_not(self):
     predicate = not_(equal("this", "value-1"))
     self.assertEqual(
         str(predicate),
         "NotPredicate(predicate=EqualPredicate(attribute='this', value=value-1))",
     )
Ejemplo n.º 11
0
 def test_equal_str(self):
     predicate = equal("this", "value-1")
     self.assertEqual(str(predicate),
                      "EqualPredicate(attribute='this', value=value-1)")
 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))")