Skip to content
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 Map to XContentParser Wrapper #44036

Merged
merged 4 commits into from
Jul 10, 2019
Merged

Add Map to XContentParser Wrapper #44036

merged 4 commits into from
Jul 10, 2019

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Jul 5, 2019

In some cases we need to parse some XContent that is already parsed into
a map. This is currently happening in handling source in SQL and ingest
processors as well as parsing null_value values in geo mappings. To avoid
re-serializing and parsing the value again or writing another map-based
parser this commit adds an iterator that iterates over a map as if it was
XContent. This makes reusing existing XContent parser on maps possible.

Relates to #43554

In some cases we need to parse the XContent that is already parsed into
a map. This is currently happening in handling source in SQL and ingest
node as well as parsing null_value geo values in mappings. Instead of
serialize and parse the value again or write another map-based parser
this commit adds an iterator that iterates over a map as an XContent.

Relates to elastic#43554
@imotov imotov added >non-issue :Analytics/Geo Indexing, search aggregations of geo points and shapes :Core/Infra/Core Core issues without another label v8.0.0 v7.4.0 labels Jul 5, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@talevy talevy self-requested a review July 8, 2019 16:57
Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

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

@imotov Thanks Igor, the PR makes sense.

Are we planning to use MapXContentParser in other places as well? Does this introduced complex class worth for small changes in GeoUtils and ShapeParser?

}

try (XContentParser parser = new MapXContentParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE,
Collections.singletonMap("value", value), null)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the field name doesn't matter as we discard it later, I guess it is still good to call it "null_value"

if (iterator != null && iterator.currentValue() instanceof Boolean) {
return (Boolean) iterator.currentValue();
} else {
throw new IllegalStateException("Cannot get numeric value for the current token " + currentToken());
Copy link
Contributor

Choose a reason for hiding this comment

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

"numeric" -> "boolean" ?

@imotov
Copy link
Contributor Author

imotov commented Jul 9, 2019

Are we planning to use MapXContentParser in other places as well? Does this introduced complex class worth for small changes in GeoUtils and ShapeParser?

Yes, definitely. That was the reason for adding it here. The next planned use is ingest processor in #43554. It will also mean that we will not have to serialize/deserialize huge polygons with millions of points in ShapeParser. Savings in GeoUtils are indeed pretty worthless, but since I already have it we might as well us it there.

Copy link
Contributor

@talevy talevy left a comment

Choose a reason for hiding this comment

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

thank you Igor!

@imotov
Copy link
Contributor Author

imotov commented Jul 10, 2019

@elasticmachine run elasticsearch-ci/1

@imotov imotov merged commit 85cacff into elastic:master Jul 10, 2019
imotov added a commit that referenced this pull request Jul 11, 2019
In some cases we need to parse some XContent that is already parsed into
a map. This is currently happening in handling source in SQL and ingest
processors as well as parsing null_value values in geo mappings. To avoid
re-serializing and parsing the value again or writing another map-based
parser this commit adds an iterator that iterates over a map as if it was
XContent. This makes reusing existing XContent parser on maps possible.

Relates to #43554
@imotov imotov deleted the map-parser branch May 1, 2020 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes :Core/Infra/Core Core issues without another label >non-issue v7.4.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants