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-21386][datastream] Postpone FromElementsFunction serialization to respect later type customization #15507

Conversation

kezhuw
Copy link
Member

@kezhuw kezhuw commented Apr 7, 2021

What is the purpose of the change

Respect type customization(eg. SingleOutputStreamOperator.returns) for FromElementsFunction.

Brief change log

  • Add test to assert that AbstractUdfStreamOperator redirects OutputTypeConfigurable to function
  • Postpone FromElementsFunction serialization to respect later type customization

Verifying this change

This change added tests and can be verified as follows:

  • StreamGraphGeneratorTesttestOutputTypeConfigurationWithUdfStreamOperator
  • FromElementsFunctionTest
  • Existing tests that using FromElementsFunction directly or indirectly.

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? (no)
  • If yes, how is the feature documented? (not applicable)

WARNING: possible breaking change

Previously, FromElementsFunction serializes elements eagerly. After this pr, it serializes elements lazily. Any code which depend on previous behavior may break. Depends on perspective, this might be treated as a breaking change. Following are possible affected apis:

  • StreamExecutionEnvironment.fromElements(OUT... data)
  • StreamExecutionEnvironment.fromElements(Class<OUT> type, OUT... data)
  • StreamExecutionEnvironment.fromCollection(Collection<OUT> data)
  • StreamExecutionEnvironment.fromCollection(Collection<OUT> data, TypeInformation<OUT> typeInfo)

… to respect later type customization

This fixes cases where earlier determined serializer was incorrect and returns() was ignored.
@flinkbot
Copy link
Collaborator

flinkbot commented Apr 7, 2021

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 493e760 (Fri May 28 09:00:27 UTC 2021)

Warnings:

  • 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

@flinkbot
Copy link
Collaborator

flinkbot commented Apr 7, 2021

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
Contributor

@dawidwys dawidwys left a comment

Choose a reason for hiding this comment

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

Thank you @kezhuw for the quick PR. I had some smaller comments.

}

@Test
public void testSetOutputTypeWithExistingBrokenSerializer() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this test different from the one above? In the context of setOutputType?

Could we have one test (instead of testSetOutputTypeWithExistingBrokenSerializer & testSetOutputTypeWithDifferentSerializer) that verifies that the updated serializer is used? E.g. a custom string serializer that adds additional characters, or something similar?

Copy link
Member Author

Choose a reason for hiding this comment

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

testSetOutputTypeWithExistingBrokenSerializer will breaks if there is no setOutputType after while testSetOutputTypeWithDifferentSerializer will succeed(assumed that there is not assertion for different serializer).

testSetOutputTypeWithExistingBrokenSerializer matches scenario @zentol posted in FLINK-21386 that eagerly determined is incorrect. I reuse DeserializeTooMuchType for its incorrectness(see testDeSerializationError).

There are do duplication between the two. How about removing testSetOutputTypeWithDifferentSerializer and adding assertion for different serializer in testSetOutputTypeWithExistingBrokenSerializer ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Merged to one testSetOutputTypeWithExistingBrokenSerializer.

@@ -209,6 +211,25 @@ public void testVirtualTransformations() throws Exception {
instanceof ShufflePartitioner);
}

@Test
public void testOutputTypeConfigurationWithUdfStreamOperator() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this test related to the fromElements function?

Copy link
Member Author

Choose a reason for hiding this comment

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

FromElementsFunction relies on feature that AbstractUdfStreamOperator will redirect OutputTypeConfigurable to its function. But StreamGraphGeneratorTest does not have test for this while it has tests for StreamOperator(testOutputTypeConfigurationWithOneInputTransformation and testOutputTypeConfigurationWithTwoInputTransformation). This test resides in a separate commit.

} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
SourceFunction<OUT> function = new FromElementsFunction<>(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a single positive test for the returns method on fromElements?

Copy link
Member Author

@kezhuw kezhuw Apr 7, 2021

Choose a reason for hiding this comment

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

Add StreamExecutionEnvironmentTest.testFromElementsPostConstructionType.

…r redirects OutputTypeConfigurable to function
…ization to respect later type customization

Changes after reviewing:
* Add `testFromElementsDeducedType` and `testFromElementsPostConstructionType` in `StreamExecutionEnvironmentTest`.
* More meaningful exception message for calling `setOutputType` after serialization/deserialization.
* Use `junit.rules.ExpectedException` instead of try-catch.
* Merge `testSetOutputTypeWithExistingBrokenSerializer` and `testSetOutputTypeWithDifferentSerializer` to one.
@kezhuw
Copy link
Member Author

kezhuw commented Apr 7, 2021

Hi @dawidwys, I have pushed fixup commit for next reviewing cycle. Please confirm whether I have resolve your concerns. Thanks.

@kezhuw
Copy link
Member Author

kezhuw commented Apr 8, 2021

Test was cancelled in kafka_gelly.

@kezhuw kezhuw requested a review from dawidwys April 8, 2021 03:03
Copy link
Contributor

@dawidwys dawidwys 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 update!. Looks good now! Merging...

@dawidwys dawidwys closed this in 0fc03e4 Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants