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-34053][table-planner] Support state ttl hint for group aggregate #24179

Merged
merged 6 commits into from
Jan 30, 2024

Conversation

xuyangzhong
Copy link
Contributor

What is the purpose of the change

Currently, state ttl hint can work only on join node. This pr aims to support state ttl hint on group agg node.

Brief change log

  • support state ttl hint on group agg node
  • add IT cases and plan cases for this pr

Verifying this change

Some tests are added for it.

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, Kubernetes/Yarn, 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? Another pr will be introduced for it.

@flinkbot
Copy link
Collaborator

flinkbot commented Jan 23, 2024

CI report:

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

@LadyForest LadyForest self-requested a review January 25, 2024 02:19
Copy link
Contributor

@LadyForest LadyForest left a comment

Choose a reason for hiding this comment

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

Hi @xuyangzhong, thanks for the contribution! I left some comments, PTAL

BiRel biRel = (BiRel) node;
Optional<String> leftName = extractAliasOrTableName(biRel.getLeft());
Optional<String> rightName = extractAliasOrTableName(biRel.getRight());
newHints = validateAndGetNewHintsFromBiRel(leftName, rightName, oldHints);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think validateAndGetNewHints is good enough, and it's ok to have an overloaded method here. Another point is I don't think passing Optional<T> as arguments is a good practice.

Copy link
Contributor Author

@xuyangzhong xuyangzhong Jan 25, 2024

Choose a reason for hiding this comment

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

Agree with you. Since the improvement work for the input type Optional is not a part of this pr, I have created a new jira for it. https://issues.apache.org/jira/browse/FLINK-34235

Assigned to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -123,6 +130,7 @@ class StreamPhysicalGlobalGroupAggregate(
generateUpdateBefore,
needRetraction,
indexOfCountStar.map(Integer.valueOf).orNull,
StateTtlHint.getStateTtlFromHintOnSingleRel(hints),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is commented on explainTerms.
Before STATE_TTL hint is introduced, the rest query hints(mainly join hints for batch and lookup join hints for stream) are converted and use itemIf
So, I rethink the explanation format. How about

// for agg
      .itemIf(
        "stateTtl",
        StateTtlHint.getStateTtlFromHintOnSingleRel(hints),
        hints.stream().anyMatch(hint => StateTtlHint.isStateTtlHint(hint.hintName)))

// which yields
// stateTtl=[1d]

// for regular join
val ttlHint = StateTtlHint.getStateTtlFromHintOnBiRel(getHints)
      .itemIf("leftStateTtl", ttlHint.get(0), ttlHint.containsKey(0))
      .itemIf("rightStateTtl", ttlHint.get(1), ttlHint.containsKey(1))
// which yields
// leftStateTtl=[1d], rightStateTtl=[3d]

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 the printing of state hint should be placed in RelTreeWriterImpl and continue to be managed uniformly by withQueryHint.

newHints = validateAndGetNewHintsFromBiRel(leftName, rightName, oldHints);
} else if (node instanceof SingleRel) {
SingleRel singleRel = (SingleRel) node;
Optional<String> tableName = extractAliasOrTableName(singleRel.getInput());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get an empty table/alias name here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Emm it seems not, I will modify it separately in this separate jira. WDYT? https://issues.apache.org/jira/browse/FLINK-34235

Copy link
Contributor

@LadyForest LadyForest 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. LGTM

@xuyangzhong
Copy link
Contributor Author

Hi, @LadyForest. After rebasing onto master, the test for GroupAggregateRestoreTest#AGG_WITH_STATE_TTL_HINT failed due to an unknown reason. It succeeded after the savepoint metadata was regenerated. Considering the feature freeze on January 30th, I will continue to monitor CI for any unstable tests after merging this feature and will promptly address any issues during the bugfix period.

@LadyForest LadyForest merged commit f32b2a9 into apache:master Jan 30, 2024
@LadyForest
Copy link
Contributor

LadyForest commented Jan 30, 2024

Hi, @LadyForest. After rebasing onto master, the test for GroupAggregateRestoreTest#AGG_WITH_STATE_TTL_HINT failed due to an unknown reason. It succeeded after the savepoint metadata was regenerated. Considering the feature freeze on January 30th, I will continue to monitor CI for any unstable tests after merging this feature and will promptly address any issues during the bugfix period.

After debugging, I found that the _metadata has serialized the last accessed timestamp for keyed state when state retention is enabled. So I guess this test would fail in 4 days.
image
image

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