trait TestGroupState[S] extends GroupState[S]
:: Experimental ::
The extended version of GroupState interface with extra getters of state machine fields to improve testability of the GroupState implementations which inherit from the extended interface.
Scala example of using TestGroupState
:
// Please refer to ScalaDoc of `GroupState` for the Scala definition of `mappingFunction()` import org.apache.spark.api.java.Optional import org.apache.spark.sql.streaming.GroupStateTimeout import org.apache.spark.sql.streaming.TestGroupState // other imports // test class setups test("MapGroupsWithState state transition function") { // Creates the prevState input for the state transition function // with desired configs. The `create()` API would guarantee that // the generated instance has the same behavior as the one built by // engine with the same configs. val prevState = TestGroupState.create[Int]( optionalState = Optional.empty[Int], timeoutConf = NoTimeout, batchProcessingTimeMs = 1L, eventTimeWatermarkMs = Optional.of(1L), hasTimedOut = false) val key: String = ... val values: Iterator[Int] = ... // Asserts the prevState is in init state without updates. assert(!prevState.isUpdated) // Calls the state transition function with the test previous state // with desired configs. mappingFunction(key, values, prevState) // Asserts the test GroupState object has been updated but not removed // after calling the state transition function assert(prevState.isUpdated) assert(!prevState.isRemoved) }
Java example of using TestGroupSate
:
// Please refer to ScalaDoc of `GroupState` for the Java definition of `mappingFunction()` import org.apache.spark.api.java.Optional; import org.apache.spark.sql.streaming.GroupStateTimeout; import org.apache.spark.sql.streaming.TestGroupState; // other imports // test class setups // test `MapGroupsWithState` state transition function `mappingFunction()` public void testMappingFunctionWithTestGroupState() { // Creates the prevState input for the state transition function // with desired configs. The `create()` API would guarantee that // the generated instance has the same behavior as the one built by // engine with the same configs. TestGroupState<Int> prevState = TestGroupState.create( Optional.empty(), GroupStateTimeout.NoTimeout(), 1L, Optional.of(1L), false); String key = ...; Integer[] values = ...; // Asserts the prevState is in init state without updates. Assert.assertFalse(prevState.isUpdated()); // Calls the state transition function with the test previous state // with desired configs. mappingFunction.call(key, Arrays.asList(values).iterator(), prevState); // Asserts the test GroupState object has been updated but not removed // after calling the state transition function Assert.assertTrue(prevState.isUpdated()); Assert.assertFalse(prevState.isRemoved()); }
- S
User-defined type of the state to be stored for each group. Must be encodable into Spark SQL types (see
Encoder
for more details).
- Annotations
- @Experimental() @Evolving()
- Since
3.2.0
- Alphabetic
- By Inheritance
- TestGroupState
- GroupState
- LogicalGroupState
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def exists: Boolean
- Definition Classes
- GroupState
- abstract def get: S
- Definition Classes
- GroupState
- Annotations
- @throws("when state does not exist")
- abstract def getCurrentProcessingTimeMs(): Long
- Definition Classes
- GroupState
- abstract def getCurrentWatermarkMs(): Long
- Definition Classes
- GroupState
- Annotations
- @throws("if watermark has not been set before in [map|flatMap]GroupsWithState")
- abstract def getOption: Option[S]
- Definition Classes
- GroupState
- abstract def getTimeoutTimestampMs: Optional[Long]
Returns the timestamp if
setTimeoutTimestamp()
is called.Returns the timestamp if
setTimeoutTimestamp()
is called. Or, returns batch processing time + the duration whensetTimeoutDuration()
is called.Otherwise, returns
Optional.empty
if not set. - abstract def hasTimedOut: Boolean
- Definition Classes
- GroupState
- abstract def isRemoved: Boolean
Whether the state has been marked for removing
- abstract def isUpdated: Boolean
Whether the state has been updated but not removed
- abstract def remove(): Unit
- Definition Classes
- GroupState
- abstract def setTimeoutDuration(duration: String): Unit
- Definition Classes
- GroupState
- Annotations
- @throws("if \'duration\' is not a valid duration") @throws("if processing time timeout has not been enabled in [map|flatMap]GroupsWithState")
- abstract def setTimeoutDuration(durationMs: Long): Unit
- Definition Classes
- GroupState
- Annotations
- @throws("if \'durationMs\' is not positive") @throws("if processing time timeout has not been enabled in [map|flatMap]GroupsWithState")
- abstract def setTimeoutTimestamp(timestamp: Date, additionalDuration: String): Unit
- Definition Classes
- GroupState
- Annotations
- @throws("if \'additionalDuration\' is invalid") @throws("if event time timeout has not been enabled in [map|flatMap]GroupsWithState")
- abstract def setTimeoutTimestamp(timestamp: Date): Unit
- Definition Classes
- GroupState
- Annotations
- @throws("if event time timeout has not been enabled in [map|flatMap]GroupsWithState")
- abstract def setTimeoutTimestamp(timestampMs: Long, additionalDuration: String): Unit
- Definition Classes
- GroupState
- Annotations
- @throws("if \'additionalDuration\' is invalid or the final timeout timestamp is less than the current watermark in a streaming query") @throws("if event time timeout has not been enabled in [map|flatMap]GroupsWithState")
- abstract def setTimeoutTimestamp(timestampMs: Long): Unit
- Definition Classes
- GroupState
- Annotations
- @throws("if \'timestampMs\' is not positive or less than the current watermark in a streaming query") @throws("if event time timeout has not been enabled in [map|flatMap]GroupsWithState")
- abstract def update(newState: S): Unit
- Definition Classes
- GroupState
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()