WweiL commented on code in PR #41558:
URL: https://github.com/apache/spark/pull/41558#discussion_r1231370155
##########
connector/connect/common/src/main/protobuf/spark/connect/relations.proto:
##########
@@ -858,6 +857,21 @@ message GroupMap {
// (Optional) Expressions for sorting. Only used by Scala Sorted Group Map
API.
repeated Expression sorting_expressions = 4;
+
+ // (Optional) Input relation for initial State.
+ Relation initial_input = 5;
Review Comment:
Seems these fields are only used in (flat)mapGroupsWithState, could we add
comment above?
##########
connector/connect/common/src/main/scala/org/apache/spark/sql/connect/common/UdfUtils.scala:
##########
@@ -97,22 +97,27 @@ private[sql] object UdfUtils extends Serializable {
}
def mapValuesAdaptor[K, V, S, U, IV](
- f: (K, Iterator[V], GroupState[S]) => U,
- valueMapFunc: IV => V): (K, Iterator[IV], GroupState[S]) => U = {
- (k: K, itr: Iterator[IV], s: GroupState[S]) =>
- {
+ f: (K, Iterator[V], GroupState[S]) => Iterator[U],
+ valueMapFunc: IV => V): (K, Iterator[IV], GroupState[S]) => Iterator[U]
= {
+ print("Used function: mapValuesAdaptor")
Review Comment:
I think we should delete this
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/KeyValueGroupedDataset.scala:
##########
@@ -462,6 +462,15 @@ abstract class KeyValueGroupedDataset[K, V] private[sql]
() extends Serializable
UdfUtils.coGroupFunctionToScalaFunc(f))(encoder)
}
+ protected def flatMapGroupsWithStateHelper[S: Encoder, U: Encoder](
+ outputMode: OutputMode,
+ timeoutConf: GroupStateTimeout,
+ initialState: KeyValueGroupedDataset[K, S],
Review Comment:
I feel this helper method shouldn't appear there. Is this change because of
this comment? https://github.com/apache/spark/pull/41558#discussion_r1227337649
I actually think it's good to use the original implementation, i.e. have a
dedicated `flatMapGroupsWithState` and `mapGroupsWIthState` that handles all
cases respectively, this also follows the original API design:
https://github.com/apache/spark/blob/28869401eff8fcd94aa68d662fdd4d3dbe2f58af/sql/core/src/main/scala/org/apache/spark/sql/KeyValueGroupedDataset.scala
But we could also just use an ultimate `flatMapGroupsWithState` that
achieves the same goal as @zhenlineo suggested and still delete this helper
method.
@zhenlineo @bogao007 wdyt?
--
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]