[FLINK-10134] UTF-16 support for TextInputFormat bug #7157
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
(This PR is designed to solve the problem of
TextInputFormat
using UTF-16 encoding to parse files.)Brief change log
(To solve this bug, I added a file BOM header encoding check to determine the current file encoding, so that when user-defined encoding format and file with a BOM header encoding format conflict processing, specific changes in the following::)
I add
getBomFileCharset
function toDelimitedInputFormat.java
to detect the current file BOM header coding judgment, mainlyUTF-16BE
,UTF-16LE
,UTF-8 with BOM header
,UTF-32BE
,UTF-32LE
these types, default toUTF-8
.I added the
bomBytes
,fileBomCharsetMap
,bomIdentifiedCharset
,configuredCharset
variable to theDelimitedInputFormat.java
,getBomFileCharset(split)
to theopen
method, andsetBomFileCharset
to set thebomIdentifiedCharset
,fileBomCharsetMap
variable.*The file name that has been parsed is used as the key, and the encoded value is inserted as a value into thefileBomCharsetMap
.In the
DelimitedInputFormat.java
methodgetCharset()
, the encoding logic is added to obtain the encoding of the current file. I would handle the different charsets with three private fields.1.configuredCharset: This is the charset that is configured via setCharset()
2.bomIdentifiedCharset: This is the charset that is set by setBomFileCharset()
3.charset: This is the charset that is returned by getCharset(). If not set before (i.e., null), it is set first depending on the configuredCharset and bomIdentifiedCharset.
In the
DelimitedInputFormat.java
methodGetSpecialCharset
handles both special cases of user input, utf-16 utf-32.Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
testFileCharset
andtestAllFileCharset
andcreateUTFEncodedFile
andtestFileCharsetReadByMultiSplits
toTextInputFormatTest
.Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (yes)Documentation
Discuss
The following are the modifications and discussions that have been made by this bug. Thank you for the review by Fabian Hueske
jira link
pr6823
pr6710