未能成功设置可以读取 AWS s3 文件的 Spark 集群。我使用的软件如下:
使用Python版本:Python 3.8.6
from pyspark.sql import SparkSession, SQLContext
from pyspark.sql.types import *
from pyspark.sql.functions import *
import sys
spark = (SparkSession.builder
.appName("AuthorsAges")
.appName('SparkCassandraApp')
.getOrCreate())
spark._jsc.hadoopConfiguration().set("fs.s3a.access.key", "access-key")
spark._jsc.hadoopConfiguration().set("fs.s3a.secret.key", "secret-key")
spark._jsc.hadoopConfiguration().set("fs.s3a.impl","org.apache.hadoop.fs.s3a.S3AFileSystem")
spark._jsc.hadoopConfiguration().set("com.amazonaws.services.s3.enableV4", "true")
spark._jsc.hadoopConfiguration().set("fs.s3a.aws.credentials.provider","org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider")
spark._jsc.hadoopConfiguration().set("fs.s3a.endpoint", "")
input_file='s3a://spark-test-data/Fire_Department_Calls_for_Service.csv'
file_schema = StructType([StructField("Call_Number",StringType(),True),
StructField("Unit_ID",StringType(),True),
StructField("Incident_Number",StringType(),True),
...
...
# Read file into a Spark DataFrame
input_df = (spark.read.format("csv") \
.option("header", "true") \
.schema(file_schema) \
.load(input_file))
Run Code Online (Sandbox Code Playgroud)
当代码开始执行spark.read.format时失败。似乎找不到该类。java.lang.NoClassDefFoundError:com.amazonaws.services.s3.model.MultiObjectDeleteException
File "<stdin>", line 1, in <module>
File "/usr/local/spark/spark-3.0.1-bin-hadoop3.2/python/pyspark/sql/readwriter.py", line 178, in load …Run Code Online (Sandbox Code Playgroud)