HyukjinKwon commented on a change in pull request #29806:
URL: https://github.com/apache/spark/pull/29806#discussion_r494009107



##########
File path: python/docs/source/user_guide/python_packaging.rst
##########
@@ -0,0 +1,220 @@
+..  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.
+
+
+################
+Python packaging
+################
+
+When you want to run your PySpark application on a cluster (like YARN, 
Kubernetes, Mesos, ..) you need to make sure that the your code
+and all used libraries are available on the executors.
+
+As an example let's say you may want to run the `Pandas UDF's examples 
<arrow_pandas.rst#series-to-scalar>`_.
+As it uses pyarrow as an underlying implementation we need to make sure to 
have pyarrow installed on each executor on the cluster. Otherwise you may get 
errors such as 
+``ModuleNotFoundError: No module named 'pyarrow'``.
+
+Here is the script ``main.py`` from the previous example that will be executed 
on the cluster:
+
+.. code-block:: python
+
+  import pandas as pd
+  from pyspark.sql.functions import pandas_udf, PandasUDFType
+  from pyspark.sql import SparkSession
+
+  def main(spark):
+    df = spark.createDataFrame(
+      [(1, 1.0), (1, 2.0), (2, 3.0), (2, 5.0), (2, 10.0)],
+      ("id", "v"))
+
+    @pandas_udf("double", PandasUDFType.GROUPED_AGG)
+    def mean_udf(v: pd.Series):
+      return v.mean()
+
+    print(df.groupby("id").agg(mean_udf(df['v'])).collect())
+
+
+  if __name__ == "__main__":
+    spark = SparkSession.builder.getOrCreate()
+    main(spark)
+
+
+There are multiple ways to ship the dependencies to the cluster:
+
+- Using py-files
+- Using a zipped virtual environment
+- Using PEX
+- Using Docker
+
+
+**************
+Using py-files
+**************
+
+PySpark allows to upload python files to the executors by setting the 
configuration setting ``spark.submit.pyFiles`` or by directly calling `addPyFile
+<../reference/api/pyspark.SparkContext.addPyFile.rst>`_ on the SparkContext.
+
+This is an easy way to ship additional custom Python code to the cluster. You 
can just add individual files or zip whole packages and upload them. 
+Using `addPyFile <../reference/api/pyspark.SparkContext.addPyFile.rst>`_ 
allows to upload code even after having started your job.
+
+It doesn't allow to add packages built as `Wheels 
<https://www.python.org/dev/peps/pep-0427/>`_ and therefore doesn't allowing to 
include dependencies with native code.
+
+
+**********************************
+Using a zipped virtual environment

Review comment:
       Yeah, it does.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to