Obtener el número actual de particiones de un DataFrame


¿Hay alguna forma de obtener el número actual de particiones de un DataFrame? Revisé el DataFrame javadoc (spark 1.6) y no encontré un método para eso, o simplemente me lo perdí? (En el caso de JavaRDD hay un método getNumPartitions ().)

Author: kecso, 2017-02-11

4 answers

Necesita llamar a getNumPartitions() en el RDD subyacente del DataFrame, por ejemplo, df.rdd.getNumPartitions(). En el caso de Scala, este es un método sin parámetros: df.rdd.getNumPartitions.

 63
Author: user4601931,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-08 06:29:17

Convertir a RDD a continuación, obtener la longitud de las particiones

DF.rdd.partitions.length
 3
Author: Bhargav Kosaraju,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-01 06:24:38
 val df = Seq(
  ("A", 1), ("B", 2), ("A", 3), ("C", 1)
).toDF("k", "v")

df.rdd.getNumPartitions
 3
Author: Achyuth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-13 20:02:28

size es otra alternativa.

Permítanme explicarles esto con un ejemplo completo..

val x = (1 to 10).toList
val numberDF = x.toDF(“number”)
numberDF.rdd.partitions.size // => 4

Para demostrar que el número de particiones que tenemos con arriba... guardar ese dataframe como csv

numberDF.write.csv(“/Users/Ram.Ghadiyaram/output/numbers”)

Así es como se separan los datos en las diferentes particiones.

Partition 00000: 1, 2
Partition 00001: 3, 4, 5
Partition 00002: 6, 7
Partition 00003: 8, 9, 10
 2
Author: Ram Ghadiyaram,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-22 20:37:17