You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "rangadi (via GitHub)" <gi...@apache.org> on 2023/06/08 23:28:53 UTC
[GitHub] [spark] rangadi commented on a diff in pull request #41129: [SPARK-43133] Scala Client DataStreamWriter Foreach support
rangadi commented on code in PR #41129:
URL: https://github.com/apache/spark/pull/41129#discussion_r1223638394
##########
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:
Is this case possible yet un this PR? Which unit test would trigger it (may be `"forEach Int"`)?
##########
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:
What is TODO about? There are no details. The ticket just links back to this comment. Can we have the issue described here?
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org