Last active
October 11, 2022 04:49
-
-
Save kovid-r/75f39e6ec59358f5a45e27da9e1d0bb4 to your computer and use it in GitHub Desktop.
PySpark Cheat Sheet Application Initialization
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
import pyspark | |
from pyspark import SparkContext | |
from pyspark.sql import SparkSession | |
from pyspark.sql import SQLContext | |
# create a SparkSession instance with the name moviedb with Hive support enabled | |
# https://spark.apache.org/docs/latest/sql-data-sources-hive-tables.html | |
spark = SparkSession.builder.appName("moviedb").enableHiveSupport().getOrCreate() | |
# create a SparkContext instance which allows the Spark Application to access | |
# Spark Cluster with the help of a resource manager which is usually YARN or Mesos | |
sc = SparkContext.getOrCreate() | |
# create a SQLContext instance to access the SQL query engine built on top of Spark | |
sqlContext = SQLContext(spark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment