ml-commons
ml-commons copied to clipboard
Use stream optional enum set from core in MLStatsInput
Description
Refactors MLStatsInput to use StreamInput::readOptionalEnumSet and StreamOutput::writeOptionalEnumSet from OpenSearch core, added in this recent PR: https://github.com/opensearch-project/OpenSearch/pull/17556
The currently this is implemented in ml-commons using a private helper. I added this functionality to core using ml-commons as a reference so it could be reused in neural search, so the implementation is identical. While I made this change so other plugins could use the same function, I figure it might make sense to use it in ml-commons as well.
Compare ml-commons implmentation
private void writeEnumSet(StreamOutput out, EnumSet<?> set) throws IOException {
if (set != null && set.size() > 0) {
out.writeBoolean(true);
out.writeEnumSet(set);
} else {
out.writeBoolean(false);
}
}
public <E extends Enum<E>> void writeOptionalEnumSet(@Nullable EnumSet<E> enumSet) throws IOException {
if (enumSet != null && enumSet.size() > 0) {
writeBoolean(true);
writeEnumSet(enumSet);
} else {
writeBoolean(false);
}
}
Related Issues
n/a
Check List
- [ ] New functionality includes testing.
- [ ] New functionality has been documented.
- [ ] API changes companion pull request created.
- [x] Commits are signed per the DCO using
--signoff. - [ ] Public documentation issue/PR created.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.