Class ProcessTableFunctionTestHarness<OUT>
java.lang.Object
org.apache.flink.table.runtime.functions.ProcessTableFunctionTestHarness<OUT>
- All Implemented Interfaces:
AutoCloseable
@PublicEvolving
public class ProcessTableFunctionTestHarness<OUT>
extends Object
implements AutoCloseable
Test harness for
ProcessTableFunction.
Provides a fluent builder API for configuring and testing ProcessTableFunctions (PTFs) with table and scalar arguments, lifecycle management, and output collection.
Example usage:
ProcessTableFunctionTestHarness<Row> harness =
ProcessTableFunctionTestHarness.ofClass(MyPTF.class)
.withTableArgument("input", DataTypes.of("ROW<id INT, name STRING>"))
.withScalarArgument("threshold", 100)
.build();
harness.processElement(Row.of(1, "Alice"));
harness.processElement(Row.of(2, "Bob"));
List<Row> output = harness.getOutput();
List<Row> functionOutput = harness.getFunctionOutput();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidclearAllStatesForKey(Row partitionKey) Clear all state for a given partition key.voidClears the fired timer history.voidClears all collected output.voidclearStateForKey(String stateName, Row partitionKey) Clear specific state entry for a given partition key.voidclose()Returns all timers (both pending and fired), sorted by timestamp then name.getAllTimers(Row partitionKey) Returns all timers (both pending and fired) for the given partition key.Returns all timers that have fired, in the order they fired.getFiredTimers(String timerName) Returns all fired timers with the given name.getFiredTimers(Row partitionKey) Returns all fired timers for the given partition key.Returns the collected output as values collected by the PTF, typed as its declared output.getKeysForState(String stateName) Get all partition keys that have a specific state entry.Returns the collected output as full rows: atomic output wrapped into anEXPR$0column or structured output flattened into its attributes, with additional columns (partition keys, rowtime, etc.) prepended or appended as configured.Returns all pending (not yet fired) timers, sorted by timestamp then name.getPendingTimers(String timerName) Returns all pending timers with the given name.getPendingTimers(Row partitionKey) Returns all pending timers for the given partition key.getStateForAllKeys(String stateName) Get all state values for a state name across all partition keys.<T> TgetStateForKey(String stateName, Row partitionKey) Get state for a specific partition key.static <OUT> ProcessTableFunctionTestHarness.Builder<OUT>ofClass(Class<? extends ProcessTableFunction<OUT>> functionClass) Creates a new harness builder for the given ProcessTableFunction class.voidprocess()Processes the PTF's eval() method with scalar arguments only.voidprocessElement(Object... values) Process a single element constructed from values.voidprocessElement(Row row) Process a single element for the default table argument.voidprocessElement(RowKind rowKind, Object... values) Process a single element with a specific RowKind.voidprocessElementForTable(String tableArgument, Object... values) Process a single element for a specific table argument.voidprocessElementForTable(String tableArgument, Row row) Process a single element for a specific table argument.voidprocessElementForTable(String tableArgument, RowKind rowKind, Object... values) Process a single element for a specific table argument with RowKind.voidsetStateForKey(String stateName, Row partitionKey, Object state) Set state for a specific partition key.voidsetWatermark(Instant watermark) Sets the watermark for all tables to the givenInstantand fires eligible timers.voidsetWatermark(LocalDateTime watermark) Sets the watermark for all tables to the givenLocalDateTimeand fires eligible timers.voidsetWatermarkForTable(String tableArgument, Instant watermark) Sets the watermark for a specific table.voidsetWatermarkForTable(String tableArgument, LocalDateTime watermark) Sets the watermark for a specific table.
-
Method Details
-
ofClass
public static <OUT> ProcessTableFunctionTestHarness.Builder<OUT> ofClass(Class<? extends ProcessTableFunction<OUT>> functionClass) Creates a new harness builder for the given ProcessTableFunction class. -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
processElement
Process a single element for the default table argument.For PTFs with a single table argument, this processes one row. For multiple table arguments, use
processElementForTable(String, Row).- Throws:
Exception
-
processElement
Process a single element constructed from values.- Throws:
Exception
-
processElement
Process a single element with a specific RowKind.- Throws:
Exception
-
processElementForTable
Process a single element for a specific table argument.- Throws:
Exception
-
processElementForTable
Process a single element for a specific table argument.- Throws:
Exception
-
processElementForTable
public void processElementForTable(String tableArgument, RowKind rowKind, Object... values) throws Exception Process a single element for a specific table argument with RowKind.- Throws:
Exception
-
process
Processes the PTF's eval() method with scalar arguments only.This method is specifically for scalar-only PTFs (PTFs with only scalar arguments and no table arguments). For PTFs that accept table arguments, use
processElement(Row)orprocessElementForTable(String, Row)instead.- Throws:
IllegalStateException- if the PTF has any table argumentsException- if the eval() invocation fails
-
getOutput
Returns the collected output as full rows: atomic output wrapped into anEXPR$0column or structured output flattened into its attributes, with additional columns (partition keys, rowtime, etc.) prepended or appended as configured. -
getFunctionOutput
Returns the collected output as values collected by the PTF, typed as its declared output. SeegetOutput()for the full row the runtime would emit, including those additional columns. -
clearOutput
public void clearOutput()Clears all collected output. -
getStateForKey
Get state for a specific partition key. -
setStateForKey
Set state for a specific partition key.- Throws:
Exception
-
getKeysForState
Get all partition keys that have a specific state entry. -
getStateForAllKeys
Get all state values for a state name across all partition keys. -
clearAllStatesForKey
Clear all state for a given partition key. -
clearStateForKey
Clear specific state entry for a given partition key. -
setWatermark
Sets the watermark for all tables to the givenLocalDateTimeand fires eligible timers.- Throws:
Exception
-
setWatermark
Sets the watermark for all tables to the givenInstantand fires eligible timers.- Throws:
Exception
-
setWatermarkForTable
Sets the watermark for a specific table. Fires eligible timers if this advances the global watermark (the minimum across all tables).- Throws:
Exception
-
setWatermarkForTable
Sets the watermark for a specific table. Fires eligible timers if this advances the global watermark (the minimum across all tables).- Throws:
Exception
-
getAllTimers
Returns all timers (both pending and fired), sorted by timestamp then name. -
getAllTimers
Returns all timers (both pending and fired) for the given partition key. -
getPendingTimers
Returns all pending (not yet fired) timers, sorted by timestamp then name. -
getPendingTimers
Returns all pending timers for the given partition key. -
getPendingTimers
Returns all pending timers with the given name. -
getFiredTimers
Returns all timers that have fired, in the order they fired. -
getFiredTimers
Returns all fired timers for the given partition key. -
getFiredTimers
Returns all fired timers with the given name. -
clearFiredTimers
public void clearFiredTimers()Clears the fired timer history.
-