Normalize malformed aggregate_double_metric#90815
Normalize malformed aggregate_double_metric#90815elasticsearchmachine merged 5 commits intoelastic:mainfrom
Conversation
| e.getCause().getMessage(), | ||
| containsString("failed to parse field [field.value_count] of type [integer] in document with id '1'.") | ||
| ); | ||
| } |
There was a problem hiding this comment.
This is tested as part of the exampleMalformedValues.
| private static Number value(XContentParser parser, NumberType numberType, Number nullValue, boolean coerce) | ||
| throws IllegalArgumentException, IOException { | ||
|
|
||
| public Number value(XContentParser parser) throws IllegalArgumentException, IOException { |
There was a problem hiding this comment.
This'll need javadoc if we want to keep it. It's sort of leaky, but I've done worse. It's for a good cause.
There was a problem hiding this comment.
This is leaky indeed, but I subscribe to your good cause. Not sure if there's a better way to parse and index the value. If the es-search is ok with it, I am fine too
There was a problem hiding this comment.
Maybe @romseygeek should have a look here too.
This makes `ignore_malformed` for `aggregate_double_metric` save just the top level field name into the meta `_ignored` field, like every other field. It does so by pulling part of the parsing logic back from it's delegate numeric fields. Now it uses the delegates to parse the value and to save the values, but not to handle malformed values. Instead, it handles malformed values itself on the top level. Doing this made it fairly simple to solve two other issues: * `ignore_malformed` had to remove non-malformed values that had previously been added to the document. Now we only save the values after all have been parsed. * When we validate some of the values we use to have to dig them out of the document using inefficient code that was written mostly for testing. Now that we're saving the values before adding them to the document it's easy enough to validate from that list instead which amounts to a single array access. Closes elastic#90572
|
Pinging @elastic/es-analytics-geo (Team:Analytics) |
csoulios
left a comment
There was a problem hiding this comment.
I think the big dilemma here is if we want to expose the parse/index methods of the NumberFieldMapper class. I don't see why not to.
I have left some small comments.
| someMalformedValues = true; | ||
| } | ||
| } | ||
| MalformedHandler onMalformed = new MalformedHandler(); |
There was a problem hiding this comment.
I don't understand where exactly is this MalformedHandler used.
There was a problem hiding this comment.
Uh..... Its been a while since I wrote this and I can't find it. Maybe it's a leftover of another attempt. I'll get back to you.
| } | ||
|
|
||
| // Check if all required metrics have been parsed. | ||
| for (Metric m : metrics) { |
There was a problem hiding this comment.
What if you only checked the sizes of metrics and metricsParsed. You would not have to iterate over metrics?
You think there can be a case that this fails?
| // Check that there aren't any duplicates already parsed | ||
| for (Metric m : metricsParsed.keySet()) { | ||
| NumberFieldMapper delegateFieldMapper = metricFieldMappers.get(m); | ||
| if (context.doc().getByKey(delegateFieldMapper.fieldType().name()) != null) { |
There was a problem hiding this comment.
Method Document.onlyAddKey() was supposed to check for duplicate fields in the doc. I think this method is called from NumferFieldMapper.indexValue(). In this case the duplicates check is performed twice.
There was a problem hiding this comment.
Yeah. I suppose I don't need to check this. It's just passing the right exception message back. I think don't need to check this because a duplicate will fail with the first key every time - because we don't index unless all keys are present. That's what I did above.
There was a problem hiding this comment.
I think this method deserves another visit because I see us constantly doing a test like this one to get a better error message. I'd like to smooth it a bit in a follow up if that's ok
.
| private static Number value(XContentParser parser, NumberType numberType, Number nullValue, boolean coerce) | ||
| throws IllegalArgumentException, IOException { | ||
|
|
||
| public Number value(XContentParser parser) throws IllegalArgumentException, IOException { |
There was a problem hiding this comment.
This is leaky indeed, but I subscribe to your good cause. Not sure if there's a better way to parse and index the value. If the es-search is ok with it, I am fine too
romseygeek
left a comment
There was a problem hiding this comment.
This makes sense to me, happy to have another look when @csoulios 's feedback has been addressed.
| return; | ||
| } | ||
| // Rethrow exception as is. It is going to be caught and nested in a MapperParsingException | ||
| // by its FieldMapper.MappedFieldType#parse() |
There was a problem hiding this comment.
Just FieldMapper#parse I think?
There was a problem hiding this comment.
This comment still applies
| private static Number value(XContentParser parser, NumberType numberType, Number nullValue, boolean coerce) | ||
| throws IllegalArgumentException, IOException { | ||
|
|
||
| public Number value(XContentParser parser) throws IllegalArgumentException, IOException { |
romseygeek
left a comment
There was a problem hiding this comment.
One nit in a comment, LGTM otherwise
| return; | ||
| } | ||
| // Rethrow exception as is. It is going to be caught and nested in a MapperParsingException | ||
| // by its FieldMapper.MappedFieldType#parse() |
There was a problem hiding this comment.
This comment still applies
This makes
ignore_malformedforaggregate_double_metricsave just the top level field name into the meta_ignoredfield, like every other field. It does so by pulling part of the parsing logic back from it's delegate numeric fields. Now it uses the delegates to parse the value and to save the values, but not to handle malformed values. Instead, it handles malformed values itself on the top level.Doing this made it fairly simple to solve two other issues:
ignore_malformedhad to remove non-malformed values that had previously been added to the document. Now we only save the values after all have been parsed.Closes #90572