开始使用免费开始使用

比较广播连接与普通连接

您已经创建了两种连接:普通连接和广播连接。现在您的主管想了解,使用 Spark 优化后性能提升有多大。如果结果不错,您将有更多机会根据需要调整 Spark 配置。

您的 DataFrame normal_dfbroadcast_df 已可使用。

本练习是课程的一部分

使用 PySpark 进行数据清洗

查看课程

练习说明

  • 在普通 DataFrame 上执行 .count()
  • 在广播的 DataFrame 上执行 .count()
  • 打印两个 DataFrame 的计数和耗时,并指出其中的差异。

交互式实操练习

通过完成这段示例代码来试试这个练习。

start_time = time.time()
# Count the number of rows in the normal DataFrame
normal_count = ____
normal_duration = time.time() - start_time

start_time = time.time()
# Count the number of rows in the broadcast DataFrame
broadcast_count = ____
broadcast_duration = time.time() - start_time

# Print the counts and the duration of the tests
print("Normal count:\t\t%d\tduration: %f" % (normal_count, normal_duration))
print("Broadcast count:\t%d\tduration: %f" % (broadcast_count, broadcast_duration))
编辑并运行代码