Free Databricks Certified Associate Developer for Apache Spark 3.0 Exam Braindumps
Certified Associate Developer for Apache Spark Questions 46–50 (page: 11)

Updated On: 9-Feb-2026

The code block displayed below contains an error. The code block below is intended to add a column itemNameElements to DataFrame itemsDf that includes an array of all words in column itemName. Find the error. Sample of DataFrame itemsDf:


Code block:
itemsDf.withColumnRenamed("itemNameElements", split("itemName")) itemsDf.withColumnRenamed("itemNameElements", split("itemName"))

  1. All column names need to be wrapped in the col() operator.
  2. Operator withColumnRenamed needs to be replaced with operator withColumn and a second argument "," needs to be passed to the split method.
  3. Operator withColumnRenamed needs to be replaced with operator withColumn and the split method needs to be replaced by the splitString method.
  4. Operator withColumnRenamed needs to be replaced with operator withColumn and a second argument " " needs to be passed to the split method.
  5. The expressions "itemNameElements" and split("itemName") need to be swapped.

Answer(s): D

Explanation:

Correct code block:
itemsDf.withColumn("itemNameElements", split("itemName"," ")) Output of code block:


The key to solving this Question: is that
the split method definitely needs a second argument here (also look at the link to the documentation below). Given the values in column itemName in DataFrame itemsDf, this should be a space character " ". This is the character we need to split the words in the column.

More info: pyspark.sql.functions.split — PySpark 3.1.1 documentation
Static notebook | Dynamic notebook: See test 1, Question: 46 (Databricks import instructions)



The code block shown below should return all rows of DataFrame itemsDf that have at least 3 items in column itemNameElements. Choose the answer that correctly fills the blanks in the code block to accomplish this.
Example of DataFrame itemsDf:

  1. 1. select
    2. count
    3. col("itemNameElements") 4. >3
  2. 1. filter
    2. count
    3. itemNameElements 4. >=3
  3. 1. select
    2. count
    3. "itemNameElements" 4. >3
  4. 1. filter
    2. size
    3. "itemNameElements" 4. >=3
  5. 1. select
    2. size
    3. "itemNameElements" 4. >3

Answer(s): D

Explanation:

Correct code block: itemsDf.filter(size("itemNameElements")>3) Output of code block:


The big difficulty with this Question: is in knowing the difference between count and size (refer to documentation below). size is the correct function to choose here since it returns the number of elements in an array on a per-row basis.
The other consideration for solving this Question: is the difference between select and filter. Since we want to return the rows in the original DataFrame, filter is the right choice. If we would use select, we would simply get a single-column DataFrame showing which rows match the criteria, like so:


More info:
Count documentation: pyspark.sql.functions.count — PySpark 3.1.1 documentation Size documentation: pyspark.sql.functions.size — PySpark 3.1.1 documentation
Static notebook | Dynamic notebook: See test 1, Question: 47 (Databricks import instructions)



The code block displayed below contains an error. The code block should use Python method find_most_freq_letter to find the letter present most in column itemName of DataFrame itemsDf and return it in a new column most_frequent_letter. Find the error. Code block:
1. find_most_freq_letter_udf = udf(find_most_freq_letter)
2. itemsDf.withColumn("most_frequent_letter", find_most_freq_letter("itemName"))

  1. Spark is not using the UDF method correctly.
  2. The UDF method is not registered correctly, since the return type is missing.
  3. The "itemName" expression should be wrapped in col().
  4. UDFs do not exist in PySpark.
  5. Spark is not adding a column.

Answer(s): A

Explanation:

Correct code block:
find_most_freq_letter_udf = udf(find_most_frequent_letter) itemsDf.withColumn("most_frequent_letter", find_most_freq_letter_udf("itemName"))
Spark should use the previously registered find_most_freq_letter_udf method here – but it is not doing that in the original codeblock. There, it just uses the non-UDF version of the Python method.
Note that typically, we would have to specify a return type for udf(). Except in this case, since the default return type for udf() is a string which is what we are expecting here. If we wanted to return an integer variable instead, we would have to register the Python function as UDF using find_most_freq_letter_udf = udf(find_most_freq_letter, IntegerType()).
More info: pyspark.sql.functions.udf — PySpark 3.1.1 documentation



Which of the following code blocks returns about 150 randomly selected rows from the 1000-row DataFrame transactionsDf, assuming that any row can appear more than once in the returned DataFrame?

  1. transactionsDf.resample(0.15, False, 3142)
  2. transactionsDf.sample(0.15, False, 3142)
  3. transactionsDf.sample(0.15)
  4. transactionsDf.sample(0.85, 8429)
  5. transactionsDf.sample(True, 0.15, 8261)

Answer(s): E

Explanation:

Answering this Question: correctly depends
on whether you understand the arguments to the DataFrame.sample() method (link to the documentation below). The arguments are as follows:
DataFrame.sample(withReplacement=None, fraction=None, seed=None).
The first argument withReplacement specified whether a row can be drawn from the DataFrame multiple times. By default, this option is disabled in Spark. But we have to enable it here, since the question asks for a row being able to appear more than once. So, we need to pass True for this argument.
About replacement: "Replacement" is easiest explained with the example of removing random items from a box. When you remove those "with replacement" it means that after you have taken an item out of the box, you put it back inside. So, essentially, if you would randomly take 10 items out of a box with 100 items, there is a chance you take the same item twice or more times. "Without replacement" means that you would not put the item back into the box after removing it. So, every time you remove an item from the box, there is one less item in the box and you can never take the same item twice.
The second argument to the withReplacement method is fraction. This referes to the fraction of items that should be returned. In the Question: we are asked for 150 out of 1000 items – a fraction of 0.15.
The last argument is a random seed. A random seed makes a randomized processed repeatable. This means that if you would re-run the same sample() operation with the same random seed, you would get the same rows returned from the sample() command. There is no behavior around the random seed specified in the question. The varying random seeds are only there to confuse you!

More info: pyspark.sql.DataFrame.sample — PySpark 3.1.1 documentation
Static notebook | Dynamic notebook: See test 1, Question: 49 (Databricks import instructions)



Which of the following code blocks returns a DataFrame where columns predError and productId are removed from DataFrame transactionsDf?
Sample of DataFrame transactionsDf:

  1. transactionsDf.withColumnRemoved("predError", "productId")
  2. transactionsDf.drop(["predError", "productId", "associateId"])
  3. transactionsDf.drop("predError", "productId", "associateId")
  4. transactionsDf.dropColumns("predError", "productId", "associateId")
  5. transactionsDf.drop(col("predError", "productId"))

Answer(s): D

Explanation:

The key here is to understand that columns that are passed to DataFrame.drop() are ignored if they do not exist in the DataFrame. So, passing column name associateId to transactionsDf.drop() does not have any effect.
Passing a list to transactionsDf.drop() is not valid. The documentation (link below) shows the call structure as DataFrame.drop(*cols). The * means that all arguments that are passed to DataFrame.drop() are read as columns. However, since a list of columns, for example ["predError", "productId", "associateId"] is not a column, Spark will run into an error.
More info: pyspark.sql.DataFrame.drop — PySpark 3.1.1 documentation Static notebook | Dynamic notebook: See test 1, Question: 50 ( Databricks import instructions)



Viewing page 11 of 37
Viewing questions 51 - 55 out of 342 questions


Post your Comments and Discuss Databricks Databricks Certified Associate Developer for Apache Spark 3.0 exam prep with other Community members:

AI Tutor AI Tutor 👋 I’m here to help!