Fix NPE when values is omitted on percentile_ranks agg#26046
Fix NPE when values is omitted on percentile_ranks agg#26046polyfractal merged 6 commits intoelastic:masterfrom
values is omitted on percentile_ranks agg#26046Conversation
|
I'm ok with this change, but I think that a better fix might be to make |
cbuescher
left a comment
There was a problem hiding this comment.
@polyfractal I think checking values is a good change, however I'd also like to try removing the setter and try to validate the values as part of the constructor if it is mandatory. I think using ConstructingObjectParser should work in this case. I haven't tried but I can give it a go if you are stuck somewhere.
|
Ah right, I didn't think about ConstructingObjectParser. ++ will make the changes! |
e6784d4 to
b33e6f1
Compare
|
Alright, so @cbuescher, @nik9000 and I chatted about this earlier today. The way aggregations are built makes it tricky to use ConstructingObjectParser. To construct the object, we need both an externally provided value ( We kicked around a few ideas:
We agreed to see if the context approach would work, and if not, fall back to option 3 (merge as-is and follow up with another PR). The most recent commit adjusts to use ConstructingObjectParser. The change was a bit more invasive than I wanted; the helpers that add common numeric fields ( The rest of the changes are just fixing up the tests. Sooo... thoughts? Keep this, or revert to the simple exception and trying to enhance ConstructingObjectParser? |
cbuescher
left a comment
There was a problem hiding this comment.
Hi @polyfractal, thats a great change. I left a couple of comments how to maybe simplify things a little more and some nits but I think this is almost good to go.
There was a problem hiding this comment.
+1, I think I did this in some WIP branch as well the other day. Didn't get back to it though.
There was a problem hiding this comment.
Since this is implemented also in ObjectParser, I would make this an abstract method in AbstractObjectParser. I think this way ValuesSourceParserHelper.declareFields() could work AbstractObjectParser without all the current duclication. Not 100% sure though but I'd give it a try.
There was a problem hiding this comment.
I think this whole block can go if all the existing declare* methods in this class take AbstractObjectParser instead of ObjectParser as an argument. That works when getName() (see above) is mave abstract in AbstractObjectParser.
There was a problem hiding this comment.
nit: space between after (List)
There was a problem hiding this comment.
nit: maybe static import for ConstructingObjectParser.constructorArg, that makes it more readable IMHO.
There was a problem hiding this comment.
Okay, I see now how you are piggybacking the name in the Context slot. maybe worth a comment here to remember the "why" in a few weeks from now.
There was a problem hiding this comment.
nit: spaces between the values
There was a problem hiding this comment.
Should this include a check for an empy array? Not sure, just a though. In case the answer is yes, maybe also add a test for that.
|
Review comments addressed, definitely cleaner with the change to AbstractObjectParser :) Also added a few more tests to the |
There was a problem hiding this comment.
Thanks. I don't think its hacky ;-) Its okay as long as we have the context argument, when we try to remove it one day it might be useful to know why we use it here.
There was a problem hiding this comment.
Ah, I forgot one thing, since this changes the aggregation constructor and the AggregationBuilders helper signature without keeping the old version, I think this should be marked as breaking. I don't know which versions this was supposed to go to but in any case I think some migration docs would be needed.
An array of values is required because there is no default (or reasonable way to set a default). But validation for values only happens if it is actually set. If the values param is omitted entirely than the agg builder will NPE.
- Moves the parser to ConstructingObjectParser - Uses the context to pass in the aggregation name - Adds getName() to ConstructingObjectParser - Adds more helpers to ValuesSourceParserHelper to support Constructing variety
f600ea5 to
d5b5eb8
Compare
An array of values is required because there is no default (or reasonable way to set a default). But validation for values only happens if it is actually set. If the values param is omitted entirely than the agg builder will NPE.
An array of values is required because there is no default (or reasonable way to set a default). But validation for values only happens if it is actually set. If the values param is omitted entirely than the agg builder will NPE.
* master: (458 commits) Prevent cluster internal `ClusterState.Custom` impls to leak to a client (elastic#26232) Add packaging test for systemd runtime directive [TEST] Reenable RareClusterStateIt#testDeleteCreateInOneBulk Serialize and expose timeout of acknowledged requests in REST layer (elastic#26189) (refactor) some opportunities to use diamond operator (elastic#25585) [DOCS] Clarified readme for testing a single page Settings: Add keystore.seed auto generated secure setting (elastic#26149) Update version information (elastic#25226) "result" : created -> "result" : "created" (elastic#25446) Set RuntimeDirectory (elastic#23526) Drop upgrade from full cluster restart tests (elastic#26224) Further improve docs for requests_per_second Docs disambiguate reindex's requests_per_second (elastic#26185) [DOCS] Cleanup link for ec2 discovery (elastic#26222) Fix document field equals and hash code test Use holder pattern for lazy deprecation loggers Settings: Add keystore creation to add commands (elastic#26126) Docs: Cleanup docs for ec2 discovery (elastic#26065) Fix NPE when `values` is omitted on percentile_ranks agg (elastic#26046) Several internal improvements to internal test cluster infra (elastic#26214) ...
An array of values is required because there is no default (or reasonable way to set a default). But validation for
valuesonly happens if it is actually set on the builder. If thevaluesparam is omitted entirely thenvaluesis passed in as null, and later NPEs when attempting to iterate over the ranks.I wasn't sure the best place to do this validation, since regular aggs don't have a
validate()or equivalent. And I couldn't find a way to make params required in the ObjectParser. So checking right before the factory is built seemed like the best/only place?@cbuescher would you mind reviewing this?