Skip to content

DotExpandingXContentParser to expose the original token location#84970

Merged
javanna merged 3 commits intoelastic:masterfrom
javanna:fix/dot_expand_token_location
Mar 16, 2022
Merged

DotExpandingXContentParser to expose the original token location#84970
javanna merged 3 commits intoelastic:masterfrom
javanna:fix/dot_expand_token_location

Conversation

@javanna
Copy link
Copy Markdown
Contributor

@javanna javanna commented Mar 15, 2022

With #79922 we have introduced a parser that expands dots in fields names on the fly, so that the expansion no longer needs to be handled by consumers.

The token location exposed by such parser can be confusing to interpret: consumers are parsing the expanded version which requires jumping ahead reading tokens and exposing additional field names and start objects, while users have sent the unexpanded version and would like errors to refer to the original content.

This commit adds a test for this scenario and tweaks the DotExpandingXContentParser to cache the token location before jumping ahead to expand dots in field names.

@javanna javanna added >bug :Search/Search Search-related issues that do not fall into other categories v8.2.0 v8.1.1 labels Mar 15, 2022
@javanna javanna requested a review from romseygeek March 15, 2022 10:53
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Mar 15, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @javanna, I've created a changelog YAML for you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I meant to add a test to reproduce this issue when indexing a document, but I did not find an easy way to do so. It turns out that a lot of errors that we throw as MapperParsingException don't actually hold the xcontent location, and the ones that do are parse exception coming from jackson directly. For the latter, the token location is not aligned only while expanding start or end object, which makes it hard to recreate the situation where the wrong token location would get returned without my fix.

All this said, I came to reconsider how important this fix is. Maybe in practice nobody will ever notice...?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or maybe we should be including xcontent location in more parsing exceptions? It's a bit odd that we use the same exception type for parsing mappings and parsing documents as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I opened #85083

@javanna javanna added :Search Foundations/Mapping Index mappings, including merging and defining field types and removed :Search/Search Search-related issues that do not fall into other categories labels Mar 15, 2022
@javanna
Copy link
Copy Markdown
Contributor Author

javanna commented Mar 15, 2022

run elasticsearch-ci/part-2

@javanna
Copy link
Copy Markdown
Contributor Author

javanna commented Mar 15, 2022

run elasticsearch-ci/bwc

Copy link
Copy Markdown
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

LGTM

@javanna javanna changed the base branch from master to main March 16, 2022 10:53
javanna added 3 commits March 16, 2022 11:55
With elastic#79922 we have introduced a parser that expands dots in fields names on the fly, so that the expansion no longer needs to be handled by consumers.

The token location exposed by such parser can be confusing to interpret: consumers are parsing the expanded version which requires jumping ahead reading tokens and exposing additional field names and start objects, while users have sent the unexpanded version and would like errors to refer to the original content.

This commit adds a test for this scenario and tweaks the DotExpandingXContentParser to cache the token location before jumping ahead to expand dots in field names.
@javanna javanna force-pushed the fix/dot_expand_token_location branch from 08bbbaf to 7474c98 Compare March 16, 2022 10:56
@javanna javanna changed the base branch from main to master March 16, 2022 10:58
@javanna javanna added the auto-backport Automatically create backport pull requests when merged label Mar 16, 2022
@javanna javanna merged commit 4a26ed2 into elastic:master Mar 16, 2022
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

💚 Backport successful

Status Branch Result
8.1

javanna added a commit to javanna/elasticsearch that referenced this pull request Mar 16, 2022
…stic#84970)

With elastic#79922 we have introduced a parser that expands dots in fields names on the fly, so that the expansion no longer needs to be handled by consumers.

The token location exposed by such parser can be confusing to interpret: consumers are parsing the expanded version which requires jumping ahead reading tokens and exposing additional field names and start objects, while users have sent the unexpanded version and would like errors to refer to the original content.

This commit adds a test for this scenario and tweaks the DotExpandingXContentParser to cache the token location before jumping ahead to expand dots in field names.
javanna added a commit that referenced this pull request Mar 16, 2022
)

With #79922 we have introduced a parser that expands dots in fields names on the fly, so that the expansion no longer needs to be handled by consumers.

The token location exposed by such parser can be confusing to interpret: consumers are parsing the expanded version which requires jumping ahead reading tokens and exposing additional field names and start objects, while users have sent the unexpanded version and would like errors to refer to the original content.

This commit adds a test for this scenario and tweaks the DotExpandingXContentParser to cache the token location before jumping ahead to expand dots in field names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.1.1 v8.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants