ueshin commented on code in PR #43791:
URL: https://github.com/apache/spark/pull/43791#discussion_r1401347054


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PythonDataSourceWrites.scala:
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources
+
+import java.io.{DataInputStream, DataOutputStream}
+
+import net.razorvine.pickle.Pickler
+
+import org.apache.spark.api.python.{PythonEvalType, PythonFunction, 
PythonWorkerUtils, SimplePythonFunction, SpecialLengths}
+import org.apache.spark.sql.SaveMode
+import org.apache.spark.sql.catalyst.expressions.{PredicateHelper, PythonUDF}
+import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, 
PythonMapInArrow}
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.catalyst.types.DataTypeUtils.toAttributes
+import org.apache.spark.sql.errors.QueryCompilationErrors
+import org.apache.spark.sql.execution.python.PythonPlannerRunner
+import org.apache.spark.sql.types.{BinaryType, StructField, StructType}
+
+
+/**
+ * A rule that constructs logical writes for Python data sources.
+ */
+object PythonDataSourceWrites extends Rule[LogicalPlan] with PredicateHelper {
+  override def apply(plan: LogicalPlan): LogicalPlan = plan transformDown {
+    case c @ SaveIntoPythonDataSourceCommand(
+        query, dataSourceCls, provider, options, mode, false) =>
+
+      // Start a Python process and create an instance of the Python data 
source writer.
+      // Return back a serialized Python function that's used to write data 
into the data source.
+      val runner = new SaveIntoPythonDataSourceRunner(
+        dataSourceCls, provider, options, mode, query)
+      val result = runner.runInPython()
+
+      // Construct the Python UDF.
+      val func = SimplePythonFunction(
+        command = result.func,
+        envVars = dataSourceCls.envVars,
+        pythonIncludes = dataSourceCls.pythonIncludes,
+        pythonExec = dataSourceCls.pythonExec,
+        pythonVer = dataSourceCls.pythonVer,
+        broadcastVars = dataSourceCls.broadcastVars,
+        accumulator = dataSourceCls.accumulator)
+
+      val dataType = StructType(Array(StructField("message", BinaryType)))
+
+      val pythonUDF = PythonUDF(
+        name = "save_into_data_source",
+        func = func,
+        dataType = dataType,
+        children = query.output,
+        evalType = PythonEvalType.SQL_MAP_ARROW_ITER_UDF,
+        udfDeterministic = true)  // TODO(SPARK-45930): support 
non-deterministic udf

Review Comment:
   nit: The issue `SPARK-45930` seems to be resolved?



-- 
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