Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A column for partition ID.
Syntax
from pyspark.sql import functions as sf
sf.spark_partition_id()
Returns
pyspark.sql.Column: partition id the record belongs to.
Examples
Example 1: Get partition ID for each row
from pyspark.sql import functions as sf
spark.range(10, numPartitions=5).select("*", sf.spark_partition_id()).show()
+---+--------------------+
| id|SPARK_PARTITION_ID()|
+---+--------------------+
| 0| 0|
| 1| 0|
| 2| 1|
| 3| 1|
| 4| 2|
| 5| 2|
| 6| 3|
| 7| 3|
| 8| 4|
| 9| 4|
+---+--------------------+