[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 1 commit 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
|
|
||
| // Verify the timer was registered | ||
| assertThat(harness.getPendingTimers()).hasSize(1); | ||
| assertThat(harness.getPendingTimers().get(0).getName()).isEqualTo("timeout-Alice"); |
There was a problem hiding this comment.
is it possible to assert the timestamp of a timer as well?
| assertThat(harness.getPendingTimers().get(0).getName()).isEqualTo("timeout-Alice"); | ||
|
|
||
| // Advance watermark past the timer's timestamp to fire it | ||
| harness.clearOutput(); |
There was a problem hiding this comment.
the output should still be empty, no?
|
|
||
| harness.processElement(Row.of("P1", LocalDateTime.of(2025, 1, 1, 0, 0, 1))); | ||
| harness.processElement(Row.of("P1", LocalDateTime.of(2025, 1, 1, 0, 0, 1))); | ||
| harness.processElement(Row.of("P1", LocalDateTime.of(2025, 1, 1, 0, 0, 1))); |
There was a problem hiding this comment.
| harness.processElement(Row.of("P1", LocalDateTime.of(2025, 1, 1, 0, 0, 1))); | |
| harness.processElement(Row.of("P1", LocalDateTime.of(2025, 1, 1, 0, 0, 2))); |
show that two timers can be fired from one wm advancement?
| harness.setWatermark(LocalDateTime.of(2025, 1, 1, 0, 0, 7)); | ||
| assertThat(harness.getOutput()) | ||
| .containsExactly( | ||
| Row.of("P1", "count=3", LocalDateTime.of(2025, 1, 1, 0, 0, 6))); |
There was a problem hiding this comment.
| harness.setWatermark(LocalDateTime.of(2025, 1, 1, 0, 0, 7)); | |
| assertThat(harness.getOutput()) | |
| .containsExactly( | |
| Row.of("P1", "count=3", LocalDateTime.of(2025, 1, 1, 0, 0, 6))); | |
| harness.setWatermark(LocalDateTime.of(2025, 1, 1, 0, 0, 8)); | |
| assertThat(harness.getOutput()) | |
| .containsExactly( | |
| Row.of("P1", "count=2", LocalDateTime.of(2025, 1, 1, 0, 0, 6)), | |
| Row.of("P1", "count=3", LocalDateTime.of(2025, 1, 1, 0, 0, 7)),); |
| - `Context` parameter | ||
| - Timers (`onTimer`) | ||
| - `on_time` / `rowtime` |
| private static Method findOnTimerMethod( | ||
| Class<?> functionClass, List<ArgumentInfo> arguments) { | ||
| List<Method> candidates = ExtractionUtils.collectMethods(functionClass, "onTimer"); | ||
| if (candidates.isEmpty()) { |
There was a problem hiding this comment.
shouldn't we also fail if we have more than one candidate?
How would the framework decide which onTimer method to call?
| ListView.class.isAssignableFrom(stateDataType.getConversionClass()) | ||
| || MapView.class.isAssignableFrom( | ||
| stateDataType.getConversionClass()) | ||
| ? stateDataType.getChildren().get(0) |
There was a problem hiding this comment.
Woundn't this just return the key type for MapView?
| 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).
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)