

















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















































Question 1. Which component in Spark is responsible for converting user code into a logical plan, then into a physical execution plan? A) SparkContext B) Catalyst Optimizer C) Cluster Manager D) Executor Answer: B Explanation: The Catalyst Optimizer parses the DataFrame/Dataset API calls, creates a logical plan, applies rule-based optimizations, and finally produces a physical plan for execution. Question 2. In a Spark Standalone cluster, what role does the process that runs the driver program play? A) It manages worker node heartbeats. B) It schedules tasks on executors. C) It stores block manager data. D) It provides HDFS namenode services. Answer: B Explanation: The driver holds the SparkContext, builds the DAG, and communicates with the cluster manager to assign tasks to executors on worker nodes. Question 3. Which of the following is a narrow transformation? A) groupByKey B) reduceByKey C) map D) distinct
Answer: C Explanation: A narrow transformation like map processes each input partition independently, producing output without requiring data from other partitions, unlike wide transformations that cause shuffles. Question 4. What triggers the actual execution of a Spark job? A) Calling a transformation such as filter. B) Registering a UDF. C) Invoking an action like collect. D) Creating a SparkSession. Answer: C Explanation: Spark uses lazy evaluation; only actions (e.g., collect, count, save) cause the DAG to be materialized and executed. Question 5. How many stages will the following code generate? df.filter($"age">30).groupBy("country").agg(count("*")) A) 1 B) 2 C) 3 D) 4 Answer: B Explanation: The filter is a narrow transformation (same stage). The groupBy followed by agg is a wide transformation that requires a shuffle, creating a second stage. Question 6. Which Spark storage level stores data only in memory as deserialized Java objects and does not replicate it? A) MEMORY_ONLY_SER B) DISK_ONLY_
Question 9. Which of the following is true about Spark’s broadcast join? A) It is automatically used when both tables are larger than 1 GB. B) It replicates the smaller dataset to all executors. C) It always results in a shuffle. D) It cannot be used with SQL API. Answer: B Explanation: A broadcast join sends a copy of the smaller DataFrame to each executor, allowing the join to be performed locally without a shuffle. Question 10. What does the repartition(10) transformation do to a DataFrame? A) Reduces the number of partitions to 10 without a shuffle. B) Increases the number of partitions to 10 using a hash shuffle. C) Merges partitions until there are exactly 10, preserving order. D) Coalesces partitions without data movement. Answer: B Explanation: repartition always triggers a full shuffle and creates the specified number of partitions, regardless of the current count. Question 11. Which Spark configuration property controls the number of cores allocated per executor? A) spark.executor.instances B) spark.executor.memory C) spark.executor.cores D) spark.driver.cores Answer: C Explanation: spark.executor.cores defines how many CPU cores each executor can use for running tasks.
Question 12. Which built-in function would you use to split a string column on a comma delimiter and explode the resulting array? A) split_and_flatten B) explode(split(col, ",")) C) split_explode(col, ",") D) flatten(split(col, ",")) Answer: B Explanation: split(col, ",") creates an array, and explode turns each element into a separate row. Question 13. In Spark SQL, what is the difference between a global temporary view and a regular temporary view? A) Global views persist across Spark sessions; regular views do not. B) Global views are stored in Hive metastore; regular views are in-memory only. C) Global views are visible to all sessions within the same Spark application; regular views are session-scoped. D) There is no difference; they are synonyms. Answer: C Explanation: A global temporary view is tied to the Spark application and can be accessed from any session using the global_temp database, whereas a standard temporary view is scoped to the session that created it. Question 14. Which of the following statements about Adaptive Query Execution (AQE) is FALSE? A) AQE can coalesce shuffle partitions at runtime. B) AQE can dynamically switch from sort-merge join to broadcast join. C) AQE is enabled by default in Spark 3.x.
C) DAGScheduler D) TaskScheduler Answer: B Explanation: The Catalyst Optimizer parses the SQL string, creates a logical plan, and optimizes it before execution. Question 18. Which of the following is NOT a valid storage level for persisting a DataFrame? A) MEMORY_AND_DISK_SER_ B) OFF_HEAP C) DISK_ONLY_ D) MEMORY_ONLY_ Answer: C Explanation: Storage levels can have a replication factor of 1 or 2; DISK_ONLY_3 is invalid. Question 19. What does the coalesce(5) transformation do? A) Increases partitions to 5 using a full shuffle. B) Decreases partitions to 5 without a full shuffle. C) Guarantees exactly 5 partitions after a shuffle. D) Merges all partitions into a single partition. Answer: B Explanation: coalesce reduces the number of partitions by collapsing them, avoiding a full shuffle when decreasing partitions. Question 20. Which of the following is a correct way to create a SparkSession in Scala? A) val spark = SparkSession.builder().appName("App").getOrCreate()
B) val spark = new SparkSession("App") C) SparkSession("App") D) SparkContext.builder().appName("App").getOrCreate() Answer: A Explanation: The builder pattern is used to configure and instantiate a SparkSession. Question 21. In Spark Structured Streaming, what is the purpose of a watermark? A) To limit the size of the state store. B) To discard state for events older than the watermark. C) To synchronize batch intervals with event time. D) To force a full recomputation of the query. Answer: B Explanation: Watermarks define a threshold for late data; records older than the watermark are considered too late and can be dropped, allowing state cleanup. Question 22. Which function can be used to compute a running total of a column sales partitioned by region and ordered by date? A) sum(sales) over (partition by region order by date rows between unbounded preceding and current row) B) cumulative_sum(sales) over (partition by region order by date) C) sum(sales) over (partition by region) D) running_total(sales, region, date) Answer: A Explanation: The standard window expression using sum with rows between unbounded preceding and current row calculates a cumulative sum.
Explanation: Both withColumn and select with alias can create a new column; they are equivalent in this context. Question 26. In Spark, which execution engine component is responsible for converting a physical plan into Java bytecode for CPU-efficient processing? A) Catalyst Optimizer B) Tungsten Project C) DAGScheduler D) BlockManager Answer: B Explanation: Tungsten (Project Tungsten) provides whole-stage code generation, turning parts of the physical plan into optimized Java bytecode. Question 27. Which of the following DataFrame APIs can be used to remove rows that contain any null value? A) df.na.drop() B) df.dropna() C) df.filter(col.isNotNull()) D) Both A and B are correct. Answer: D Explanation: na.drop() and dropna() are synonymous; both drop rows with nulls. Question 28. When using Spark Connect, which of the following statements is true? A) The client runs the full Spark engine locally. B) The client sends logical plans to a remote Spark server for execution.
C) Spark Connect only works with Scala, not Python. D) It replaces the need for a SparkSession. Answer: B Explanation: Spark Connect decouples the client from the execution engine; the client builds logical plans and sends them to a remote Spark server. Question 29. Which function converts a Pandas DataFrame to a Spark DataFrame without copying data? A) spark.createDataFrame(pandas_df) B) pandas_df.to_spark() C) pandas_on_spark.from_pandas(pandas_df) D) spark.pandas.from_pandas(pandas_df) Answer: C Explanation: pandas_on_spark.from_pandas (or ps.from_pandas) creates a Spark DataFrame that shares underlying data where possible, avoiding a full copy. Question 30. What is the effect of calling df.persist(StorageLevel.DISK_ONLY)? A) Data is cached in memory only. B) Data is stored on disk only and not in memory. C) Data is stored both in memory and on disk. D) Data is not persisted at all. Answer: B Explanation: DISK_ONLY forces Spark to write the persisted partitions to disk, freeing memory. Question 31. Which of the following is the correct syntax to create a temporary view named sales_view from a DataFrame df in PySpark?
Question 34. Which of the following best describes the purpose of the spark.sql.execution.arrow.enabled configuration? A) Enables columnar storage for Parquet files. B) Uses Apache Arrow to accelerate DataFrame ↔ Pandas conversion. C) Turns on vectorized query execution for SQL. D) Allows Spark to read Arrow files directly. Answer: B Explanation: When enabled, Spark uses Arrow columnar format for efficient data transfer between the JVM and Python processes. Question 35. Which Spark function would you use to generate a new column containing the year extracted from a timestamp column event_time? A) year(event_time) B) date_format(event_time, "yyyy") C) extract_year(event_time) D) Both A and B are correct. Answer: D Explanation: Both year(col) and date_format(col, "yyyy") return the year component. Question 36. What is the default number of shuffle partitions in Spark 3.x if the configuration is not set? A) 100 B) 200 C) 300 D) 500 Answer: B
Explanation: Spark defaults spark.sql.shuffle.partitions to 200. Question 37. Which of the following statements about the cache() method is FALSE? A) It uses the default storage level MEMORY_AND_DISK. B) It is a lazy operation; caching happens when an action is executed. C) It always replicates data across two executors. D) It can be called on both RDDs and DataFrames. Answer: C Explanation: cache() does not replicate data; replication is controlled by storage level (e.g., MEMORY_ONLY_2). Question 38. In PySpark, which API call would you use to broadcast a small lookup dictionary lookup_dict to all executors? A) spark.broadcast(lookup_dict) B) sc.broadcast(lookup_dict) C) broadcast(lookup_dict) D) Both A and B are valid (A is a shortcut). Answer: B Explanation: The SparkContext.broadcast method is used; spark does not expose a direct broadcast method. Question 39. Which of the following is a correct way to read a JSON file stored in HDFS into a DataFrame? A) spark.read.json("hdfs://namenode:8020/data/file.json") B) spark.read.format("json").load("hdfs:///data/file.json") C) spark.read.format("json").option("path", "hdfs:///data/file.json").load() D) All of the above are correct.
B) Use broadcast join for the smaller side. C) Increase spark.sql.shuffle.partitions. D) Disable caching. Answer: B Explanation: Broadcasting the smaller table avoids the shuffle, dramatically reducing shuffle read size. Question 43. Which of the following statements about Delta Lake’s “time travel” feature is correct? A) It allows you to query previous table versions using a timestamp or version number. B) It only works when the table is stored in S3. C) It requires a separate metastore outside of Spark. D) It is incompatible with Spark Structured Streaming. Answer: A Explanation: Delta Lake stores transaction logs, enabling queries on older snapshots via VERSION AS OF or TIMESTAMP AS OF. Question 44. Which of the following is the correct way to define a window specification that partitions by city and orders by date in Scala? A) Window.partitionBy("city").orderBy("date") B) Window.by("city").sort("date") C) Window.partition("city").order("date") D) Window.groupBy("city").orderBy("date") Answer: A Explanation: The Window API uses partitionBy and orderBy to define the window.
Question 45. In Spark Structured Streaming, which sink guarantees exactly-once semantics when writing to a file system? A) console B) foreachBatch C) file sink with checkpointing D) memory sink Answer: C Explanation: The file sink combined with a checkpoint directory ensures exactly-once writes by tracking progress. Question 46. Which statement about spark.sql.autoBroadcastJoinThreshold is true? A) It sets the maximum size (in bytes) of a table that can be broadcast automatically. B) It disables broadcast joins when set to -1. C) It only applies to DataFrames, not SQL queries. D) Both A and B are correct. Answer: D Explanation: The threshold (default 10 MB) controls automatic broadcast; setting it to -1 disables automatic broadcasting. Question 47. Which of the following functions can be used to convert a column of type String to Timestamp in Spark SQL? A) to_timestamp(col) B) cast(col as Timestamp) C) unix_timestamp(col) D) Both A and B are valid. Answer: D
D) Whether cross joins are executed using sort-merge join. Answer: A Explanation: When disabled, Spark throws an error for cross joins lacking a join condition, preventing accidental Cartesian products. Question 51. Which of the following is true about the mapPartitions transformation? A) It processes each partition with a user-defined function that receives an iterator of rows. B) It always results in a shuffle. C) It cannot change the number of rows per partition. D) It is a lazy transformation that returns a DataFrame. Answer: A Explanation: mapPartitions gives the full iterator of a partition to the function, allowing batch processing of rows. Question 52. In PySpark, which method would you use to write a streaming query to a Kafka topic named output_topic? A) query.writeStream.format("kafka").option("topic", "output_topic")... B) query.write.format("kafka").option("topic", "output_topic")... C) query.writeStream.kafka("output_topic") D) query.write.kafka("output_topic") Answer: A Explanation: Streaming writes use writeStream; you must specify format "kafka" and the topic option. Question 53. Which of the following is a benefit of using the Pandas API on Spark (pyspark.pandas)?
A) Automatic vectorized UDF generation. B) Ability to run Pandas code on a single node without Spark. C) Seamless scaling of Pandas syntax to distributed execution. D) It replaces the need for DataFrames. Answer: C Explanation: pyspark.pandas provides a familiar Pandas-like API that runs on Spark’s distributed engine. Question 54. Which of the following statements about spark.sql.shuffle.partitions is FALSE? A) It can be set per query using spark.conf.set. B) It influences the number of reduce tasks for shuffle stages. C) Setting it to 0 disables shuffling. D) The default is 200. Answer: C Explanation: Setting it to 0 is not allowed; Spark will throw an error because at least one partition is required. Question 55. Which of the following is the correct way to add a monotonically increasing id column to a DataFrame in PySpark? A) df.withColumn("id", monotonically_increasing_id()) B) df.withColumn("id", row_number().over(Window.orderBy(lit(1)))) C) df.select("*", lit(monotonically_increasing_id())) D) Both A and B are valid ways. Answer: D Explanation: Both monotonically_increasing_id and a row_number over a dummy window produce a unique increasing identifier.