generated from kbase/kbase-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b09aa49
commit 1921729
Showing
8 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
|
||
from pyspark.conf import SparkConf | ||
from pyspark.sql import SparkSession | ||
|
||
|
||
def get_spark_session(app_name: str, local: bool = False) -> SparkSession: | ||
""" | ||
Helper to get and manage the `SparkSession` and keep all of our spark configuration params in one place. | ||
:param app_name: The name of the application | ||
:param local: Whether to run the spark session locally or not | ||
:return: A `SparkSession` object | ||
""" | ||
|
||
if local: | ||
return SparkSession.builder.appName(app_name).getOrCreate() | ||
|
||
spark_conf = SparkConf() | ||
|
||
spark_conf.setAll( | ||
[ | ||
( | ||
"spark.master", | ||
os.environ.get("SPARK_MASTER_URL", "spark://spark-master:7077"), | ||
), | ||
("spark.app.name", app_name), | ||
] | ||
) | ||
|
||
return SparkSession.builder.config(conf=spark_conf).getOrCreate() |