This repository was archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Increase operator support #14
Open
soderluk
wants to merge
4
commits into
ioxiocom:main
Choose a base branch
from
soderluk:add_operator_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,89 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class Operators(str, Enum): | ||
| """ | ||
| Enum class for different operators. | ||
|
|
||
| See: | ||
| https://www.arangodb.com/docs/stable/aql/operators.html#comparison-operators | ||
| https://www.arangodb.com/docs/stable/aql/operators.html#array-comparison-operators | ||
| for more details. | ||
| """ | ||
|
|
||
| EQ = "==" | ||
| NE = "!=" | ||
| LT = "<" | ||
| LTE = "<=" | ||
| GT = ">" | ||
| GTE = ">=" | ||
| IN = "IN" | ||
| NOT_IN = "NOT IN" | ||
| LIKE = "LIKE" | ||
| NOT_LIKE = "NOT LIKE" | ||
| REG_MATCH = "=~" | ||
| NOT_REG_MATCH = "!~" | ||
| NOT = "NOT" | ||
| ALL_IN = "ALL IN" | ||
| NONE_IN = "NONE IN" | ||
| ANY_IN = "ANY IN" | ||
| # These array comparison operators requires an extra operator | ||
| # which will compare each individual array element. | ||
| ANY_EQ = "ANY ==" | ||
| ANY_NE = "ANY !=" | ||
| ANY_LT = "ANY <" | ||
| ANY_LTE = "ANY <=" | ||
| ANY_GT = "ANY >" | ||
| ANY_GTE = "ANY >=" | ||
| ALL_EQ = "==" | ||
| ALL_NE = "!=" | ||
| ALL_LT = "ALL <" | ||
| ALL_LTE = "ALL <=" | ||
| ALL_GT = "ALL >" | ||
| ALL_GTE = "ALL >=" | ||
| NONE_EQ = "NONE ==" | ||
| NONE_NE = "NONE !=" | ||
| NONE_LT = "NONE <" | ||
| NONE_LTE = "NONE <=" | ||
| NONE_GT = "NONE >" | ||
| NONE_GTE = "NONE >=" | ||
|
|
||
|
|
||
| # List of supported operators mapped to a-z string representations that can be | ||
| # used safely in the names of bind_vars in AQL | ||
| comparison_operators = { | ||
| Operators.EQ: "eq", | ||
| Operators.NE: "ne", | ||
| Operators.LT: "lt", | ||
| Operators.LTE: "lte", | ||
| Operators.GT: "gt", | ||
| Operators.GTE: "gte", | ||
| Operators.IN: "in", | ||
| Operators.NOT_IN: "not_in", | ||
| Operators.LIKE: "like", | ||
| Operators.NOT_LIKE: "not_like", | ||
| Operators.REG_MATCH: "reg_match", | ||
| Operators.NOT_REG_MATCH: "not_reg_match", | ||
| Operators.NOT: "not", | ||
| Operators.ALL_IN: "all_in", | ||
| Operators.NONE_IN: "none_in", | ||
| Operators.ANY_IN: "any_in", | ||
| Operators.ANY_EQ: "any_eq", | ||
| Operators.ANY_NE: "any_ne", | ||
| Operators.ANY_LT: "any_lt", | ||
| Operators.ANY_LTE: "any_lte", | ||
| Operators.ANY_GT: "any_gt", | ||
| Operators.ANY_GTE: "any_gte", | ||
| Operators.ALL_EQ: "all_eq", | ||
| Operators.ALL_NE: "all_ne", | ||
| Operators.ALL_LT: "all_lt", | ||
| Operators.ALL_LTE: "all_lte", | ||
| Operators.ALL_GT: "all_gt", | ||
| Operators.ALL_GTE: "all_gte", | ||
| Operators.NONE_EQ: "none_eq", | ||
| Operators.NONE_NE: "none_ne", | ||
| Operators.NONE_LT: "none_lt", | ||
| Operators.NONE_LTE: "none_lte", | ||
| Operators.NONE_GT: "none_gt", | ||
| Operators.NONE_GTE: "none_gte", | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| from typing import Any, List, Union | ||
|
|
||
| import pytest | ||
|
|
||
| from arangodantic.operators import Operators | ||
| from arangodantic.tests.conftest import Identity | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "data, operator, query, expected_length", | ||
| [ | ||
| (0, Operators.EQ, None, 0), | ||
| (1, Operators.GT, 0, 1), | ||
| (True, Operators.NE, None, 1), | ||
| (45, Operators.LTE, "yikes!", 1), | ||
| (65, Operators.NE, "65", 1), | ||
| (65, Operators.EQ, 65, 1), | ||
| (1.23, Operators.GT, 1.32, 0), | ||
| (1.5, Operators.IN, [2, 3, 1.5], 1), | ||
| ("foo", Operators.IN, None, 0), | ||
| (42, Operators.NOT_IN, [17, 40, 50], 1), | ||
| ("abc", Operators.EQ, "abc", 1), | ||
| ("abc", Operators.EQ, "ABC", 0), | ||
| ("foo", Operators.LIKE, "f%", 1), | ||
| ("foo", Operators.NOT_LIKE, "f%", 0), | ||
| ("foo", Operators.REG_MATCH, "^f[o].$", 1), | ||
| ("foo", Operators.NOT_REG_MATCH, "[a-z]+bar$", 1), | ||
| ], | ||
| ) | ||
| @pytest.mark.asyncio | ||
| async def test_comparison_operators( | ||
| identity_collection, | ||
| data: Any, | ||
| operator: Operators, | ||
| query: Any, | ||
| expected_length: int, | ||
| ): | ||
| # See https://www.arangodb.com/docs/stable/aql/operators.html#comparison-operators | ||
| # for the test cases. | ||
| i_a = Identity(name="a", data={"value": data}) | ||
| await i_a.save() | ||
|
|
||
| cursor = await Identity.find({"data.value": {operator: query}}, count=True) | ||
| async with cursor: | ||
| assert len(cursor) == expected_length | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "data, operator, query, expected_length", | ||
| [ | ||
| ([1, 2, 3], Operators.ALL_IN, [2, 3, 4], 0), | ||
| ([1, 2, 3], Operators.ALL_IN, [1, 2, 3], 1), | ||
| ([1, 2, 3], Operators.NONE_IN, [3], 0), | ||
| ([1, 2, 3], Operators.NONE_IN, [23, 42], 1), | ||
| ([1, 2, 3], Operators.ANY_IN, [4, 5, 6], 0), | ||
| ([1, 2, 3], Operators.ANY_IN, [1, 42], 1), | ||
| ([1, 2, 3], Operators.ANY_EQ, 2, 1), | ||
| ([1, 2, 3], Operators.ANY_EQ, 4, 0), | ||
| ([1, 2, 3], Operators.ANY_GT, 0, 1), | ||
| ([1, 2, 3], Operators.ANY_LTE, 1, 1), | ||
| ([1, 2, 3], Operators.ANY_LTE, 1, 1), | ||
| ([1, 2, 3], Operators.NONE_LT, 99, 0), | ||
| ([1, 2, 3], Operators.NONE_GT, 10, 1), | ||
| ([1, 2, 3], Operators.ALL_GT, 2, 0), | ||
| ([1, 2, 3], Operators.ALL_GT, 0, 1), | ||
| ([1, 2, 3], Operators.ALL_GTE, 3, 0), | ||
| (["foo", "bar"], Operators.ALL_NE, "moo", 1), | ||
| (["foo", "bar"], Operators.NONE_EQ, "bar", 0), | ||
| (["foo", "bar"], Operators.ANY_EQ, "foo", 1), | ||
| ], | ||
| ) | ||
| @pytest.mark.asyncio | ||
| async def test_array_comparison_operators( | ||
| identity_collection, | ||
| data: List[Union[int, str]], | ||
| operator: Operators, | ||
| query: Union[List[int], int], | ||
| expected_length: int, | ||
| ): | ||
| # See | ||
| # https://www.arangodb.com/docs/stable/aql/operators.html#array-comparison-operators | ||
| # for the test cases. | ||
| i_a = Identity(name="a", data={"list": data}) | ||
|
|
||
| await i_a.save() | ||
|
|
||
| cursor = await Identity.find({"data.list": {operator: query}}, count=True) | ||
| async with cursor: | ||
| assert len(cursor) == expected_length |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much poker? 😄