sale_id, product_id, and quantity.product_id and product_name.product_id.sale_id, product_id, and quantity.product_id and product_name.product_id.sales_df with these exact rows: (1, 101, 2), (2, 102, 1), (3, 103, 5). The columns must be sale_id, product_id, and quantity.Use spark.createDataFrame with a list of tuples and a list of column names.
product_df with these exact rows: (101, "Pen"), (102, "Notebook"), (103, "Eraser"). The columns must be product_id and product_name.Use spark.createDataFrame with a list of tuples and a list of column names for products.
broadcast from pyspark.sql.functions. Use sales_df.join() to join sales_df with product_df on product_id. Use broadcast(product_df) inside the join to broadcast the small product table. Save the result as joined_df.Use broadcast(product_df) inside the join() method.
print() and joined_df.show() to display the joined DataFrame output.Use joined_df.show() to display the DataFrame rows.
What is the main benefit of using broadcast() in Spark when joining tables?
Which of the following is the correct syntax to broadcast a small DataFrame small_df in Spark before joining?
from pyspark.sql.functions import broadcast
result = large_df.join(____, 'id')broadcast() function around the small DataFrame to mark it for broadcasting.large_df.join(broadcast(small_df), 'id') to broadcast the small table.Given the following Spark code, what will be the output count?
from pyspark.sql import SparkSession
from pyspark.sql.functions import broadcast
spark = SparkSession.builder.getOrCreate()
large_data = [(1, 'A'), (2, 'B'), (3, 'C')]
small_data = [(1, 'X'), (2, 'Y')]
large_df = spark.createDataFrame(large_data, ['id', 'val1'])
small_df = spark.createDataFrame(small_data, ['id', 'val2'])
joined_df = large_df.join(broadcast(small_df), 'id')
print(joined_df.count())
Identify the error in the following Spark code that attempts a broadcast join:
from pyspark.sql.functions import broadcast
result = large_df.join(small_df.broadcast(), 'id')small_df.broadcast() is invalid syntax.broadcast(small_df) instead to mark small_df for broadcasting.You have a large DataFrame orders with millions of rows and a small DataFrame countries with 10 rows. You want to join them on country_code. Which approach will give the best performance?
countries is small, broadcasting it avoids shuffling the large orders DataFrame.Pass the test and this pattern moves unknown