I am using EMR 7.0.0 version, which has python 3.9, spark 3.5.0, Hadoop 3.3.6 in AWS.
I got the error:
File "/usr/local/lib/python3.9/site-packages/pyspark/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 740, in csv
File "/usr/local/lib/python3.9/site-packages/pyspark/python/lib/py4j-0.10.9.7-src.zip/py4j/java_gateway.py", line 1322, in __call__
File "/usr/local/lib/python3.9/site-packages/pyspark/python/lib/pyspark.zip/pyspark/errors/exceptions/captured.py", line 179, in deco
File "/usr/local/lib/python3.9/site-packages/pyspark/python/lib/py4j-0.10.9.7-src.zip/py4j/protocol.py", line 326, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o45.csv.
: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.apache.hadoop.fs.s3a.S3AFileSystem not found
I searched the solution, and suggested to org.apache.hadoop:hadoop-aws = 3.2.0
.
However, it still keeps failing. The code to build spark
builder = pyspark.sql.SparkSession.builder.appName("stock-daily-ingestion")
.config("spark.jars.packages", "org.apache.hadoop:hadoop-aws:3.2.0")
.config('spark.sql.shuffle.partitions', 2500)
.config("fs.s3.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem")
.config("fs.s3a.aws.credentials.provider", "org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider")
sc = builder.getOrCreate()
Did anyone meet this error? Help will be appreciated. Thanks.
2
Answers
The issue is resolved. When running in spark, adding the following in the spark-submit command
Spark cannot find the class responsible for accessing S3 storage within the Hadoop ecosystem.The class is part of the hadoop-aws library.
Sample code to include hadoop-aws library is as follows: