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-13289][table-planner-blink] Blink-planner should setKeyFields to upsert table sink #9195

Closed
wants to merge 6 commits into from

Conversation

JingsongLi
Copy link
Contributor

What is the purpose of the change

Support upsert table sink in blink-planner

Verifying this change

TableSinkITCase

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): no
  • 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: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 22, 2019

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 1eeb005 (Tue Aug 06 15:51:04 UTC 2019)

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 Jul 22, 2019

CI report:

Copy link
Contributor

@tsreaper tsreaper 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 PR @JingsongLi . Looks good to me overall, just left a minor comment.

val uniqueKeys = fmq.getUniqueKeys(relNode)
if (uniqueKeys != null) {
uniqueKeys.filter(_.nonEmpty).toList.map { uniqueKey =>
val keys = new util.HashSet[String]()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a HashSet is needed? It seems that the indices returned by the ImmutableBitSet is strictly ascending. Why not just uniqueKey.asList().toArray?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove HashSet.

Copy link
Contributor

@tsreaper tsreaper left a comment

Choose a reason for hiding this comment

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

Looks good to me.

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 effort @JingsongLi . I left some comments.

// Now we pick shortest one to sink
// TODO UpsertStreamTableSink setKeyFields interface should be Array[Array[String]]
val tableKeys: Option[Array[String]] =
UpdatingPlanChecker.getUniqueKeys(getInput, planner).sortBy(_.length).headOption
Copy link
Member

Choose a reason for hiding this comment

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

There is a potential NPE at this line. Because UpdatingPlanChecker.getUniqueKeys may return null.
What about returning Option[Array[String]] like flink planner? We can move the sortBy and headOption into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can return Option[Array[Array[String]]], let sortBy and headOption still remain in caller, keep the TODO with UpsertStreamTableSink.setKeyFields

val uniqueKeys = fmq.getUniqueKeys(relNode)
if (uniqueKeys != null) {
uniqueKeys.filter(_.nonEmpty).toList
.map(_.asList().map(rowType.getFieldNames.get(_)).toArray).toArray
Copy link
Member

Choose a reason for hiding this comment

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

Can be simplified to uniqueKeys.filter(_.nonEmpty).map(_.toArray.map(fieldNames.get)).toArray


}

private[flink] class TestUpsertSink(
Copy link
Member

Choose a reason for hiding this comment

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

I would like to avoid introducing another set of testing sink (incl. upsert sink, retract sink, append sink). We also have TestingRetractTableSink, TestingUpsertTableSink, TestingAppendTableSink. Can we leverage them in this class? Maybe we need some changes for TestingUpsertTableSink.setKeyFields/setIsAppendOnly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we can make TestingUpsertTableSink support expectedKeys and expectedIsAppendOnly

@JingsongLi
Copy link
Contributor Author

@wuchong Please take a look again.

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 @JingsongLi for the updating. I left two thoughts. However, overall looks good to me now.

.assignAscendingTimestamps(_._1.toLong)
.toTable(tEnv, 'id, 'num, 'text, 'rowtime.rowtime)

val sink = new TestingUpsertTableSink(Array(0, 1, 2), TimeZone.getDefault)
Copy link
Member

Choose a reason for hiding this comment

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

Key array can be "0, 1" to align with "wend", "num"

// TODO UpsertStreamTableSink setKeyFields interface should be Array[Array[String]]
val tableKeys = {
UpdatingPlanChecker.getUniqueKeyFields(getInput, planner) match {
case Some(keys) => keys.sortBy(_.length).headOption
Copy link
Member

Choose a reason for hiding this comment

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

Should we return the longest instead of the shortest one? So that it can be the same with flink planner when window start and window end are both selected.

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.

Hi @JingsongLi , I looked into the FlinkRelMdUniqueKeys. Currently, we didn't permutate all the possible unique keys and it may touch too many things. I think it's not a blocking problem, we can fix it later.

So I will merge this pull request.

@asfgit asfgit closed this in 35237ae Jul 26, 2019
asfgit pushed a commit that referenced this pull request Jul 26, 2019
@JingsongLi JingsongLi deleted the upsert branch July 28, 2019 11:51
wzhero1 pushed a commit to wzhero1/flink that referenced this pull request Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants