View Full Databricks Certified Associate Developer for Apache Spark Exam Dumps and Practice Test Dumps
Question 1.
Which Spark API is primarily used to represent structured data organized into named columns?
- RDD
2. Broadcast variable
3. DataFrame
4. SparkContext
Correct Answer: 3. DataFrame
Explanation:
A DataFrame represents distributed structured data organized into named columns, much like a table in a relational database. Spark can optimize DataFrame operations through its query optimizer and execution engine. RDDs provide a lower-level distributed collection abstraction but do not inherently include named columns or schema information. SparkContext represents the connection to a Spark cluster in older APIs, while broadcast variables distribute read-only values efficiently to executors. For most structured-data workloads, DataFrames provide the preferred high-level API.
Question 2.
Which operation is considered a Spark transformation rather than an action?
- filter()
2. collect()
3. show()
4. count()
Correct Answer: 1. filter()
Explanation:
filter() is a transformation because it creates a new logical dataset from an existing DataFrame without immediately returning a final result to the driver. Spark transformations are evaluated lazily and are executed only when an action requires a result. count(), collect(), and show() are actions because they trigger execution of the transformations required to produce their output. Lazy evaluation allows Spark to optimize multiple transformations together before running the job.
Question 3.
What is the main purpose of Spark’s lazy evaluation model?
- To eliminate the need for executors
2. To force every transformation to run immediately
3. To delay all computations permanently
4. To allow Spark to optimize the execution plan before running it
Correct Answer: 4. To allow Spark to optimize the execution plan before running it
Explanation:
Spark evaluates transformations lazily, meaning that operations such as select(), filter(), and join() build a logical execution plan rather than immediately processing the data. When an action is called, Spark analyzes the accumulated transformations and can optimize the execution plan before performing the work. This approach can reduce unnecessary operations and improve performance. Lazy evaluation does not eliminate executors or permanently delay computations. Instead, it allows Spark to execute workloads more efficiently once a result is actually required.
Question 4.
Which DataFrame method is commonly used to select a subset of columns?
- count()
2. select()
3. cache()
4. repartition()
Correct Answer: 2. select()
Explanation:
select() is used to choose specific columns or expressions from a DataFrame. For example, selecting only customer_id and amount creates a new DataFrame containing those columns. cache() stores a DataFrame for potential reuse, count() returns the number of rows, and repartition() changes the number or distribution of partitions. select() is therefore the appropriate method when the objective is to project only certain columns from a structured dataset.
Question 5.
Which function can be used to add or replace a column in a Spark DataFrame?
- distinct()
2. union()
3. explain()
4. withColumn()
Correct Answer: 4. withColumn()
Explanation:
withColumn() creates a new DataFrame by adding a new column or replacing an existing column with an expression. It is frequently used for calculations, type conversions, conditional logic, and derived fields. distinct() removes duplicate rows, union() combines rows from compatible DataFrames, and explain() displays information about the query execution plan. Because Spark DataFrames are immutable, withColumn() returns a new DataFrame rather than modifying the original one in place.
Question 6.
Which Spark function should be used to remove duplicate rows from a DataFrame?
- persist()
2. orderBy()
3. dropDuplicates()
4. repartition()
Correct Answer: 3. dropDuplicates()
Explanation:
dropDuplicates() removes duplicate rows from a DataFrame and can optionally consider only selected columns when determining duplicates. This is useful during data-cleaning workflows when repeated records must be eliminated. repartition() changes data partitioning, orderBy() sorts rows, and persist() stores computed data for reuse. Removing duplicates is a data-transformation operation, so Spark returns a new DataFrame containing the deduplicated records.
Question 7.
What does the collect() action do in Spark?
- Writes all rows directly to storage
2. Sends all rows of the result to the driver
3. Automatically repartitions the DataFrame
4. Creates additional executor nodes
Correct Answer: 2. Sends all rows of the result to the driver
Explanation:
collect() triggers computation and returns all result rows to the driver process. This can be useful for small datasets, but it should be used carefully because a large result can exceed driver memory. collect() does not automatically write data to storage, create executors, or repartition the DataFrame. When only a sample or limited number of rows is needed, operations such as show(), take(), or limit() may be safer than collecting a very large distributed dataset.
Question 8.
Which operation commonly causes a shuffle in Spark?
- groupBy() followed by aggregation
2. renaming a column
3. select() of an existing column
4. filter() on a single partition
Correct Answer: 1. groupBy() followed by aggregation
Explanation:
groupBy() operations commonly require Spark to redistribute records so that rows sharing the same grouping key are processed together. This redistribution is called a shuffle and may involve significant network and disk activity. Operations such as selecting existing columns or renaming columns usually do not require a shuffle. Because shuffles can be expensive, understanding when they occur is important when optimizing Spark workloads and diagnosing performance issues.
Question 9.
Which method is used to inspect the logical and physical execution plans for a DataFrame query?
- checkpoint()
2. collect()
3. describe()
4. explain()
Correct Answer: 4. explain()
Explanation:
explain() displays information about how Spark plans to execute a DataFrame query. Depending on the options used, it can show logical and physical plans and provide insight into joins, scans, filters, exchanges, and other execution details. This is useful for understanding optimization behavior and diagnosing inefficient plans. describe() produces summary statistics for columns, collect() returns rows to the driver, and checkpoint() truncates lineage by materializing data to checkpoint storage.
Question 10.
Which join returns only rows whose join keys match in both DataFrames?
- Full outer join
2. Inner join
3. Left anti join
4. Left outer join
Correct Answer: 2. Inner join
Explanation:
An inner join returns only records with matching join conditions in both DataFrames. Rows without a corresponding match on the opposite side are excluded. A left outer join keeps every row from the left side, while a full outer join keeps unmatched rows from both sides. A left anti join returns rows from the left side that do not have matches on the right. Inner joins are commonly used when only intersecting records are required.
Question 11.
Which join type returns rows from the left DataFrame that have no match in the right DataFrame?
- Left anti join
2. Inner join
3. Cross join
4. Left semi join
Correct Answer: 1. Left anti join
Explanation:
A left anti join returns rows from the left DataFrame for which no matching row exists in the right DataFrame. This is useful for identifying missing records, unmatched identifiers, or new entities not present in a reference dataset. A left semi join returns left-side rows that do have a match, while an inner join returns matched rows from both sides. A cross join produces the Cartesian product of the two datasets and serves a completely different purpose.
Question 12.
Which DataFrame operation is most appropriate for changing a column from string type to integer type?
- cache()
2. coalesce()
3. cast()
4. union()
Correct Answer: 3. cast()
Explanation:
cast() converts a column expression from one data type to another. For example, a numeric string can be cast to an integer when the values are valid for that conversion. cache() stores computed results for reuse, coalesce() generally reduces the number of partitions, and union() combines rows from compatible DataFrames. Type conversion is common when loading semi-structured or text-based data whose inferred schema does not match the types required for downstream processing.
Question 13.
What is the primary purpose of cache() in Spark?
- To keep computed data available for reuse across actions
2. To permanently save a DataFrame to external storage
3. To remove duplicate rows
4. To force all data into one partition
Correct Answer: 1. To keep computed data available for reuse across actions
Explanation:
cache() marks a dataset so that computed partitions can be retained and reused by subsequent actions rather than recomputed from the complete lineage each time. This can improve performance when the same expensive DataFrame is accessed repeatedly. Caching is not the same as permanently writing data to external storage. It also does not remove duplicates or force the dataset into a single partition. Caching is most beneficial when reused data is expensive to recompute and sufficient cluster resources are available.
Question 14.
Which method generally reduces the number of partitions without performing a full shuffle when possible?
- groupBy()
2. coalesce()
3. distinct()
4. repartition()
Correct Answer: 2. coalesce()
Explanation:
coalesce() is commonly used to reduce the number of partitions while avoiding a full shuffle when possible. This can make it less expensive than repartition() when decreasing partitions. repartition() can increase or decrease partitions and generally performs a shuffle to redistribute data more evenly. groupBy() and distinct() can also trigger shuffles for different reasons. coalesce() is particularly useful when reducing partition count before writing smaller numbers of output files.
Question 15.
What is a key difference between repartition() and coalesce()?
- coalesce() always increases partitions
2. repartition() never moves data between executors
3. repartition() can increase or decrease partitions and generally performs a shuffle
4. coalesce() converts DataFrames into RDDs
Correct Answer: 3. repartition() can increase or decrease partitions and generally performs a shuffle
Explanation:
repartition() can increase or decrease the number of partitions and generally performs a full shuffle to redistribute data. This can create a more balanced partition layout but may be relatively expensive. coalesce() is commonly used when reducing partitions and tries to minimize data movement. Neither operation converts DataFrames to RDDs. Understanding the difference is useful when tuning parallelism, addressing skew, or controlling the number of files generated when writing output.
Question 16.
Which Spark SQL function is commonly used to calculate the number of rows within each group?
- explode()
2. lit()
3. monotonically_increasing_id()
4. count()
Correct Answer: 4. count()
Explanation:
count() is commonly used as an aggregation function after groupBy() to calculate the number of records in each group. For example, grouping transactions by customer and applying count() returns the number of transactions for each customer. explode() expands array or map values into multiple rows, lit() creates a literal column expression, and monotonically_increasing_id() generates unique increasing identifiers that are not necessarily consecutive. count() is therefore the appropriate aggregation for measuring group frequency.
Question 17.
Which function is commonly used to turn each element of an array column into a separate row?
- collect_list()
2. explode()
3. concat()
4. struct()
Correct Answer: 2. explode()
Explanation:
explode() expands an array or map column so that each contained element becomes a separate output row. This is useful when nested data needs to be normalized before filtering, aggregation, or joining. concat() combines values, collect_list() aggregates values into an array, and struct() creates a nested structure from multiple expressions. explode() is therefore the appropriate function when one row containing an array must be expanded into multiple rows.
Question 18.
What happens when union() is applied to two compatible Spark DataFrames?
- Both DataFrames are converted to local pandas DataFrames
2. Duplicate rows are always removed automatically
3. Rows from the second DataFrame are appended to rows from the first
4. Columns are joined based on a key
Correct Answer: 3. Rows from the second DataFrame are appended to rows from the first
Explanation:
union() combines the rows of two compatible DataFrames into a new DataFrame. It does not automatically remove duplicate rows, so duplicate records can remain in the result. If duplicate removal is required, an additional distinct() or dropDuplicates() transformation can be applied. union() is not a relational join and does not match records using a key. It also does not convert Spark DataFrames into pandas objects. The operation is intended for vertically combining datasets with compatible schemas.
Question 19.
Which expression is appropriate for creating a new column containing the same constant value for every row?
- broadcast()
2. countDistinct()
3. lit()
4. explode()
Correct Answer: 3. lit()
Explanation:
lit() creates a literal column expression containing a constant value. It is commonly used with withColumn() or select() when every row should receive the same value, such as a processing date, source-system label, or fixed status. explode() expands arrays or maps, countDistinct() calculates the number of unique values during aggregation, and broadcast() is associated with distributing small data efficiently for operations such as joins. lit() is therefore the appropriate function for constructing a constant-valued column.
Question 20.
When joining a very large DataFrame with a sufficiently small DataFrame, which optimization can reduce shuffle cost?
- Collect the large DataFrame to the driver
2. Convert both DataFrames to one partition
3. Apply distinct() to every column first
4. Broadcast the small DataFrame
Correct Answer: 4. Broadcast the small DataFrame
Explanation:
Broadcasting a sufficiently small DataFrame can improve join performance by sending a copy of the small dataset to each executor. This can avoid shuffling the much larger dataset across the cluster and can significantly reduce network overhead. Collecting a large DataFrame to the driver may cause memory problems, while forcing all data into one partition eliminates useful parallelism. Applying distinct() unnecessarily can introduce additional expensive processing. Broadcast joins are therefore a useful optimization when one side of the join is small enough to distribute efficiently.