Spark-configuraties schrijven
Nu je enkele Spark-configuraties op je cluster hebt bekeken, wil je een paar instellingen aanpassen om Spark beter op jouw behoeften af te stemmen. Je importeert wat data om te controleren of je wijzigingen effect hebben op het cluster.
De Spark-configuratie staat aanvankelijk op de standaardwaarde van 200 partities.
Het spark-object is beschikbaar. Er is een bestand departures.txt.gz beschikbaar om te importeren. Een initiële DataFrame met de unieke rijen uit departures.txt.gz is beschikbaar als departures_df.
Deze oefening maakt deel uit van de cursus
Data opschonen met PySpark
Oefeninstructies
- Sla het aantal partities in
departures_dfop in de variabelebefore. - Wijzig de configuratie
spark.sql.shuffle.partitionsnaar 500 partities. - Maak de DataFrame
departures_dfopnieuw aan door de unieke rijen uit het departures-bestand in te lezen. - Print het aantal partities van vóór en na de configuratiewijziging.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Store the number of partitions in variable
before = departures_df.____
# Configure Spark to use 500 partitions
____('spark.sql.shuffle.partitions', ____)
# Recreate the DataFrame using the departures data file
departures_df = spark.read.csv('departures.txt.gz').____
# Print the number of partitions for each instance
print("Partition count before change: %d" % ____)
print("Partition count after change: %d" % ____)