Spark SQL

Nhập môn Spark SQL bằng Python

Mark Plutowski Phd

Data Scientist

Tạo bảng SQL và truy vấn

Con trỏ Pyspark Shell

Nhập môn Spark SQL bằng Python

Tải DataFrame từ tệp

df = spark.read.csv(filename)
df = spark.read.csv(filename, header=True)
Nhập môn Spark SQL bằng Python

Tạo bảng SQL và truy vấn

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|
+--------+--------+-----+
Nhập môn Spark SQL bằng Python

Xem lược đồ bảng

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)
Nhập môn Spark SQL bằng Python

Khung

Nhập môn Spark SQL bằng Python

Khung dữ liệu

Nhập môn Spark SQL bằng Python

Dữ liệu dạng bảng

+--------+-------------+-----+
|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|
+--------+-------------+-----+
Nhập môn Spark SQL bằng Python

hai DataFrame

Nhập môn Spark SQL bằng Python

hai DataFrame được nối

Nhập môn Spark SQL bằng Python

một DataFrame

Nhập môn Spark SQL bằng Python

tách một DataFrame 1

Nhập môn Spark SQL bằng Python

tách một DataFrame 2

Nhập môn Spark SQL bằng Python

tách một DataFrame 3

Nhập môn Spark SQL bằng Python

tách một DataFrame 4

Nhập môn Spark SQL bằng Python

tách một DataFrame 5

Nhập môn Spark SQL bằng Python

tách một DataFrame 6

Nhập môn Spark SQL bằng Python

tách DataFrame phân tán

Nhập môn Spark SQL bằng Python

SQL

Nhập môn Spark SQL bằng Python

Ngôn ngữ truy vấn có cấu trúc

Nhập môn Spark SQL bằng Python

truy vấn

Nhập môn Spark SQL bằng Python

dữ liệu phân tán

Nhập môn Spark SQL bằng Python

dữ liệu phân tán + truy vấn

Nhập môn Spark SQL bằng Python

Tải văn bản phân tách

Tải tệp phân tách bằng dấu phẩy trainsched.txt vào DataFrame df:

df = spark.read.csv("trainsched.txt", header=True)
Nhập môn Spark SQL bằng Python

Tải văn bản phân tách

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|
+--------+-------------+-----+
Nhập môn Spark SQL bằng Python

Pyspark Shell

Nhập môn Spark SQL bằng Python

Con trỏ Pyspark Shell

Nhập môn Spark SQL bằng Python

Pyspark Shell

Nhập môn Spark SQL bằng Python

Con trỏ Pyspark Shell

Nhập môn Spark SQL bằng Python

Pyspark Shell

Nhập môn Spark SQL bằng Python

Nhập môn Spark SQL bằng Python

Pyspark Shell

Nhập môn Spark SQL bằng Python

Con trỏ Pyspark Shell

Nhập môn Spark SQL bằng Python

Pyspark Shell

Nhập môn Spark SQL bằng Python

Con trỏ Pyspark Shell

Nhập môn Spark SQL bằng Python

Pyspark Shell

Nhập môn Spark SQL bằng Python

Con trỏ Pyspark Shell

Nhập môn Spark SQL bằng Python

Ayo berlatih!

Nhập môn Spark SQL bằng Python

Preparing Video For Download...