-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Projections follow up This is a follow up PR after merging the Projections PR. This is a combination of lots of small things. - Add documentation to properties of `MapEntry` so that they are displayed - Move map#project so that we maintain alphabetical order - Add some corner case tests for projections and aggregations - Used asserCountEqual on projection tests so that the tests will be more durable, even if we add more items to map - Add missing API documentation for projections - Fix API documentation of projections around the return value documentations - Add unit tests for the invalid projection inputs - Make the projections code snippet simpler - Add a code sample for projections * add type hints to projections * add projections to feature list
- Loading branch information
Showing
10 changed files
with
158 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ API Documentation | |
lifecycle | ||
partition | ||
predicate | ||
projection | ||
proxy/modules | ||
security | ||
serialization | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Projection | ||
========== | ||
|
||
.. automodule:: hazelcast.projection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import hazelcast | ||
|
||
from hazelcast.core import HazelcastJsonValue | ||
from hazelcast.predicate import less_or_equal | ||
from hazelcast.projection import single_attribute, multi_attribute | ||
|
||
client = hazelcast.HazelcastClient() | ||
|
||
people = client.get_map("people").blocking() | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
|
||
from hazelcast.projection import single_attribute, multi_attribute | ||
|
||
|
||
class ProjectionsInvalidInputTest(unittest.TestCase): | ||
def test_single_attribute_with_any_operator(self): | ||
with self.assertRaises(ValueError): | ||
single_attribute("foo[any]") | ||
|
||
def test_single_attribute_with_empty_path(self): | ||
with self.assertRaises(ValueError): | ||
single_attribute("") | ||
|
||
def test_multi_attribute_with_no_paths(self): | ||
with self.assertRaises(ValueError): | ||
multi_attribute() | ||
|
||
def test_multi_attribute_with_any_operator(self): | ||
with self.assertRaises(ValueError): | ||
multi_attribute("valid", "invalid[any]") | ||
|
||
def test_multi_attribute_with_empty_path(self): | ||
with self.assertRaises(ValueError): | ||
multi_attribute("valid", "") |