<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=TransformWithState</id>
	<title>TransformWithState - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=TransformWithState"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=TransformWithState&amp;action=history"/>
	<updated>2026-12-06T00:07:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=TransformWithState&amp;diff=107&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@f2492a3</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=TransformWithState&amp;diff=107&amp;oldid=prev"/>
		<updated>2026-11-23T00:34:55Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@f2492a3&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:transformWithState}}&lt;br /&gt;
{{Infobox concept&lt;br /&gt;
| name            = transformWithState&lt;br /&gt;
| also_known_as   = Arbitrary State API v2, TWS&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Stateful processor, state variables (value, list, map), timers, TTL, time mode, output mode, optional initial state&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]] 4.0 and later (Scala, Java, Python)&lt;br /&gt;
| related         = [[mapGroupsWithState and flatMapGroupsWithState]], [[Watermark]], [[State store]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-22|the v4.0.0, v4.1.0 and v4.3.0 tags of apache/spark (KeyValueGroupedDataset.scala, StatefulProcessor.scala, TransformWithStateExecBase.scala, python/pyspark/sql/pandas/group_ops.py, python/pyspark/sql/connect/group.py, docs/streaming/structured-streaming-transform-with-state.md), the Spark 4.0.0, 4.1.0, 4.2.0 and 4.3.0 release notes, and SPARK-46815, SPARK-50770, SPARK-50855, SPARK-50856, SPARK-51814 and SPARK-51827}}&lt;br /&gt;
{{Status|active |since=Apache Spark 4.0.0 |note=The current operator for arbitrary stateful processing in Structured Streaming. Its public interfaces (&amp;lt;code&amp;gt;StatefulProcessor&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TimeMode&amp;lt;/code&amp;gt;) carry the &amp;lt;code&amp;gt;@Evolving&amp;lt;/code&amp;gt; annotation at v4.3.0, not &amp;lt;code&amp;gt;@Experimental&amp;lt;/code&amp;gt;. |ref=&amp;lt;ref name=&amp;quot;jira46815&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-46815 |title=SPARK-46815: Structured Streaming - Arbitrary State API v2 |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
In [[Structured Streaming]], &amp;#039;&amp;#039;&amp;#039;transformWithState&amp;#039;&amp;#039;&amp;#039; is the operator for arbitrary stateful processing: user code, written as a stateful processor class, receives the rows for each grouping key, keeps any number of typed state variables for that key across micro-batches, registers timers and emits zero or more output rows.&amp;lt;ref name=&amp;quot;guide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/structured-streaming-transform-with-state.html |title=Structured Streaming Programming Guide: transformWithState (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; It was added in [[Apache Spark]] 4.0.0 as the &amp;quot;Arbitrary State API v2&amp;quot;.&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; The Spark documentation calls it the next-generation replacement for [[mapGroupsWithState and flatMapGroupsWithState]] in Scala and Java and for &amp;lt;code&amp;gt;applyInPandasWithState&amp;lt;/code&amp;gt; in Python; those older operators are still supported and are not deprecated.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What transformWithState is for ==&lt;br /&gt;
Built-in stateful operators such as streaming aggregation, deduplication and stream-stream joins cover common patterns, and Spark manages their state. Some logic does not fit them: sessionization with custom rules, downtime detection, fraud scoring over a user&amp;#039;s history, or emitting an alert when nothing has arrived for a key. For these, Structured Streaming offers arbitrary stateful operators, where user code decides what to store, when to emit and when to forget.&amp;lt;ref name=&amp;quot;ssguide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html |title=Structured Streaming Programming Guide: APIs on DataFrames and Datasets (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; transformWithState is the second generation of that API. The guide says that since Spark 4.0 users are encouraged to build complex stateful applications on it rather than on the older operators.&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How it works ==&lt;br /&gt;
A query groups a streaming Dataset or DataFrame by key and passes a &amp;#039;&amp;#039;&amp;#039;stateful processor&amp;#039;&amp;#039;&amp;#039; to &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt;. The processor is a class that extends &amp;lt;code&amp;gt;StatefulProcessor&amp;lt;/code&amp;gt; and implements these methods:&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sp&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/streaming/StatefulProcessor.scala |title=StatefulProcessor.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt;, called once to declare state variables through the processor&amp;#039;s handle.&lt;br /&gt;
* &amp;lt;code&amp;gt;handleInputRows&amp;lt;/code&amp;gt;, called with the key and an iterator of that key&amp;#039;s new rows; it returns output rows.&lt;br /&gt;
* &amp;lt;code&amp;gt;handleExpiredTimer&amp;lt;/code&amp;gt;, called once for each timer that has fired; by default it returns nothing.&lt;br /&gt;
* &amp;lt;code&amp;gt;handleInitialState&amp;lt;/code&amp;gt;, available on &amp;lt;code&amp;gt;StatefulProcessorWithInitialState&amp;lt;/code&amp;gt;, called once per key of an optional initial-state DataFrame before any input is processed.&lt;br /&gt;
* &amp;lt;code&amp;gt;close&amp;lt;/code&amp;gt;, for cleanup.&lt;br /&gt;
&lt;br /&gt;
=== State variables ===&lt;br /&gt;
State is declared as named variables, not as a single object per key. There are three types: &amp;#039;&amp;#039;&amp;#039;ValueState&amp;#039;&amp;#039;&amp;#039; (one value), &amp;#039;&amp;#039;&amp;#039;ListState&amp;#039;&amp;#039;&amp;#039; (appends are cheap) and &amp;#039;&amp;#039;&amp;#039;MapState&amp;#039;&amp;#039;&amp;#039; (point lookups by a user key are cheap). A processor can declare several of each, and each has its own encoder.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt; Variables can be added between runs of the same query, and removed with &amp;lt;code&amp;gt;deleteIfExists&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt;. With the Avro state encoding (&amp;lt;code&amp;gt;spark.sql.streaming.stateStore.encodingFormat&amp;lt;/code&amp;gt; set to &amp;lt;code&amp;gt;avro&amp;lt;/code&amp;gt;), the schema of a variable&amp;#039;s value can evolve by adding, removing, reordering or widening fields.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Timers and TTL ===&lt;br /&gt;
The time mode is chosen per query: &amp;lt;code&amp;gt;TimeMode.None()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TimeMode.ProcessingTime()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;TimeMode.EventTime()&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;timemode&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/java/org/apache/spark/sql/streaming/TimeMode.java |title=TimeMode.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; In processing-time or event-time mode, the processor can register, list and delete any number of timers per key; timers are checkpointed and can fire after a restart.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt; In event-time mode, timers fire as the [[watermark]] passes them.&lt;br /&gt;
&lt;br /&gt;
Each state variable can have a time-to-live (TTL) through &amp;lt;code&amp;gt;TTLConfig&amp;lt;/code&amp;gt;. Values are not returned after the TTL has passed and are eventually removed; every update resets the TTL. TTL works only with &amp;lt;code&amp;gt;TimeMode.ProcessingTime&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/streaming/TTLConfig.scala |title=TTLConfig.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== State store requirement ===&lt;br /&gt;
transformWithState runs only on the RocksDB [[state store]]. In a streaming query, the operator checks &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.providerClass&amp;lt;/code&amp;gt; and fails with the error &amp;lt;code&amp;gt;STORE_BACKEND_NOT_SUPPORTED_FOR_TWS&amp;lt;/code&amp;gt; unless it is &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;base&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/TransformWithStateExecBase.scala |title=TransformWithStateExecBase.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; The default provider in Spark 4.3.0 is still the HDFS-backed state store, so the setting must be changed before the query first starts; the provider cannot be changed between restarts of a query.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0), spark.sql.streaming.stateStore.providerClass |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; The operator stores its several variables as column families in one RocksDB instance.&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debugging and testing ===&lt;br /&gt;
The state data source can read a transformWithState query&amp;#039;s state one variable at a time (option &amp;lt;code&amp;gt;stateVarName&amp;lt;/code&amp;gt;) and list registered timers (option &amp;lt;code&amp;gt;readRegisteredTimers&amp;lt;/code&amp;gt;). &amp;lt;code&amp;gt;TwsTester&amp;lt;/code&amp;gt;, in Scala and Python, runs a stateful processor without a streaming query for unit tests; it does not model TTL or automatic watermark advancement.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Language and Spark Connect support ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! API !! Language !! Data passed to the processor !! Added in !! Spark Connect support&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;KeyValueGroupedDataset.transformWithState&amp;lt;/code&amp;gt; || Scala, Java || Typed objects (encoders) || 4.0.0&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira50770&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-50770 |title=SPARK-50770: Removing package scope for transformWithState operator APIs |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; || 4.1.0&amp;lt;ref name=&amp;quot;jira50855&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-50855 |title=SPARK-50855: Spark Connect Support for TransformWithState In Scala |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;GroupedData.transformWithStateInPandas&amp;lt;/code&amp;gt; || Python || pandas DataFrames || 4.0.0&amp;lt;ref name=&amp;quot;groupops&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/pandas/group_ops.py |title=group_ops.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; || 4.1.0&amp;lt;ref name=&amp;quot;jira50856&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-50856 |title=SPARK-50856: Spark Connect Support for TransformWithStateInPandas In Python |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;GroupedData.transformWithState&amp;lt;/code&amp;gt; || Python || &amp;lt;code&amp;gt;Row&amp;lt;/code&amp;gt; objects || 4.1.0&amp;lt;ref name=&amp;quot;jira51814&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-51814 |title=SPARK-51814: Introduce a new API transformWithState in PySpark |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; || 4.1.0&amp;lt;ref name=&amp;quot;jira51827&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-51827 |title=SPARK-51827: Support Spark Connect in new API transformWithState in PySpark |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In Spark 4.0.0 the [[Spark Connect]] Scala client declared &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; but threw &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt;, and the Python Connect client had no &amp;lt;code&amp;gt;transformWithStateInPandas&amp;lt;/code&amp;gt;; both work over Connect from 4.1.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.0.0/sql/connect/common/src/main/scala/org/apache/spark/sql/connect/KeyValueGroupedDataset.scala |title=connect/KeyValueGroupedDataset.scala (v4.0.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; The guide suggests the pandas variant for most Python users and the Row variant for high key cardinality, where conversion to pandas costs more.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From Spark 4.3.0 the Scala and Java API can run with the real-time trigger (SPARK-57228); the two Python APIs are not supported in Real-time Mode.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; transformWithState also runs in batch queries (SPARK-46865 for Scala, SPARK-50428 for Python).&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison with mapGroupsWithState ==&lt;br /&gt;
{{Main|mapGroupsWithState and flatMapGroupsWithState}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! transformWithState !! mapGroupsWithState / flatMapGroupsWithState&lt;br /&gt;
|-&lt;br /&gt;
! Added in&lt;br /&gt;
| Spark 4.0.0&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 2.2.0&amp;lt;ref name=&amp;quot;r220&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-2-2-0.html |title=Spark Release 2.2.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! User code&lt;br /&gt;
| A class with &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;handleInputRows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;handleExpiredTimer&amp;lt;/code&amp;gt; and other methods&amp;lt;ref name=&amp;quot;sp&amp;quot; /&amp;gt;&lt;br /&gt;
| One function of key, values and a &amp;lt;code&amp;gt;GroupState&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;gs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/streaming/GroupState.scala |title=GroupState.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State per key&lt;br /&gt;
| Any number of named value, list and map variables&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| One state object&amp;lt;ref name=&amp;quot;gs&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Timers&lt;br /&gt;
| Many timers per key, listed and deleted by the processor&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| One timeout per key&amp;lt;ref name=&amp;quot;gs&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Automatic expiry&lt;br /&gt;
| TTL per state variable (processing time)&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| None; the function removes state itself, usually on timeout&lt;br /&gt;
|-&lt;br /&gt;
! State schema evolution&lt;br /&gt;
| Supported for values with Avro encoding&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| Not offered&lt;br /&gt;
|-&lt;br /&gt;
! State store&lt;br /&gt;
| RocksDB only&amp;lt;ref name=&amp;quot;base&amp;quot; /&amp;gt;&lt;br /&gt;
| HDFS-backed (default) or RocksDB&lt;br /&gt;
|-&lt;br /&gt;
! Python API&lt;br /&gt;
| &amp;lt;code&amp;gt;transformWithStateInPandas&amp;lt;/code&amp;gt; (4.0.0), &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; (4.1.0)&amp;lt;ref name=&amp;quot;groupops&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;applyInPandasWithState&amp;lt;/code&amp;gt; (3.4.0)&amp;lt;ref name=&amp;quot;groupops&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Deprecated?&lt;br /&gt;
| No&lt;br /&gt;
| No; see [[mapGroupsWithState and flatMapGroupsWithState]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
A running count per word in Scala, for Spark 4.0 or later. &amp;lt;code&amp;gt;words&amp;lt;/code&amp;gt; is a streaming &amp;lt;code&amp;gt;Dataset[String]&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.implicits._&amp;lt;/code&amp;gt; is imported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;scala&amp;quot;&amp;gt;&lt;br /&gt;
import org.apache.spark.sql.Encoders&lt;br /&gt;
import org.apache.spark.sql.streaming._&lt;br /&gt;
&lt;br /&gt;
class RunningCount extends StatefulProcessor[String, String, (String, Long)] {&lt;br /&gt;
  @transient private var count: ValueState[Long] = _&lt;br /&gt;
&lt;br /&gt;
  override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = {&lt;br /&gt;
    count = getHandle.getValueState[Long](&amp;quot;count&amp;quot;, Encoders.scalaLong, TTLConfig.NONE)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  override def handleInputRows(&lt;br /&gt;
      key: String,&lt;br /&gt;
      rows: Iterator[String],&lt;br /&gt;
      timerValues: TimerValues): Iterator[(String, Long)] = {&lt;br /&gt;
    val updated = (if (count.exists()) count.get() else 0L) + rows.size&lt;br /&gt;
    count.update(updated)&lt;br /&gt;
    Iterator((key, updated))&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
spark.conf.set(&amp;quot;spark.sql.streaming.stateStore.providerClass&amp;quot;,&lt;br /&gt;
  &amp;quot;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
val counts = words&lt;br /&gt;
  .groupByKey(identity)&lt;br /&gt;
  .transformWithState(new RunningCount, TimeMode.None(), OutputMode.Update())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[mapGroupsWithState and flatMapGroupsWithState]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>