-
Notifications
You must be signed in to change notification settings - Fork 1.2k
make SignificantTermsBucket generic on key type #3795
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
make SignificantTermsBucket generic on key type #3795
Conversation
d114ce7
to
399747e
Compare
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.
Awesome awesome PR thanks for raising it @kevinphelps
Left a couple of nitpicks.
Backporting to 6.x
might be a tad harder as SignificantTermsAggregate
SignificantTermsBucket
are now generic, we could look into keeping both the non generic and generic versions of those in that branch though
Meta = bucket.Meta | ||
}; | ||
} | ||
|
||
public SignificantTermsAggregate SignificantText(string key) | ||
public SignificantTermsAggregate<TKey> SignificantText<TKey>(string key) |
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 think having a non generic overload defaulting to TKey
as string would be a nicer experience for the most common case.
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 can add that.
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 is done.
{ | ||
Key = (string)key, |
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.
key is known to be only string
or double
from where its called:
private IBucket GetKeyedBucket(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
perhaps we can use this to our advantage and instantiate either a SignificantTermBucket<string>
or SignificantTermBucket<double>
and then use this type information in
private IEnumerable<SignificantTermsBucket<TKey>> GetSignificantTermsBuckets<TKey>(IEnumerable<IBucket> items)
To return the items
(casted) directly instead.
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.
You could do the same thing in GetKeyedBucket
. Should that one be refactored as well?
Thanks! I'll try to make the requested changes tomorrow! :)
That sounds like it could work, but if not it's alright. I've already forked 6.x internally, so it's no big deal for me at least. |
399747e
to
fc59906
Compare
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 LGTM thanks for updating the PR @kevinphelps
Supersedes: #3795 Key of SignificantTermsBucket is generic to allow for returning both string and numeric key values. Co-authored-by: kevinphelps <KevinPhelps11@gmail.com>
@kevinphelps I'm going to close this PR in favour of #3890, as we're pulling it into 7.x and retargeting introduces a few merge conflicts to resolve. I've added you as co-author 👍 |
Supersedes: #3795 Key of SignificantTermsBucket is generic to allow for returning both string and numeric key values. Co-authored-by: kevinphelps <KevinPhelps11@gmail.com>
The problem is similar to #2336 except with
SignificantTermsBucket
instead ofKeyedBucket
. My use case is significant terms aggregation over numeric terms. ButSignificantTermsBucket.Key
is always null due to theKey = (string)key
line inAggregateFormatter
.This solution is modeled after the solution for
KeyedBucket
in 91f1f81.I have based this PR on
master
but if this could also be targeted for 6.x, I would be very appreciative. I can open a separate PR targeting the 6.x branch if necessary.Let me know if there are any changes needed. I would be happy to comply.