Skip to content

Conversation

pulak777
Copy link

@pulak777 pulak777 commented Sep 9, 2024

This makes sure that dates that overflow a long fail with a reasonable message rather than an ArithmeticException. This mostly just hits the field mapper.

@pulak777 pulak777 requested a review from a team as a code owner September 9, 2024 08:30
@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team needs:triage Requires assignment of a team area label v8.16.0 labels Sep 9, 2024
@pulak777 pulak777 force-pushed the handle-long-overflow branch from 20a1d47 to 0c9b57f Compare September 9, 2024 08:35
@alex-spies alex-spies added :Analytics/ES|QL AKA ESQL and removed needs:triage Requires assignment of a team area label labels Sep 9, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Sep 9, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elasticmachine, ok to test

@nik9000 nik9000 added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Sep 9, 2024
@nik9000 nik9000 self-assigned this Sep 9, 2024
@nik9000 nik9000 changed the title Handle long overflow Handle long overflow in dates Sep 9, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Sep 9, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@nik9000
Copy link
Member

nik9000 commented Sep 9, 2024

I think it'd be nice to have a file like 80_date_nanos.yml that asserts what we expect to happen with this one on dates. Those files are the most integration-test-style things we do and is nice and paranoid about the presentation of the error.

@nik9000
Copy link
Member

nik9000 commented Sep 9, 2024

@elasticsearchmachine test this please

@nik9000 nik9000 removed their assignment Sep 9, 2024
@nik9000
Copy link
Member

nik9000 commented Sep 9, 2024

I'm removing myself as the assignee. I think it should be one of the search foundations folks. I can certainly review the ESQL side of things.

Copy link

cla-checker-service bot commented Sep 9, 2024

💚 CLA has been signed

@pulak777 pulak777 force-pushed the handle-long-overflow branch from cde2dba to fe1655d Compare September 9, 2024 14:58
@smalyshev smalyshev self-assigned this Sep 9, 2024
area: Search
type: bug
issues:
- 112483
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this patch solves issue #112483 though - wouldn't IllegalArgumentException still produce 500? One would have to catch it in DateFieldMapper and convert it to ElasticsearchParseException to make it 4xx if I understand it correctly. Which however raises the question - if we'd have to catch it there, does it really need to be also converted in toLongMillis (not a rhetorical question, I don't have a predetermined answer to it)?

Copy link
Author

@pulak777 pulak777 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with this point. Now I think, the only use case of this patch can be providing better error message to the user (given that we catch it in DateFieldMapper as well, and convert to ElasticsearchParseException to make it 4xx)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException does normally get converted to a 400 error here: https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/ExceptionsHelper.java#L64 . Any reason why this one specifically would lead to a 500 instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of this and assumed IllegalArgumentException returns 500 based on previous comment. As that's not the case, I think the patch should work without additonal modification

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah maybe I was confusing it with another exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that verifies this? Don't just believe me :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't verify the full circle here because the original issue did not contain reproducing example and I am not sure how to reproduce it from scratch. But this suggests @javanna is correct:

} else if (t instanceof IllegalArgumentException) {
so while I'd be more happy if we had full cycle test I think this is ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ sounds good.

@smalyshev
Copy link
Contributor

@elasticmachine test this please

@smalyshev
Copy link
Contributor

smalyshev commented Sep 26, 2024

@pulak777 looks like we have some checkstyle problems here, please fix them. Usually just running ./gradlew spotlessApply takes care of that.

@pulak777
Copy link
Author

done

@smalyshev
Copy link
Contributor

@elasticmachine test this please

@smalyshev
Copy link
Contributor

Looks like it breaks some tests, e.g.:

DateFieldMapperTests > testIgnoreMalformedFalseByDefault FAILED
  | java.lang.AssertionError: incorrect exception while parsing {"field":"-522000000"}
  | Expected: a string containing "long overflow"
  | but: was "date[-522000000-01-01T00:00:00Z] is too far in the past to fit in a long milliseconds variable"

@pulak777
Copy link
Author

is it possible to grant me access to see the failing tests on ci? it kinda takes forever to run all the tests on my laptop

@smalyshev
Copy link
Contributor

smalyshev commented Sep 30, 2024

@pulak777 Not sure about the access, but look at org.elasticsearch.index.mapper.DateFieldMapperTests there are a bunch of failing tests there. You should be able to just run ./gradlew ":server:test" --tests "org.elasticsearch.index.mapper.DateFieldMapperTests" and see it, it should be pretty quick.

@pulak777
Copy link
Author

updated the failing tests in "org.elasticsearch.index.mapper.DateFieldMapperTests"

@smalyshev
Copy link
Contributor

@elasticmachine test this please

@smalyshev
Copy link
Contributor

@elasticmachine update branch

@smalyshev
Copy link
Contributor

@elasticmachine test this please

@mark-vieira mark-vieira added auto-backport Automatically create backport pull requests when merged and removed auto-backport-and-merge labels Oct 4, 2024
@smalyshev
Copy link
Contributor

@elasticmachine update branch

@smalyshev
Copy link
Contributor

@elasticmachine test this please

@smalyshev
Copy link
Contributor

Replaced by #124048 to update to current code.

@smalyshev smalyshev closed this Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >enhancement external-contributor Pull request authored by a developer outside the Elasticsearch team :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants