-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Pass InputStream when creating XContent parser #28754
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
Conversation
Rather than passing the raw `BytesReference` in when creating the xcontent parser, this passes the StreamInput (which is an InputStream), this allows us to decouple XContent from BytesReference. This also removes the use of `commons.Booleans` so it doesn't require more external commons classes. Related to elastic#28504
jasontedor
left a comment
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.
Left one comment, no need for another pass.
| static boolean isStrictDuplicateDetectionEnabled() { | ||
| // Don't allow duplicate keys in JSON content by default but let the user opt out | ||
| return Booleans.parseBoolean(System.getProperty("es.xcontent.strict_duplicate_detection", "true")); | ||
| String dupProp = System.getProperty("es.xcontent.strict_duplicate_detection", "true"); |
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.
Can you make this one separate?
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.
A separate PR?
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.
Yes please, the change has nothing to do with the title (it does with the goal, but not the title).
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.
Certainly, thanks for clarifying
| /** | ||
| * Creates a parser over the provided bytes. | ||
| * @deprecated use {@link #createParser(NamedXContentRegistry, DeprecationHandler, InputStream)} | ||
| * instead, the BytesReference will be removed it a future commit |
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.
s/it/in , also not sure what you mean with "the BytesReference will be removed in a future commit", maybe the sentence needs to be clarified.
This removes the use of the `common.Boolean` class from two of the XContent classes, so they can be decoupled from the ES code as much as possible. Related to elastic#28754, elastic#28504
* Pass InputStream when creating XContent parser Rather than passing the raw `BytesReference` in when creating the xcontent parser, this passes the StreamInput (which is an InputStream), this allows us to decouple XContent from BytesReference. This also removes the use of `commons.Booleans` so it doesn't require more external commons classes. Related to #28504 * Undo boolean removal * Enhance deprecation javadoc
* es/master: (143 commits) Revert "Disable BWC tests for build issues" Remove AcknowledgedRestListener in favour of RestToXContentListener (#28724) Build: Consolidate archives and packages configuration (#28760) Skip some plugins service tests on Windows Migrate some *ResponseTests to AbstractStreamableXContentTestCase (#28749) Disable BWC tests for build issues Ensure that azure stream has socket privileges (#28751) [DOCS] Fixed broken link. Pass InputStream when creating XContent parser (#28754) [DOCS] Changed to use transient setting to reenabled allocation. Closes #27677 Delay path expansion on Windows [TEST] replace randomAsciiAlphanumOfLengthBetween with randomAsciiLettersOfLengthBetween [Tests] Extract the testing logic for Google Cloud Storage (#28576) [Docs] Update links to java9 docs (#28750) version set in ingest pipeline (#27573) Revert "Add startup logging for standalone tests" Tests: don't wait for completion while trying to get completed task Add 5.6.9 snapshot version [Docs] Java high-level REST client : clean up (#28703) Updated distribution outputs in contributing docs ...
* es/6.x: (140 commits) Remove AcknowledgedRestListener in favour of RestToXContentListener (#28724) Migrate some *ResponseTests to AbstractStreamableXContentTestCase (#28749) Revert "Disable BWC tests for build issues" Skip some plugins service tests on Windows Build: Consolidate archives and packages configuration (#28760) Ensure that azure stream has socket privileges (#28773) Disable BWC tests for build issues Pass InputStream when creating XContent parser (#28754) [DOCS] Fixed broken link. [DOCS] Changed to use transient setting to reenabled allocation. Closes #27677 Delay path expansion on Windows [TEST] replace randomAsciiAlphanumOfLengthBetween with randomAsciiLettersOfLengthBetween REST high-level client: add support for Rollover Index API (#28698) [Tests] Extract the testing logic for Google Cloud Storage (#28576) Moved Grok helper code to a separate Gradle module and let ingest-common module depend on it. version set in ingest pipeline (#27573) [Docs] Update links to java9 docs (#28750) Revert "Add startup logging for standalone tests" Tests: don't wait for completion while trying to get completed task Add 5.6.9 snapshot version ...
| BytesReference bytesRef = (fieldValue == null) ? new BytesArray("null") : new BytesArray(fieldValue.toString()); | ||
| try (XContentParser parser = JsonXContent.jsonXContent | ||
| .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytesRef)) { | ||
| .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytesRef.streamInput())) { |
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.
These input streams need to be closed.
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 believe closing the XContentParser closes the internal JsonParser, which closes the stream (similar to other wrapping chains with streams/readers).
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.
That’s correct but it’s not enough. An exception could be thrown constructing the parser in which case the stream will not be closed.
* Pass InputStream when creating XContent parser Rather than passing the raw `BytesReference` in when creating the xcontent parser, this passes the StreamInput (which is an InputStream), this allows us to decouple XContent from BytesReference. This also removes the use of `commons.Booleans` so it doesn't require more external commons classes. Related to elastic#28504 * Undo boolean removal * Enhance deprecation javadoc
* Remove Booleans use from XContent and ToXContent This removes the use of the `common.Boolean` class from two of the XContent classes, so they can be decoupled from the ES code as much as possible. Related to elastic#28754, elastic#28504
Rather than passing the raw
BytesReferencein when creating the xcontentparser, this passes the StreamInput (which is an InputStream), this allows us to
decouple XContent from BytesReference.
This also removes the use of
commons.Booleansso it doesn't require moreexternal commons classes.
Related to #28504