from pyspark.sql.types import *
schema = StructType([StructField("type", StringType(), True), StructField("average", IntegerType(), True)])
values = [('A', 19), ('B', 17), ('C', 10)]
df = spark.createDataFrame(values, schema)
parts = df.rdd.getNumPartitions()
print(parts)
Вывод: 44
Как происходит создание 44 разделов для фрейма данных с 3 дисками?
import pyspark.sql.functions as F
df.withColumn('p_id', F.spark_partition_id()).show()
Вывод:
+----+-------+----+
|type|average|p_id|
+----+-------+----+
| A| 19| 14|
| B| 17| 29|
| C| 10| 43|
+----+-------+----+