Skip to content

Instantly share code, notes, and snippets.

@PetrGlad
Last active February 19, 2018 16:51
Show Gist options
  • Save PetrGlad/cca2028250e0c5d8e98dbaa1dcd1f34a to your computer and use it in GitHub Desktop.
Save PetrGlad/cca2028250e0c5d8e98dbaa1dcd1f34a to your computer and use it in GitHub Desktop.
Spark Python exsamples
# SPARK_HOME=$HOME/opt/spark-2.2.1-bin-hadoop2.7 ptpython
# SPARK_HOME=$HOME/opt/spark-2.2.1-bin-hadoop2.7 pyspark
from pyspark.sql import SparkSession
spark = SparkSession.builder \
.appName('hello') \
.master('local[3]') \
.config("spark.ui.port", 9100) \
.getOrCreate()
# Add postgresql JDBC driver to Spark's classpath
evts = spark.read.jdbc(url="jdbc:postgresql://localhost:15432/diga?user=a_pg_user&password=friend",
table="event_type")
evts.select("name").show(50, False)
evts.createGlobalTempView("event_type")
spark.sql("select * from global_temp.event_type limit 10")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment