-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Conversation
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
Pinging @elastic/es-analytics-geo |
Pinging @elastic/es-core-infra |
libs/x-content/src/test/java/org/elasticsearch/common/xcontent/MapXContentParserTests.java
Show resolved
Hide resolved
libs/x-content/src/test/java/org/elasticsearch/common/xcontent/MapXContentParserTests.java
Show resolved
Hide resolved
libs/x-content/src/main/java/org/elasticsearch/common/xcontent/support/MapXContentParser.java
Show resolved
Hide resolved
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.
@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)) { |
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.
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()); |
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.
"numeric" -> "boolean" ?
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. |
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.
thank you Igor!
@elasticmachine run elasticsearch-ci/1 |
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 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