-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Add method that parses dates without throwing exceptions #83801
base: main
Are you sure you want to change the base?
Conversation
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Pinging @elastic/es-data-management (Team:Data Management) |
@elasticmachine run elasticsearch-ci/bwc |
@elasticmachine update branch |
* @return Tuple containing a boolean value indicating parsing success or failure and a java time object containing | ||
* the parsed input in the case of successful parsing | ||
*/ | ||
Tuple<Boolean, TemporalAccessor> parseWithoutException(String input); |
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.
Is it expected that a success could result in a null TemporalAccessor
? That is, is it acceptable to return Tuple.tuple(true, null)
?
If not, what about Optional<TemporalAccessor>
?
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.
Good idea. Done in 15622ec
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.
Could you explain how this differs from the existing parse method? The existing method doesn't catch exceptions, it looks almost identical to your new implementation. If the goal is to simply do away with any exceptions, then I think we should change the existing parse method to work like you have, but return null
on no match. Having two methods will make it unclear which should be used.
* @return Tuple containing a boolean value indicating parsing success or failure and a java time object containing | ||
* the parsed input in the case of successful parsing | ||
*/ | ||
Optional<TemporalAccessor> parseWithoutException(String input); |
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 do not think we should add another parse method. If this is more performant, then let's change the implementation of parse.
@rjernst, the existing method will throw an exception if none of the parsers complete successfully. I believe this was the intended behavior of the method given the explicit This method is also used in many places in ES (mappings, cluster metadata, etc.) where its behavior is at least expected if not preferred since exceptions are explicitly caught and handled but null return values are not. I wouldn't presume to change all those other usages as a date parsing failure in those cases may very well be exceptional. |
I don't think date parsing failure in other cases within Elasticsearch is any more or less exceptional. I would argue that even in ingest processors not having any patterns match is exceptional. Can you explain in what situation not matching any patterns is expected and normal? I don't have a preference for either way, but I think we should stick with one type of error handling. Your new method is almost a copy of the existing parse method. These kinds of things can become tricky to keep in sync as changes are made over time. And like I mentioned in my previous comment, having 2 different ways to call a parser is confusing for callers, not knowing which is preferred. |
To be used to improve the performance of the date processor when it encounters a lot of date patterns that do not match the supplied input.
Relates to #73918