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-17604] Implement format factory for CSV serialization and #12065

Closed
wants to merge 2 commits into from

Conversation

danny0405
Copy link
Contributor

deseriazation schema of RowData type

What is the purpose of the change

Implements format factory for CSV RowData Se/De schema so that they can use in SQL.

Brief change log

  • A new CsvFormatFactory, the options are in style of what FLIP-122 has concluded.

Verifying this change

Added UTs.

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

  • Dependencies (does it add or upgrade a dependency): no
  • 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, Kubernetes/Yarn/Mesos, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? not documented

@flinkbot
Copy link
Collaborator

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit a2a08d5 (Mon May 11 03:15:34 UTC 2020)

Warnings:

  • 1 pom.xml files were touched: Check for build and licensing issues.
  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

Please see the Pull Request Review Guide for a full explanation of the review process.


The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

// Options
// ------------------------------------------------------------------------

private static final ConfigOption<Character> FIELD_DELIMITER = ConfigOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you extract these config options to a CsvOptions? Because file system also requires these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would do, thanks for the suggestions ~

@flinkbot
Copy link
Collaborator

flinkbot commented May 11, 2020

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build
  • @flinkbot run azure re-run the last Azure build

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

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

Thanks, I left some comments.

@Test
public void testInvalidCharacterOption() {
thrown.expect(ValidationException.class);
thrown.expect(containsCause(new ValidationException("Option [csv.quote-character] must be a Character.")));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
thrown.expect(containsCause(new ValidationException("Option [csv.quote-character] must be a Character.")));
thrown.expect(containsCause(new ValidationException("Option 'csv.quote-character' must be a Character.")));

public static final ConfigOption<String> ARRAY_ELEMENT_DELIMITER = ConfigOptions
.key("array-element-delimiter")
.stringType()
.noDefaultValue();
Copy link
Member

Choose a reason for hiding this comment

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

default value is ;.

DynamicTableFactory.Context context,
ReadableConfig formatOptions) {
validateFormatOptions(formatOptions);
return new SinkFormat<SerializationSchema<RowData>>() {
Copy link
Member

Choose a reason for hiding this comment

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

Add a empty line before this.

public static final ConfigOption<String> FIELD_DELIMITER = ConfigOptions
.key("field-delimiter")
.stringType()
.defaultValue(",");
Copy link
Member

Choose a reason for hiding this comment

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

Could you add .withDescription(...) to each option? We may auto generate the documentation in the near future. You can refer description in the documentation.

ConfigOption<String> option) {
if (tableOptions.getOptional(option).isPresent()) {
if (tableOptions.get(option).length() != 1) {
throw new ValidationException(String.format("Option [%s.%s] must be a Character.", IDENTIFIER, option.key()));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw new ValidationException(String.format("Option [%s.%s] must be a Character.", IDENTIFIER, option.key()));
throw new ValidationException(String.format("Option '%s.%s' must be a single character, but was '%s'.", IDENTIFIER, option.key(), tableOptions.get(option)));

Use 'csv.xxx' to be more align with DDL options. And use character instead of Character because this is not in Java language.

}
validateCharacterVal(tableOptions, FIELD_DELIMITER);
validateCharacterVal(tableOptions, QUOTE_CHARACTER);
validateCharacterVal(tableOptions, ESCAPE_CHARACTER);
Copy link
Member

Choose a reason for hiding this comment

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

ARRAY_ELEMENT_DELIMITER is also a single character in CsvValidator.

// Validation
// ------------------------------------------------------------------------

private static void validateFormatOptions(ReadableConfig tableOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

We should also check LINE_DELIMITER is one of "\r", "\n", "\r\n".

@SuppressWarnings("unchecked")
@Override
public ScanFormat<DeserializationSchema<RowData>> createScanFormat(
DynamicTableFactory.Context context, ReadableConfig formatOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

Call FactoryUtil.validateFactoryOptions(this, formatOptions); at the beginning. It will checks all the options.
Please also add a test for verify invalid "csv.ignore-parse-errors" = "abc" option.

Copy link
Contributor Author

@danny0405 danny0405 May 13, 2020

Choose a reason for hiding this comment

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

Added to FactoryUtil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in the factory instead.

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

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

Thanks for the updating. LGTM.

@wuchong
Copy link
Member

wuchong commented May 14, 2020

The failed tests are not related to this one. Will merge it.

@wuchong
Copy link
Member

wuchong commented May 14, 2020

The failed python tests is caused by FLINK-17596.

@wuchong wuchong closed this in 654a637 May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants