spark_partition_id
パーティション ID の列。
構文
Python
from pyspark.sql import functions as sf
sf.spark_partition_id()
戻り値
pyspark.sql.Column: レコードが属するパーティション ID。
例
例1 : 各行のパーティションIDを取得する
Python
from pyspark.sql import functions as sf
spark.range(10, numPartitions=5).select("*", sf.spark_partition_id()).show()
Output
+---+--------------------+
| id|SPARK_PARTITION_ID()|
+---+--------------------+
| 0| 0|
| 1| 0|
| 2| 1|
| 3| 1|
| 4| 2|
| 5| 2|
| 6| 3|
| 7| 3|
| 8| 4|
| 9| 4|
+---+--------------------+