You have two tables: a customer table (~20–30 MB) and a transaction table (~50 MB). How would you join them efficiently, possibly using a broadcast join?
💡 Model Answer
Both tables are relatively small, so a broadcast join is a good choice. First, ensure that the smaller table (customer) is broadcasted by setting spark.sql.autoBroadcastJoinThreshold to a value larger than 30 MB or by using the broadcast hint: dfCustomer.broadcast.join(dfTransaction, "customer_id"). Spark will serialize the customer table and send it to all executors. The transaction table will be scanned locally, and the join will be performed in memory on each executor, avoiding a shuffle. If you prefer to be explicit, you can also use broadcast(dfCustomer) from the SQL functions. This approach reduces network I/O and speeds up the join. If the tables grow larger, you might consider a sort‑merge join or a shuffle hash join, but for the current sizes, broadcast join is optimal.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500