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-19282][table sql/planner]Supports watermark push down with Wat… #13449

Merged
merged 1 commit into from Nov 7, 2020

Conversation

fsk119
Copy link
Member

@fsk119 fsk119 commented Sep 22, 2020

…ermarkStrategy

  1. convert class FunctionContext to interface which allows us convert WatermarkStrategy.Context to FunctionContext;
  2. add bindConstructorTerm in ExprCodeGenerator;
  3. add switch that WatermarkGeneratorCodeGenerator will generate WatermarkGenerator with parameterized constructor and use the term to init udf ;
  4. add rule that transpose between project and watermark assigner. After optimization, watermark assigner will replace reference with rowtime expr;

What is the purpose of the change

Allow planner to push watermark strategy into DynamicTableSource.

Brief change log

  • convert class FunctionContext to interface which allows us convert WatermarkStrategy.Context to FunctionContext;
  • add bindConstructorTerm in ExprCodeGenerator;
  • add switch that WatermarkGeneratorCodeGenerator will generate WatermarkGenerator with parameterized constructor and use the term to open udf ;
  • add rule that transpose between project and watermark assigner. After optimization, watermark assigner will replace reference with rowtime expr;

Verifying this change

This change added tests and can be verified as follows:

  • Added test that WatermarkGeneartor can be init with passed context && classload in constructor in WatermarkGeneratorCodeGenTest
  • Added test for single rule, all rule and ITcase

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

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

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / 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 b042779 (Tue Sep 22 04:43:42 UTC 2020)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!
  • This pull request references an unassigned Jira ticket. According to the code contribution guide, tickets need to be assigned before starting with the implementation work.

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 Sep 22, 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

@fsk119
Copy link
Member Author

fsk119 commented Sep 25, 2020

@flinkbot run azure

@twalthr
Copy link
Contributor

twalthr commented Oct 6, 2020

Thanks for the PR @fsk119. I would like to take a look at this PR soon. Some code changes might conflict with FLIP-107. We need to make sure that both efforts are aligned.

@fsk119
Copy link
Member Author

fsk119 commented Oct 6, 2020

Thanks for your reply. Looking forward for your suggestions!

Copy link
Contributor

@godfreyhe godfreyhe 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 contribution @fsk119 , I left some comments

Comment on lines 253 to 254
tableConfig: TableConfig,
contextTerm: String = "parameters")
Copy link
Contributor

Choose a reason for hiding this comment

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

indent

@@ -18,14 +18,16 @@

package org.apache.flink.table.planner.codegen

import org.apache.calcite.rex.RexNode
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: reorder imports

@@ -35,7 +37,8 @@ object WatermarkGeneratorCodeGenerator {
def generateWatermarkGenerator(
config: TableConfig,
inputType: RowType,
watermarkExpr: RexNode): GeneratedWatermarkGenerator = {
watermarkExpr: RexNode,
contextTerm: String = null): GeneratedWatermarkGenerator = {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use None instead of null in Scala

@@ -44,11 +47,33 @@ object WatermarkGeneratorCodeGenerator {
" but is " + watermarkOutputType)
}
val funcName = newName("WatermarkGenerator")
val ctx = CodeGeneratorContext(config)
val ctx = if (contextTerm != null) {
new ConstantCodeGeneratorContext(config, contextTerm)
Copy link
Contributor

Choose a reason for hiding this comment

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

why we use ConstantCodeGeneratorContext here ? ConstantCodeGeneratorContext is used for constant reducer, we should create a new special CodeGeneratorContext for watermark generator

import java.util.Collections
import java.util.function.{Function => JFunction, Supplier => JSupplier}

import org.apache.flink.api.common.eventtime.WatermarkGeneratorSupplier
Copy link
Contributor

Choose a reason for hiding this comment

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

reorder imports

Comment on lines 168 to 170
/*
* Used by apply method to deal with.
* */
Copy link
Contributor

Choose a reason for hiding this comment

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

/**
 * 
 */

Comment on lines 48 to 73
util.buildStreamProgram(FlinkStreamProgram.DEFAULT_REWRITE());
CalciteConfig calciteConfig = TableConfigUtils.getCalciteConfig(util.tableEnv().getConfig());
calciteConfig.getStreamProgram().get().addLast(
"PushWatermarkIntoTableSourceScanRule",
FlinkHepRuleSetProgramBuilder.<StreamOptimizeContext>newBuilder()
.setHepRulesExecutionType(HEP_RULES_EXECUTION_TYPE.RULE_SEQUENCE())
.setHepMatchOrder(HepMatchOrder.BOTTOM_UP)
.add(RuleSets.ofList(
WatermarkAssignerProjectTransposeRule.INSTANCE,
PushWatermarkIntoTableSourceScanRule.INSTANCE))
.build()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

it's better to build a specific program that only contains the rules needed for the current test, this could avoid interference with other rules.

" 'bounded' = 'false'\n" +
")";
util.tableEnv().executeSql(ddl);
util.verifyPlan("select * from MyTable");
Copy link
Contributor

Choose a reason for hiding this comment

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

add some tests about

  1. projection/filter in select,
  2. watermark expression contains two field references

Copy link
Member Author

Choose a reason for hiding this comment

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

Please refer to testWatermarkOnComputedColumnWithQuery
and testWatermarkOnComputedColumnWithMultipleInputs.

import java.time.ZoneOffset;

/**
* Test rule PushWatermarkIntoTableSourceScanRule.
Copy link
Contributor

Choose a reason for hiding this comment

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

Test for [[PushWatermarkIntoTableSourceScanRule]] and [[WatermarkAssignerProjectTransposeRule]]

@Before
override def before(): Unit = {
super.before()
env.setParallelism(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

why parallelism is 1 ?

Copy link
Contributor

@godfreyhe godfreyhe 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, I left some comments


@Before
public void setup() {
util.buildStreamProgram(FlinkStreamProgram.LOGICAL_REWRITE());
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

</Resource>
<Resource name="planAfter">
<![CDATA[
WatermarkAssigner(rowtime=[c], watermark=[-(c, 5000:INTERVAL SECOND)])
Copy link
Contributor

Choose a reason for hiding this comment

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

why the watermark node can't be pushed down

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! I add the wrong rule into the rule set. It works now.

" b bigint,\n" +
" c timestamp(3) not null,\n" +
" d as c + interval '5' second,\n" +
" watermark for d as d - interval '5' second\n" +
Copy link
Contributor

Choose a reason for hiding this comment

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

add a test about watermark for d as d - interval '5' second + other timestamp field

Copy link
Member Author

Choose a reason for hiding this comment

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

The watermark expression only allows one input reference. The expression mentioned is illegal

Copy link
Contributor

@godfreyhe godfreyhe 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 @fsk119 , LGTM

@fsk119
Copy link
Member Author

fsk119 commented Nov 6, 2020

Thanks for your review! Very thanks!

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