tdas commented on a change in pull request #33336:
URL: https://github.com/apache/spark/pull/33336#discussion_r673534407
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/FlatMapGroupsWithStateExec.scala
##########
@@ -404,3 +402,70 @@ case class FlatMapGroupsWithStateExec(
copy(child = newLeft, initialState = newRight)
}
+object FlatMapGroupsWithStateExec {
+
+ def foundDuplicateInitialKeyException(): Exception = {
+ throw new IllegalArgumentException("The initial state provided contained "
+
+ "multiple rows(state) with the same key. Make sure to de-duplicate the "
+
+ "initial state before passing it.")
+ }
+
+ /**
+ * Plan logical flatmapGroupsWIthState for batch queries
+ * If the initial state is provided, we create an instance of the
CoGroupExec, if the initial
+ * state is not provided we create an instance of the MapGroupsExec
+ */
+ // scalastyle:off argcount
+ def generateSparkPlanForBatchQueries(
+ userFunc: (Any, Iterator[Any], LogicalGroupState[Any]) => Iterator[Any],
+ keyDeserializer: Expression,
+ valueDeserializer: Expression,
+ initialStateDeserializer: Expression,
+ groupingAttributes: Seq[Attribute],
+ initialStateGroupAttrs: Seq[Attribute],
+ dataAttributes: Seq[Attribute],
+ initialStateDataAttrs: Seq[Attribute],
+ outputObjAttr: Attribute,
+ timeoutConf: GroupStateTimeout,
+ hasInitialState: Boolean,
+ initialState: SparkPlan,
+ child: SparkPlan): SparkPlan = {
+ if (hasInitialState) {
+ val watermarkPresent = child.output.exists {
+ case a: Attribute if a.metadata.contains(EventTimeWatermark.delayKey)
=> true
+ case _ => false
+ }
+ val func = (keyRow: Any, values: Iterator[Any], states: Iterator[Any])
=> {
+ // Check if there is only one state for every key.
+ var foundInitialStateForKey = false
+ val optionalState = states.map { stateValue =>
+ if (foundInitialStateForKey) {
+ foundDuplicateInitialKeyException()
Review comment:
does this bug exist for streaming as well?
--
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]