Salting adds a new column but does not change the number of rows.
Step 2: Count rows after salting
The count remains the same as original DataFrame, 1000 rows.
Final Answer:
1000 -> Option B
Quick Check:
Salting adds column, count unchanged [OK]
Hint: Salting adds column, row count stays same [OK]
Common Mistakes:
Thinking salting duplicates rows
Confusing salt range with row count
Assuming count changes after withColumn
4. You have a join in Spark that is very slow due to data skew on the join key. Which of the following code snippets correctly applies salting to both DataFrames to fix the skew?
A. Incorrect: salting with fixed value instead of random
B. Incorrect: salting only one DataFrame
C. Incorrect: joining without salt column
D. Correct: salting both sides and joining on key and salt
Solution
Step 1: Understand salting for joins
To fix skew, salt both DataFrames on join key with same salt range.
Step 2: Verify join condition
Joining on both original key and salt column ensures balanced partitions.
Final Answer:
Correct: salting both sides and joining on key and salt -> Option D
Quick Check:
Salt both sides + join on key & salt [OK]
Hint: Salt both DataFrames and join on key plus salt [OK]
Common Mistakes:
Salting only one DataFrame
Joining without salt column
Using fixed salt value instead of random
5. You have a Spark job with a very large skewed key causing one partition to be huge. You want to reduce skew by salting and also control shuffle partitions. Which approach below best balances load and parallelism?
hard
A. Add salt column but keep shuffle partitions very low
B. Do not add salt, just increase shuffle partitions
C. Add a salt column with random values, join on salted keys, and increase shuffle partitions
D. Add salt column with fixed value and reduce shuffle partitions
Solution
Step 1: Apply salting to spread skewed key
Adding a salt column with random values breaks large groups into smaller ones.
Step 2: Adjust shuffle partitions to increase parallelism
Increasing shuffle partitions allows more tasks to run in parallel, reducing bottlenecks.
Step 3: Combine salting and partition tuning
Both salting and increasing partitions together balance load and improve job speed.
Final Answer:
Add a salt column with random values, join on salted keys, and increase shuffle partitions -> Option C
Quick Check:
Salt + more partitions = balanced load [OK]
Hint: Salt keys and increase shuffle partitions for best balance [OK]
Common Mistakes:
Keeping shuffle partitions too low after salting
Not salting and only increasing partitions
Using fixed salt value causing no skew fix
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.