EPAM Interview Questions
RDD (Resilient Distributed Dataset) is Spark's low level abstraction — a distributed collection of JVM objects with no schema. DataFrame is a higher lev...
What are the Key differences between DataFrame and RDD.
RDD (Resilient Distributed Dataset) is Spark's low level abstraction — a distributed collection of JVM objects with no schema. DataFrame is a higher level abstraction built on top of RDD with a named column schema, similar to a relational table. Key differences: Schema : RDDs are untyped; DataFrames have a defined schema with column names and data types Optimization : DataFrames go through the Catalyst optimizer and Tungsten execution engine for automatic query optimization; RDDs do not Performa
Narrow vs wide transformations; shuffling impact and optimization.
Narrow transformations are operations where each output partition depends on exactly one input partition — no data movement across executors is required. Examples: map , filter , flatMap , union . Wide transformations require data from multiple input partitions to produce each output partition, triggering a shuffle — data is serialized, written to disk, and transferred over the network. Examples: groupByKey , reduceByKey , join , distinct , repartition . Shuffle impact: Significant network I/O a
What strategies can be used to minimize shuffling in Spark?
Minimizing shuffle is one of the most impactful Spark performance optimizations: Broadcast joins : When one table is small (< spark.sql.autoBroadcastJoinThreshold , default 10MB), Spark broadcasts it to all executors, eliminating the shuffle entirely Pre partition data : Store data pre partitioned by join/group keys in Parquet/Delta so Spark can exploit partition pruning and avoid full shuffles Use reduceByKey over groupByKey : reduceByKey performs a map side combine (partial aggregation) before
What is the difference between repartition and coalesce in Spark?
Both repartition and coalesce change the number of partitions in a DataFrame, but they work differently: repartition(n) : Performs a full shuffle — data is redistributed evenly across all n partitions Can both increase and decrease the number of partitions Produces evenly sized partitions (good for balancing skew) More expensive due to the shuffle, but necessary when you need balanced partitions coalesce(n) : Avoids a full shuffle by merging existing partitions on the same executor — moves data
When should you use repartition vs. coalesce?
Choose between these operations based on your specific need: Use repartition when: You need to increase the number of partitions (e.g., before a large join or shuffle heavy aggregation) Your data is skewed and you need evenly distributed partitions for downstream processing You want to repartition by a specific column for efficient downstream joins or writes: df.repartition(200, 'customer id') Writing to storage and you want a controlled, uniform number of output files Use coalesce when: You nee
In what scenario would you use repartition to reduce the number of partitions?
Although coalesce is the typical choice for reducing partitions, repartition to reduce is preferred when data is heavily skewed . coalesce simply merges adjacent partitions on the same executor — if some partitions are very large (due to data skew), those large partitions remain large. This causes stragglers during downstream processing. Scenario: skewed data after a filter or aggregation Also use repartition to reduce partitions when you simultaneously want to repartition by a column for downst
Which version of Spark are you using? Are you working with Spark 3.4?
This is a context setting question the interviewer asks to gauge your familiarity with recent Spark features. A strong answer acknowledges both version specifics and notable improvements. Spark 3.x major improvements over Spark 2.x: Adaptive Query Execution (AQE) — introduced in 3.0, stable in 3.2+. Dynamically re plans queries at runtime based on shuffle statistics Dynamic Partition Pruning (DPP) — pushes partition filters from dimension tables into fact table scans at runtime Improved Pandas U
What is Adaptive Query Execution (AQE) in Spark, and how does it improve performance?
Adaptive Query Execution (AQE) is a Spark optimization framework (stable since Spark 3.2) that re optimizes query plans at runtime using statistics collected from completed shuffle stages, rather than relying solely on compile time estimates. Enabled via: spark.conf.set('spark.sql.adaptive.enabled', 'true') Three core features of AQE: 1. Dynamically coalescing shuffle partitions : After a shuffle, Spark inspects actual partition sizes and merges small partitions into larger ones. This prevents t