anishshri-db commented on code in PR #45467:
URL: https://github.com/apache/spark/pull/45467#discussion_r1530882509


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -271,57 +340,122 @@ case class TransformWithStateExec(
       case _ =>
     }
 
-    if (isStreaming) {
-      child.execute().mapPartitionsWithStateStore[InternalRow](
-        getStateInfo,
-        schemaForKeyRow,
-        schemaForValueRow,
-        numColsPrefixKey = 0,
-        session.sqlContext.sessionState,
-        Some(session.sqlContext.streams.stateStoreCoordinator),
-        useColumnFamilies = true,
-        useMultipleValuesPerKey = true
-      ) {
-        case (store: StateStore, singleIterator: Iterator[InternalRow]) =>
-          processData(store, singleIterator)
+    if (hasInitialState) {
+      if (isStreaming) {
+        val storeConf = new 
StateStoreConf(session.sqlContext.sessionState.conf)
+        val hadoopConfBroadcast = sparkContext.broadcast(
+          new 
SerializableConfiguration(session.sqlContext.sessionState.newHadoopConf()))
+        child.execute().stateStoreAwareZipPartitions(
+          initialState.execute(),
+          getStateInfo,
+          storeNames = Seq(),
+          session.sqlContext.streams.stateStoreCoordinator) {
+          // The state store aware zip partitions will provide us with two 
iterators,
+          // child data iterator and the initial state iterator per partition.
+          case (partitionId, childDataIterator, initStateIterator) =>
+            val stateStoreId = StateStoreId(stateInfo.get.checkpointLocation,
+              stateInfo.get.operatorId, partitionId)
+            val storeProviderId = StateStoreProviderId(stateStoreId, 
stateInfo.get.queryRunId)
+            val store = StateStore.get(
+              storeProviderId,
+              schemaForKeyRow,
+              schemaForValueRow,
+              0,
+              stateInfo.get.storeVersion,
+              useColumnFamilies = true,
+              storeConf, hadoopConfBroadcast.value.value
+            )
+
+            processDataWithInitialState(store, childDataIterator, 
initStateIterator)
+        }
+      } else {
+        // If the query is running in batch mode, we need to create a new 
StateStore and instantiate
+        // a temp directory on the executors in zipPartitionsWithIndex.
+        val broadcastedHadoopConf =
+          new SerializableConfiguration(session.sessionState.newHadoopConf())
+        child.execute().zipPartitionsWithIndex(
+          initialState.execute()

Review Comment:
   nit: move to line above ? same for 1 line below 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to