เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Spark SQL Join

Sometimes it is much easier to write complex joins in SQL. In this exercise, we will start with the join keys already in the same format and precision but will use SparkSQL to do the joining.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Feature Engineering with PySpark

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Register the Dataframes as SparkSQL tables with createOrReplaceTempView, name them the df and walk_df respectively.
  • In the join_sql string, set the left table to df and the right table to walk_df
  • Call spark.sql() on the join_sql string to perform the join.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Register dataframes as tables
____.createOrReplaceTempView(____)
____.createOrReplaceTempView(____)

# SQL to join dataframes
join_sql = 	"""
			SELECT 
				*
			FROM ____
			LEFT JOIN ____
			ON df.longitude = walk_df.longitude
			AND df.latitude = walk_df.latitude
			"""
# Perform sql join
joined_df = spark.sql(____)
แก้ไขและรันโค้ด