Last active
February 19, 2018 16:51
-
-
Save PetrGlad/cca2028250e0c5d8e98dbaa1dcd1f34a to your computer and use it in GitHub Desktop.
Spark Python exsamples
This file contains hidden or 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
# 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