Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get the current spark context settings in PySpark?

I'm trying to get the path to spark.worker.dir for the current sparkcontext.

If I explicitly set it as a config param, I can read it back out of SparkConf, but is there anyway to access the complete config (including all defaults) using PySpark?

like image 820
whisperstream Avatar asked May 31 '15 17:05

whisperstream


People also ask

How do I get the current Spark context?

In Spark/PySpark you can get the current active SparkContext and its configuration settings by accessing spark. sparkContext. getConf.

How do I check my default Spark settings?

There is no option of viewing the spark configuration properties from command line. Instead you can check it in spark-default. conf file. Another option is to view from webUI.

What is PySpark Spark context?

A SparkContext represents the connection to a Spark cluster, and can be used to create RDD and broadcast variables on that cluster. When you create a new SparkContext, at least the master and app name should be set, either through the named parameters here or through conf .

How do you get SparkContext from SparkSession PySpark?

In Spark or PySpark SparkSession object is created programmatically using SparkSession. builder() and if you are using Spark shell SparkSession object “ spark ” is created by default for you as an implicit object whereas SparkContext is retrieved from the Spark session object by using sparkSession. sparkContext .


2 Answers

Spark 2.1+

spark.sparkContext.getConf().getAll() where spark is your sparksession (gives you a dict with all configured settings)

like image 70
Kevad Avatar answered Oct 12 '22 23:10

Kevad


Yes: sc.getConf().getAll()

Which uses the method:

SparkConf.getAll() 

as accessed by

SparkContext.sc.getConf() 

But it does work:

In [4]: sc.getConf().getAll() Out[4]: [(u'spark.master', u'local'),  (u'spark.rdd.compress', u'True'),  (u'spark.serializer.objectStreamReset', u'100'),  (u'spark.app.name', u'PySparkShell')] 
like image 21
WestCoastProjects Avatar answered Oct 12 '22 23:10

WestCoastProjects