def test_equal_values_paging(self):
        self.fill_map()
        # keys[50 - 99], values[0 - 49]:
        m = {"key-%d" % i: i - 50 for i in range(50, 100)}
        self.map.put_all(m)

        predicate = paging(less_or_equal("this", 8), 5)

        self.assertEqual(self.map.values(predicate), [0, 0, 1, 1, 2])
        predicate.next_page()
        self.assertEqual(self.map.values(predicate), [2, 3, 3, 4, 4])
        predicate.next_page()
        self.assertEqual(self.map.values(predicate), [5, 5, 6, 6, 7])
        predicate.next_page()
        self.assertEqual(self.map.values(predicate), [7, 8, 8])
 def test_less_than_or_equal(self):
     self.fill_map_numeric()
     predicate = less_or_equal("this", 10)
     self.assertCountEqual(self.map.key_set(predicate), list(range(0, 11)))
Exemplo n.º 3
0
 def test_max_by_with_predicate(self):
     max_item = self.map.aggregate(max_by("this"),
                                   less_or_equal("this", 10))
     self.assertEqual("key-10", max_item.key)
     self.assertEqual(10, max_item.value)
Exemplo n.º 4
0
 def test_max_with_predicate(self):
     average = self.map.aggregate(max_(), less_or_equal("this", 3))
     self.assertEqual(3, average)
Exemplo n.º 5
0
import hazelcast

from hazelcast.aggregator import count, number_avg, max_by
from hazelcast.predicate import less_or_equal

client = hazelcast.HazelcastClient()

people = client.get_map("people").blocking()

people.put_all({
    "Philip": 46,
    "Elizabeth": 44,
    "Henry": 13,
    "Paige": 15,
})

people_count = people.aggregate(count())
print("There are %d people." % people_count)

children_count = people.aggregate(count(), less_or_equal("this", 18))
print("There are %d children." % children_count)

average_age = people.aggregate(number_avg())
print("Average age is %f." % average_age)

eldest_person = people.aggregate(max_by("this"))
print("Eldest person is %s, with the age of %d." %
      (eldest_person.key, eldest_person.value))

client.shutdown()
 def test_greater_less(self):
     predicate = less_or_equal("this", 10)
     self.assertEqual(
         str(predicate),
         "GreaterLessPredicate(attribute='this', value=10, is_equal=True, is_less=True)",
     )
Exemplo n.º 7
0
people.put_all({
    1: HazelcastJsonValue({
        "name": "Philip",
        "age": 46
    }),
    2: HazelcastJsonValue({
        "name": "Elizabeth",
        "age": 44
    }),
    3: HazelcastJsonValue({
        "name": "Henry",
        "age": 13
    }),
    4: HazelcastJsonValue({
        "name": "Paige",
        "age": 15
    }),
})

names = people.project(single_attribute("name"))
print("Names of the people are %s." % names)

children_names = people.project(single_attribute("name"),
                                less_or_equal("age", 18))
print("Names of the children are %s." % children_names)

names_and_ages = people.project(multi_attribute("name", "age"))
print("Names and ages of the people are %s." % names_and_ages)

client.shutdown()