-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-generate aggregation classes #1918
Auto-generate aggregation classes #1918
Conversation
2f33a36
to
588f58e
Compare
0d6d89d
to
4212e69
Compare
4212e69
to
2378640
Compare
@@ -220,7 +220,13 @@ def test_filters_correctly_identifies_the_hash() -> None: | |||
|
|||
|
|||
def test_bucket_sort_agg() -> None: | |||
bucket_sort_agg = aggs.BucketSort(sort=[{"total_sales": {"order": "desc"}}], size=3) | |||
bucket_sort_agg = aggs.BucketSort(sort=[{"total_sales": {"order": "desc"}}], size=3) # type: ignore |
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.
For several examples in this file I kept the original dict based solution with ignored typing errors, and right below I've added a correctly typed version, so that we make sure we are backwards compatible.
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.
This deserves to be an in-file comment IMO, because it's tempting to remove in a refactoring.
elasticsearch_dsl/aggs.py
Outdated
return FieldBucketData(self, search, data) | ||
|
||
|
||
class RandomSampler(Bucket[_R]): |
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.
I'm manually adding the missing RandomSampler
for now. I think once it is added to the schema this is going to cause a failure in the type checking, so I'll know I can remove it then.
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.
RandomSampler
is in the specification now. I've just backported to 8.15 in case it helps here.
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.
Thanks! LGTM.
@@ -220,7 +220,13 @@ def test_filters_correctly_identifies_the_hash() -> None: | |||
|
|||
|
|||
def test_bucket_sort_agg() -> None: | |||
bucket_sort_agg = aggs.BucketSort(sort=[{"total_sales": {"order": "desc"}}], size=3) | |||
bucket_sort_agg = aggs.BucketSort(sort=[{"total_sales": {"order": "desc"}}], size=3) # type: ignore |
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.
This deserves to be an in-file comment IMO, because it's tempting to remove in a refactoring.
query: Union[str, float, bool, DefaultType] = DEFAULT, | ||
analyzer: Union[str, DefaultType] = DEFAULT, | ||
auto_generate_synonyms_phrase_query: Union[bool, DefaultType] = DEFAULT, | ||
cutoff_frequency: Union[float, DefaultType] = DEFAULT, | ||
fuzziness: Union[str, int, DefaultType] = DEFAULT, | ||
fuzzy_rewrite: Union[str, DefaultType] = DEFAULT, | ||
fuzzy_transpositions: Union[bool, DefaultType] = DEFAULT, | ||
lenient: Union[bool, DefaultType] = DEFAULT, | ||
max_expansions: Union[int, DefaultType] = DEFAULT, | ||
minimum_should_match: Union[int, str, DefaultType] = DEFAULT, | ||
operator: Union[Literal["and", "or"], DefaultType] = DEFAULT, | ||
prefix_length: Union[int, DefaultType] = DEFAULT, | ||
zero_terms_query: Union[Literal["all", "none"], DefaultType] = DEFAULT, | ||
boost: Union[float, DefaultType] = DEFAULT, | ||
_name: Union[str, DefaultType] = DEFAULT, | ||
query: Union[str, float, bool, DefaultType] = DEFAULT, | ||
analyzer: Union[str, DefaultType] = DEFAULT, | ||
auto_generate_synonyms_phrase_query: Union[bool, DefaultType] = DEFAULT, | ||
cutoff_frequency: Union[float, DefaultType] = DEFAULT, | ||
fuzziness: Union[str, int, DefaultType] = DEFAULT, | ||
fuzzy_rewrite: Union[str, DefaultType] = DEFAULT, | ||
fuzzy_transpositions: Union[bool, DefaultType] = DEFAULT, | ||
lenient: Union[bool, DefaultType] = DEFAULT, | ||
max_expansions: Union[int, DefaultType] = DEFAULT, | ||
minimum_should_match: Union[int, str, DefaultType] = DEFAULT, | ||
operator: Union[Literal["and", "or"], DefaultType] = DEFAULT, | ||
prefix_length: Union[int, DefaultType] = DEFAULT, | ||
zero_terms_query: Union[Literal["all", "none"], DefaultType] = DEFAULT, | ||
boost: Union[float, DefaultType] = DEFAULT, | ||
_name: Union[str, DefaultType] = DEFAULT, |
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.
Go home GitHub, you're drunk?
elasticsearch_dsl/aggs.py
Outdated
""" | ||
A single bucket aggregation that narrows the set of documents to those | ||
that match a query. | ||
|
||
:arg filter: A single bucket aggregation that narrows the set of | ||
documents to those that match a query. | ||
""" |
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.
I love how we're keeping essentially the same code but adding documentation!
elasticsearch_dsl/aggs.py
Outdated
return FieldBucketData(self, search, data) | ||
|
||
|
||
class RandomSampler(Bucket[_R]): |
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.
RandomSampler
is in the specification now. I've just backported to 8.15 in case it helps here.
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-8.x 8.x
# Navigate to the new working tree
cd .worktrees/backport-8.x
# Create a new branch
git switch --create backport-1918-to-8.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 ec8da5577f5c127a0c8fba9b0bfcfabb3e5eb171
# Push it to GitHub
git push --set-upstream origin backport-1918-to-8.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-8.x Then, create a pull request where the |
* auto-generate aggregation classes * feedback (cherry picked from commit ec8da55)
* auto-generate aggregation classes * feedback
This change adds docstrings and types to all aggregation classes.