WweiL commented on code in PR #41129:
URL: https://github.com/apache/spark/pull/41129#discussion_r1223658042
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/streaming/DataStreamWriter.scala:
##########
@@ -202,6 +208,28 @@ final class DataStreamWriter[T] private[sql] (ds:
Dataset[T]) extends Logging {
this
}
+ /**
+ * Sets the output of the streaming query to be processed using the provided
writer object.
+ * object. See [[org.apache.spark.sql.ForeachWriter]] for more details on
the lifecycle and
+ * semantics.
+ * @since 3.5.0
+ */
+ def foreach(writer: ForeachWriter[T]): DataStreamWriter[T] = {
+ // ds.encoder equal to UnboundRowEncoder means type parameter T is Row,
+ // which is not able to be serialized. Server will detect this and use
default encoder.
+ val rowEncoder = if (ds.encoder != UnboundRowEncoder) {
Review Comment:
The action item is item 1 in Zhen's approval note:
https://github.com/apache/spark/pull/41129#pullrequestreview-1463092531
`UnboundRowEncoder` needs special care here which is not very ideal and they
want to update
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -2445,10 +2451,24 @@ class SparkConnectPlanner(val session: SparkSession) {
}
if (writeOp.hasForeachWriter) {
- val foreach = writeOp.getForeachWriter.getPythonWriter
- val pythonFcn = transformPythonFunction(foreach)
- writer.foreachImplementation(
- new PythonForeachWriter(pythonFcn,
dataset.schema).asInstanceOf[ForeachWriter[Any]])
+ if (writeOp.getForeachWriter.hasPythonWriter) {
+ val foreach = writeOp.getForeachWriter.getPythonWriter
+ val pythonFcn = transformPythonFunction(foreach)
+ writer.foreachImplementation(
+ new PythonForeachWriter(pythonFcn,
dataset.schema).asInstanceOf[ForeachWriter[Any]])
+ } else {
+ val foreachWriterPkt =
unpackForeachWriter(writeOp.getForeachWriter.getScalaWriter)
+ val clientWriter = foreachWriterPkt.foreachWriter
+ if (foreachWriterPkt.datasetEncoder == null) {
+ // datasetEncoder is null means the client-side writer has type
parameter Row,
+ // Since server-side dataset is always dataframe, here just use
foreach directly.
+ writer.foreach(clientWriter.asInstanceOf[ForeachWriter[Row]])
+ } else {
+ val encoder = ExpressionEncoder(
Review Comment:
Yes
--
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]