Spark SQL

Introducción a Spark SQL en Python

Mark Plutowski Phd

Data Scientist

Crear tabla SQL y consultarla

Cursor de PySpark

Introducción a Spark SQL en Python

Cargar un DataFrame desde archivo

df = spark.read.csv(filename)
df = spark.read.csv(filename, header=True)
Introducción a Spark SQL en Python

Crear tabla SQL y consultarla

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|
+--------+--------+-----+
Introducción a Spark SQL en Python

Inspeccionar el esquema de la tabla

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)
Introducción a Spark SQL en Python

Marco

Introducción a Spark SQL en Python

DataFrame

Introducción a Spark SQL en Python

Datos tabulares

+--------+-------------+-----+
|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|
+--------+-------------+-----+
Introducción a Spark SQL en Python

dos dataframes

Introducción a Spark SQL en Python

dos dataframes concatenados

Introducción a Spark SQL en Python

un dataframe

Introducción a Spark SQL en Python

dividir un dataframe 1

Introducción a Spark SQL en Python

dividir un dataframe 2

Introducción a Spark SQL en Python

dividir un dataframe 3

Introducción a Spark SQL en Python

dividir un dataframe 4

Introducción a Spark SQL en Python

dividir un dataframe 5

Introducción a Spark SQL en Python

dividir un dataframe 6

Introducción a Spark SQL en Python

dos dataframes distribuidos

Introducción a Spark SQL en Python

SQL

Introducción a Spark SQL en Python

Lenguaje de consulta estructurado

Introducción a Spark SQL en Python

consultas

Introducción a Spark SQL en Python

datos distribuidos

Introducción a Spark SQL en Python

datos distribuidos + consulta

Introducción a Spark SQL en Python

Cargar texto delimitado

Carga un archivo con comas trainsched.txt en un DataFrame df:

df = spark.read.csv("trainsched.txt", header=True)
Introducción a Spark SQL en Python

Cargar texto delimitado

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|
+--------+-------------+-----+
Introducción a Spark SQL en Python

PySpark Shell

Introducción a Spark SQL en Python

Cursor de PySpark

Introducción a Spark SQL en Python

PySpark Shell

Introducción a Spark SQL en Python

Cursor de PySpark

Introducción a Spark SQL en Python

PySpark Shell

Introducción a Spark SQL en Python

Introducción a Spark SQL en Python

PySpark Shell

Introducción a Spark SQL en Python

Cursor de PySpark

Introducción a Spark SQL en Python

PySpark Shell

Introducción a Spark SQL en Python

Cursor de PySpark

Introducción a Spark SQL en Python

PySpark Shell

Introducción a Spark SQL en Python

Cursor de PySpark

Introducción a Spark SQL en Python

¡Vamos a practicar!

Introducción a Spark SQL en Python

Preparing Video For Download...