Spark SQL

Introductie tot Spark SQL in Python

Mark Plutowski Phd

Data Scientist

SQL-tabel maken en bevragen

Pyspark Shell-cursor

Introductie tot Spark SQL in Python

Dataframe uit bestand laden

df = spark.read.csv(filename)
df = spark.read.csv(filename, header=True)
Introductie tot Spark SQL in Python

SQL-tabel maken en bevragen

df.createOrReplaceTempView("schedule")

spark.sql("SELECT * FROM schedule WHERE station = 'San Jose'") .show()
+--------+--------+-----+
|train_id| station| time|
+--------+--------+-----+
|     324|San Jose|9:05a|
|     217|San Jose|6:59a|
+--------+--------+-----+
Introductie tot Spark SQL in Python

Tableschema inspecteren

result = spark.sql("SHOW COLUMNS FROM tablename")
result = spark.sql("SELECT * FROM tablename LIMIT 0")
result = spark.sql("DESCRIBE tablename")
result.show()
print(result.columns)
Introductie tot Spark SQL in Python

Frame

Introductie tot Spark SQL in Python

Dataframe

Introductie tot Spark SQL in Python

Tabeldata

+--------+-------------+-----+
|train_id|      station| time|
+--------+-------------+-----+
|     324|San Francisco|7:59a| 
|     324|  22nd Street|8:03a|
|     324|     Millbrae|8:16a|
|     324|    Hillsdale|8:24a|
|     324| Redwood City|8:31a|
|     324|    Palo Alto|8:37a|
|     324|     San Jose|9:05a|
|     217|       Gilroy|6:06a|
|     217|   San Martin|6:15a|
|     217|  Morgan Hill|6:21a|
|     217| Blossom Hill|6:36a|
|     217|      Capitol|6:42a|
|     217|       Tamien|6:50a|
|     217|     San Jose|6:59a|
+--------+-------------+-----+
Introductie tot Spark SQL in Python

twee dataframes

Introductie tot Spark SQL in Python

twee dataframes samengevoegd

Introductie tot Spark SQL in Python

één dataframe

Introductie tot Spark SQL in Python

dataframe splitsen 1

Introductie tot Spark SQL in Python

dataframe splitsen 2

Introductie tot Spark SQL in Python

dataframe splitsen 3

Introductie tot Spark SQL in Python

dataframe splitsen 4

Introductie tot Spark SQL in Python

dataframe splitsen 5

Introductie tot Spark SQL in Python

dataframe splitsen 6

Introductie tot Spark SQL in Python

dataframe splitsen, gedistribueerd

Introductie tot Spark SQL in Python

SQL

Introductie tot Spark SQL in Python

Structured Query Language

Introductie tot Spark SQL in Python

query uitvoeren

Introductie tot Spark SQL in Python

gedistribueerde data

Introductie tot Spark SQL in Python

gedistribueerde data + query

Introductie tot Spark SQL in Python

Gescheiden tekst laden

Laadt een kommagescheiden bestand trainsched.txt in een dataframe df:

df = spark.read.csv("trainsched.txt", header=True)
Introductie tot Spark SQL in Python

Gescheiden tekst laden

df = spark.read.csv("trainsched.txt", header=True)
df.show()
+--------+-------------+-----+
|train_id|      station| time|
+--------+-------------+-----+
|     324|San Francisco|7:59a|
|     324|  22nd Street|8:03a|
|     324|     Millbrae|8:16a|
|     324|    Hillsdale|8:24a|
|     324| Redwood City|8:31a|
|     ...|          ...|  ...|
|     217| Blossom Hill|6:36a|
|     217|      Capitol|6:42a|
|     217|       Tamien|6:50a|
|     217|     San Jose|6:59a|
+--------+-------------+-----+
Introductie tot Spark SQL in Python

Pyspark Shell

Introductie tot Spark SQL in Python

Pyspark Shell-cursor

Introductie tot Spark SQL in Python

Pyspark Shell

Introductie tot Spark SQL in Python

Pyspark Shell cursor

Introductie tot Spark SQL in Python

Pyspark Shell

Introductie tot Spark SQL in Python

Introductie tot Spark SQL in Python

Pyspark Shell

Introductie tot Spark SQL in Python

Pyspark Shell-cursor

Introductie tot Spark SQL in Python

Pyspark Shell

Introductie tot Spark SQL in Python

Pyspark Shell-cursor

Introductie tot Spark SQL in Python

Pyspark Shell

Introductie tot Spark SQL in Python

Pyspark Shell-cursor

Introductie tot Spark SQL in Python

Laten we oefenen!

Introductie tot Spark SQL in Python

Preparing Video For Download...