ericm-db commented on code in PR #49277: URL: https://github.com/apache/spark/pull/49277#discussion_r1917893390
########## sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithMapStateSuite.scala: ########## @@ -76,12 +76,71 @@ class TestMapStateProcessor } } +// Case classes for schema evolution testing +case class SimpleMapValue(count: Int) +case class EvolvedMapValue(count: Int, lastUpdated: Option[Long]) + +// Initial processor with simple schema +class InitialMapStateProcessor extends StatefulProcessor[String, String, (String, String, Int)] { + @transient protected var mapState: MapState[String, SimpleMapValue] = _ + + override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = { + mapState = getHandle.getMapState[String, SimpleMapValue]( + "mapState", + Encoders.STRING, + Encoders.product[SimpleMapValue], + TTLConfig.NONE + ) + } + + override def handleInputRows( + key: String, + rows: Iterator[String], + timerValues: TimerValues): Iterator[(String, String, Int)] = { + + rows.map { value => + val current = mapState.getValue(value) + val newCount = if (current == null) 1 else current.count + 1 + mapState.updateValue(value, SimpleMapValue(newCount)) + (key, value, newCount) + } + } +} + +// Evolved processor with additional timestamp field +class EvolvedMapStateProcessor extends StatefulProcessor[String, String, (String, String, Int)] { + @transient protected var mapState: MapState[String, EvolvedMapValue] = _ + + override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = { + mapState = getHandle.getMapState[String, EvolvedMapValue]( + "mapState", + Encoders.STRING, + Encoders.product[EvolvedMapValue], + TTLConfig.NONE + ) + } + + override def handleInputRows( + key: String, + rows: Iterator[String], + timerValues: TimerValues): Iterator[(String, String, Int)] = { + + rows.map { value => + val current = mapState.getValue(value) + val newCount = if (current == null) 1 else current.count + 1 + mapState.updateValue(value, EvolvedMapValue(newCount, Some(System.currentTimeMillis()))) + (key, value, newCount) Review Comment: Yeah I think this is covered in other tests - namely the add fields test cases -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org