Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
Why doesn't Hadoop respect 'spark.hadoop.fs' properties set in pyspark?

There are three properties in my spark-defaults.conf that I want to be able to set dynamically:

  • spark.driver.maxResultSize
  • spark.hadoop.fs.s3a.access.key
  • spark.hadoop.fs.s3a.secret.key

Here's my attempt to do so:

from pyspark import SparkConf
from pyspark.sql import SparkSession

conf = (SparkConf()
        .setMaster(spark_master)
        .setAppName(app_name)
        .set('spark.driver.maxResultSize', '5g')
        .set('spark.hadoop.fs.s3a.access.key', '<access>')\
        .set('spark.hadoop.fs.s3a.secret.key', '<secret>)
        )

spark = SparkSession.builder.\
    config(conf=conf).\
    getOrCreate()

print(spark.conf.get('spark.driver.maxResultSize'))
print(spark.conf.get('spark.hadoop.fs.s3a.access.key'))
print(spark.conf.get('spark.hadoop.fs.s3a.secret.key'))

spark.stop()

Here's the output I get:

5g
<access>
<secret>

However when I try to read a csv file on S3 using this configuration, I get a permissions denied error.

If I set the credentials via environment variables, I am able to read the file.

Why doesn't Hadoop respect the credentials specified this way?

Update:

I am aware of other Q&As relating to setting Hadoop properties in pyspark.

Here I am trying to record for posterity how you can be fooled into thinking that you can set them dynamically via spark.hadoop.*, since that is the name you use to set these properties in spark-defaults.conf, and since you don't get an error directly when you try to set them this way.

Many sites tell you to "set the spark.hadoop.fs.s3a.access.key property", but don't specify that this only the case if you set it statically in spark-defaults.conf and not dynamically in pyspark.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It turns out that you can't specify Hadoop properties via:

spark.conf.set('spark.hadoop.<property>', <value>)

but you must instead use:

spark.sparkContext._jsc.hadoopConfiguration().set('<property>', <value>)

I believe you can only use spark.conf.set() for the properties listed on the Spark Configuration page.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!