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();
 
  • 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

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • processElement

      public void processElement(Row row) throws Exception
      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

      public void processElement(Object... values) throws Exception
      Process a single element constructed from values.
      Throws:
      Exception
    • processElement

      public void processElement(RowKind rowKind, Object... values) throws Exception
      Process a single element with a specific RowKind.
      Throws:
      Exception
    • processElementForTable

      public void processElementForTable(String tableArgument, Row row) throws Exception
      Process a single element for a specific table argument.
      Throws:
      Exception
    • processElementForTable

      public void processElementForTable(String tableArgument, Object... values) throws Exception
      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

      public void process() throws Exception
      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) or processElementForTable(String, Row) instead.

      Throws:
      IllegalStateException - if the PTF has any table arguments
      Exception - if the eval() invocation fails
    • getOutput

      public List<Row> getOutput()
      Returns the collected output as full rows: atomic output wrapped into an EXPR$0 column or structured output flattened into its attributes, with additional columns (partition keys, rowtime, etc.) prepended or appended as configured.
    • getFunctionOutput

      public List<OUT> getFunctionOutput()
      Returns the collected output as values collected by the PTF, typed as its declared output. See getOutput() for the full row the runtime would emit, including those additional columns.
    • clearOutput

      public void clearOutput()
      Clears all collected output.
    • getStateForKey

      public <T> T getStateForKey(String stateName, Row partitionKey)
      Get state for a specific partition key.
    • setStateForKey

      public void setStateForKey(String stateName, Row partitionKey, Object state) throws Exception
      Set state for a specific partition key.
      Throws:
      Exception
    • getKeysForState

      public Set<Row> getKeysForState(String stateName)
      Get all partition keys that have a specific state entry.
    • getStateForAllKeys

      public <T> Map<Row,T> getStateForAllKeys(String stateName)
      Get all state values for a state name across all partition keys.
    • clearAllStatesForKey

      public void clearAllStatesForKey(Row partitionKey)
      Clear all state for a given partition key.
    • clearStateForKey

      public void clearStateForKey(String stateName, Row partitionKey)
      Clear specific state entry for a given partition key.
    • setWatermark

      public void setWatermark(LocalDateTime watermark) throws Exception
      Sets the watermark for all tables to the given LocalDateTime and fires eligible timers.
      Throws:
      Exception
    • setWatermark

      public void setWatermark(Instant watermark) throws Exception
      Sets the watermark for all tables to the given Instant and fires eligible timers.
      Throws:
      Exception
    • setWatermarkForTable

      public void setWatermarkForTable(String tableArgument, LocalDateTime watermark) throws Exception
      Sets the watermark for a specific table. Fires eligible timers if this advances the global watermark (the minimum across all tables).
      Throws:
      Exception
    • setWatermarkForTable

      public void setWatermarkForTable(String tableArgument, Instant watermark) throws Exception
      Sets the watermark for a specific table. Fires eligible timers if this advances the global watermark (the minimum across all tables).
      Throws:
      Exception
    • getAllTimers

      public List<Timer> getAllTimers()
      Returns all timers (both pending and fired), sorted by timestamp then name.
    • getAllTimers

      public List<Timer> getAllTimers(Row partitionKey)
      Returns all timers (both pending and fired) for the given partition key.
    • getPendingTimers

      public List<Timer> getPendingTimers()
      Returns all pending (not yet fired) timers, sorted by timestamp then name.
    • getPendingTimers

      public List<Timer> getPendingTimers(Row partitionKey)
      Returns all pending timers for the given partition key.
    • getPendingTimers

      public List<Timer> getPendingTimers(String timerName)
      Returns all pending timers with the given name.
    • getFiredTimers

      public List<Timer> getFiredTimers()
      Returns all timers that have fired, in the order they fired.
    • getFiredTimers

      public List<Timer> getFiredTimers(Row partitionKey)
      Returns all fired timers for the given partition key.
    • getFiredTimers

      public List<Timer> getFiredTimers(String timerName)
      Returns all fired timers with the given name.
    • clearFiredTimers

      public void clearFiredTimers()
      Clears the fired timer history.