Spark 구성 작성하기
클러스터의 일부 Spark 구성을 살펴본 뒤, 필요에 맞게 Spark를 튜닝하도록 설정을 변경해 보겠습니다. 변경 사항이 클러스터에 반영되었는지 확인하기 위해 데이터를 가져올 거예요.
초기 spark 구성에서는 파티션 수가 기본값인 200으로 설정되어 있습니다.
spark 객체를 사용할 수 있어요. 가져올 수 있는 departures.txt.gz 파일이 제공됩니다. departures.txt.gz에서 중복을 제거한 행으로 만든 초기 DataFrame은 departures_df로 제공됩니다.
이 연습은 강의의 일부입니다
PySpark로 데이터 정제하기
연습 안내
departures_df의 파티션 수를 변수before에 저장하세요.spark.sql.shuffle.partitions구성을 파티션 500으로 변경하세요.- 출발 파일에서 중복을 제거한 행을 읽어
departures_dfDataFrame을 다시 생성하세요. - 구성 변경 전과 후의 파티션 수를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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" % ____)