-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
49 lines (39 loc) · 1.33 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Environment configuration script
@author: Jesus Antonanzas Acero, Alex Carrillo Alza
@version: "1.0"
@email: "[email protected], [email protected]"
@info: BDA, GCED, Big Data Analytics project
@date: 16/12/2019
Description
-----------
Configuration of Spark environment given the structure of the code skeleton provided.
This script is called in many parts of the project as a space saver, so that code is
not repeated.
Steps
-----------
1. Given a python version (string, i.e. "python3.6"), returns an object of type "Spark Context".
"""
import os
import sys
import pyspark
from pyspark import SparkConf
from pyspark.sql import SparkSession
def config_env(version):
HADOOP_HOME = "./resources/hadoop_home"
JDBC_JAR = "./resources/postgresql-42.2.8.jar"
PYSPARK_PYTHON = PYSPARK_DRIVER_PYTHON = version
os.environ["HADOOP_HOME"] = HADOOP_HOME
sys.path.append(HADOOP_HOME + "\\bin")
os.environ["PYSPARK_PYTHON"] = PYSPARK_PYTHON
os.environ["PYSPARK_DRIVER_PYTHON"] = PYSPARK_DRIVER_PYTHON
# start the configuration
conf = SparkConf()
conf.set("spark.jars", JDBC_JAR)
spark = SparkSession.builder \
.config(conf=conf) \
.master("local") \
.appName("Training") \
.getOrCreate()
sc = pyspark.SparkContext.getOrCreate()
return sc