진지한 개발자

Pyspark 예제 실행 본문

IT/spark

Pyspark 예제 실행

제이_엔 2023. 4. 19. 14:00
728x90

spark 실행 확인

cd $SPARK_HOME
./bin/pyspark

위의 경우 worker UI 화면 접근 가능

예제 : 워드 카운트

lines = sc.textFile("README.md")

lines.count()
lines.first()

pythonLines = lines.filter(lambda line : "Python" in line)
pyrhonLines.first()

python 파일 생성

from pyspark import SparkConf, SparkContext

conf = SparkConf().setMaster("local").setAppName("test")
sc = SparkContext(conf=conf)

lines = sc.textFile("./README.md")

print("lines.count() : ", lines.count())
print("lines.first() : ", lines.first())

pythonLines = lines.filter(lambda line: "Python" in line)
print("pythonLines.first() : ", pythonLines.first())

spark로 python 파일 실행

./bin/spark-submit test.py

위의 경우 작업이 실행 되는 동안 UI 접근 가능

728x90

'IT > spark' 카테고리의 다른 글

PySpark의 UDF 예제  (0) 2023.07.31
PySpark 특징 및 장점  (0) 2023.07.31
Apache Spark 설치  (0) 2023.04.19
window 에 scala 설치  (0) 2023.02.08
ec2에 spark 설치하기  (0) 2023.02.07