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

[FLINK-10134] UTF-16 support for TextInputFormat bug #7157

Closed
wants to merge 1 commit into from
Closed

[FLINK-10134] UTF-16 support for TextInputFormat bug #7157

wants to merge 1 commit into from

Conversation

XuQianJin-Stars
Copy link
Contributor

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 to DelimitedInputFormat.java to detect the current file BOM header coding judgment, mainly UTF-16BE, UTF-16LE, UTF-8 with BOM header, UTF-32BE, UTF-32LE these types, default to UTF-8.

  • I added the bomBytes,fileBomCharsetMap,bomIdentifiedCharset ,configuredCharset variable to the DelimitedInputFormat.java, getBomFileCharset(split) to the open method, andsetBomFileCharset to set the bomIdentifiedCharset,fileBomCharsetMap variable.*The file name that has been parsed is used as the key, and the encoded value is inserted as a value into the fileBomCharsetMap.

  • In the DelimitedInputFormat.java method getCharset(), 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:)

  • I added testFileCharset and testAllFileCharset and createUTFEncodedFile and testFileCharsetReadByMultiSplits to TextInputFormatTest.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (yes)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (yes)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no )
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (yes)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

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

@XuQianJin-Stars
Copy link
Contributor Author

hi @fhueske Thank you very much for your help. If you can spare some time, I would like to continue asking you to review this PR for me.
Best,
qianjin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants