[FLINK-39378][table] Add support for Context, timers and on_time to PTF test harness#28326
[FLINK-39378][table] Add support for Context, timers and on_time to PTF test harness#28326autophagy wants to merge 13 commits into
Conversation
…rocessTableFunctionTestHarness
b05a727 to
efe9d3a
Compare
fhueske
left a comment
There was a problem hiding this comment.
Thanks for the PR @autophagy!
I've reviewed the changes except for the test (will do that later this week).
Overall, the changes are good. Left a bunch of comments with suggestions and questions.
Cheers, Fabian
| Optional<List<StaticArgument>> staticArgsOpt = systemTypeInference.getStaticArguments(); | ||
| List<StaticArgument> staticArgs = | ||
| staticArgsOpt.orElseThrow( | ||
| () -> | ||
| new IllegalStateException( | ||
| "SystemTypeInference has no static arguments")); |
There was a problem hiding this comment.
nit
| Optional<List<StaticArgument>> staticArgsOpt = systemTypeInference.getStaticArguments(); | |
| List<StaticArgument> staticArgs = | |
| staticArgsOpt.orElseThrow( | |
| () -> | |
| new IllegalStateException( | |
| "SystemTypeInference has no static arguments")); | |
| List<StaticArgument> staticArgs = | |
| systemTypeInference.getStaticArguments().orElseThrow( | |
| () -> | |
| new IllegalStateException( | |
| "SystemTypeInference has no static arguments")); |
Can be folded?
| * eligible to fire. | ||
| */ | ||
| @Internal | ||
| class TestHarnessTimerManager { |
There was a problem hiding this comment.
It might make sense to add a separate test for this class.
| if (name != null) { | ||
| timerSet.removeIf(t -> name.equals(t.name)); | ||
| } |
There was a problem hiding this comment.
I think we should also remove unnamed timers.
There can only be one timer per timestamp and name (also if name = null).
…timers per partition key
fhueske
left a comment
There was a problem hiding this comment.
Hi @autophagy, thanks for addressing most of my earlier comments!
I've had a look at the tests and they are pretty complete.
Left a few comments with suggestions to increase the coverage.
Cheers, Fabian
| Context ctx, | ||
| @ArgumentHint({ArgumentTrait.SET_SEMANTIC_TABLE, ArgumentTrait.REQUIRE_ON_TIME}) | ||
| Row input) { | ||
| TimeContext<LocalDateTime> timeCtx = ctx.timeContext(LocalDateTime.class); |
There was a problem hiding this comment.
| TimeContext<LocalDateTime> timeCtx = ctx.timeContext(LocalDateTime.class); | |
| TimeContext<Instant> timeCtx = ctx.timeContext(Instant.class); |
to check another codepath?
There was a problem hiding this comment.
Also check with Long and java.sql.Timestamp?
| Context ctx, | ||
| @ArgumentHint({ArgumentTrait.SET_SEMANTIC_TABLE, ArgumentTrait.REQUIRE_ON_TIME}) | ||
| Row input) { | ||
| TableSemantics semantics = ctx.tableSemanticsFor("input"); |
There was a problem hiding this comment.
would be good to do the same check also for ctx.tableSemanticsFor() being called from the onTimer() method.
| @DataTypeHint("ROW<value INT>") | ||
| public static class PTFWithContext extends ProcessTableFunction<Row> { | ||
| public void eval(Context ctx, @ArgumentHint(ArgumentTrait.ROW_SEMANTIC_TABLE) Row input) { | ||
| collect(input); | ||
| } | ||
| } |
There was a problem hiding this comment.
I don't think we need this PTF (and the corresponding test) anymore.
Everything it covers is covered many times by all the new tests.
| private final Class<TimeType> conversionClass; | ||
|
|
||
| TestTimeContext(Class<TimeType> conversionClass) { | ||
| this.conversionClass = conversionClass; |
There was a problem hiding this comment.
Should we eagerly check here if conversionClass is a supported class?
|
|
||
| // Advance only left table past the timer — global watermark is still min(left, right) | ||
| // Since right has no watermark yet, global won't advance enough to fire | ||
| harness.setWatermarkForTable("rightTable", LocalDateTime.of(2025, 1, 1, 0, 0, 3)); |
There was a problem hiding this comment.
Do we also have tests that use the other supported WM data types?
| LocalDateTime.of(2025, 1, 1, 0, 0, 6))); | ||
|
|
||
| assertThat(harness.getPendingTimers()).isEmpty(); | ||
| assertThat(harness.getFiredTimers()).hasSize(1); |
There was a problem hiding this comment.
Also assert the specific fired timer (name + ts)?
| .withOnTimeColumn("ts") | ||
| .build()) { | ||
|
|
||
| harness.setWatermark(LocalDateTime.of(2025, 1, 1, 0, 0, 5)); |
There was a problem hiding this comment.
also check for setWatermarkForTable()?
|
|
||
| harness.processElement(Row.of("P1", LocalDateTime.of(2025, 1, 1, 0, 0, 1))); | ||
|
|
||
| assertThrows( |
There was a problem hiding this comment.
check if error message is meaningful for users?
| .build()) { | ||
|
|
||
| assertThrows( | ||
| TableRuntimeException.class, |
There was a problem hiding this comment.
check if error message is meaningful?
| harness.clearOutput(); | ||
|
|
||
| harness.setWatermark(LocalDateTime.of(2025, 1, 1, 0, 0, 7)); | ||
| assertThat(harness.getOutput()).hasSize(1); |
There was a problem hiding this comment.
check that the right onTimer() method was called by checking the output row?
What is the purpose of the change
This PR adds support for
Context,OnTimerContext,TimeContext, timer registration and firing, watermark management, androwtimesupport to the PTF Test Harness.When a PTF registers a timer, the timer is stored in the TimerManager and keyed by the partition row. When the user advances the watermark using
either
setWatermarkorsetWatermarkForTable, the manager then fires all pending timers below or equal to the watermark in a deterministic order.I moved per-invocation state stuff into an
InvocationContextto make separation of concerns a little easier to follow.Rows emitted from test harness setups that configure an
on_timecolumn also contain therowtimecolumn, and the PTF rejects at the point of registration if the user tries to register a timer withPASS_COLUMNS_THROUGHenabled (similar to live, per the
PROCESS_INVALID_PASS_THROUGH_TIMERStest on live.)Some open questions remain. One is that there's an edge case where if a user's
onTimerregisters a new timer at or before the current watermark, it then fires, and then registers,then fires, etc. Should there be some sort of max depth check here?
The second is that when defining the on time parameter in SQL, you pass in
DESCRIPTOR(ts), but in the harness you just pass in the string name of the column. Would it instead be better to supportwithOnTime("DESCRIPTOR(ts)")to better mirror SQL, rather thanwithOnTimeColumn("ts")?Brief change log
Context,OnTimerContext,TimeContextinProcessTableFunctionTestHarnessProcessTableFunctionTestHarnessInvocationContextto capture per-invocation state to simplify the collector logicon_timeanduidcreateStateConverterwhere the incorrect state converters were being used for Map/List state.Verifying this change
This change added tests and can be verified as follows:
ProcessFunctionTestHarnessesTestto cover timer firing, watermark advancement and context.Does this pull request potentially affect one of the following parts:
@Public(Evolving): (no)Documentation
Was generative AI tooling used to co-author this PR?
2.1.156 (Claude Code)