Certified Associate Developer for Apache Spark Practice Test

Certified Associate Developer for Apache Spark Practice Test practice questions, page 5 of 14, with answer review and explanations.

Question 21

Which of the following code blocks returns a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000 OR the value in column customerSatisfaction is greater than or equal to 30?

  1. storesDF.filter(col("sqft") <= 25000 | col("customerSatisfaction") >= 30)
  2. storesDF.filter(col("sqft") <= 25000 or col("customerSatisfaction") >= 30)
  3. storesDF.filter(sqft <= 25000 or customerSatisfaction >= 30)
  4. storesDF.filter(col(sqft) <= 25000 | col(customerSatisfaction) >= 30)
  5. storesDF.filter((col("sqft") <= 25000) | (col("customerSatisfaction") >= 30))

Question 22

Which of the following code blocks returns a new DataFrame from DataFrame storesDF where column storeId is of the type string?

  1. storesDF.withColumn("storeId, cast(col("storeId"), StringType()))
  2. storesDF.withColumn("storeId, col("storeId").cast(StringType()))
  3. storesDF.withColumn("storeId, cast(storeId).as(StringType)
  4. storesDF.withColumn("storeId, col(storeId).cast(StringType)
  5. storesDF.withColumn("storeId, cast("storeId").as(StringType()))

Question 23

Which of the following code blocks returns a new DataFrame with a new column employeesPerSqft that is the quotient of column numberOfEmployees and column sqft, both of which are from DataFrame storesDF? Note that column employeesPerSqft is not in the original DataFrame storesDF.

  1. storesDF.withColumn("employeesPerSqft", col("numberOfEmployees") / col("sqft"))
  2. storesDF.withColumn("employeesPerSqft", "numberOfEmployees" / "sqft")
  3. storesDF.select("employeesPerSqft", "numberOfEmployees" / "sqft")
  4. storesDF.select("employeesPerSqft", col("numberOfEmployees") / col("sqft"))
  5. storesDF.withColumn(col("employeesPerSqft"), col("numberOfEmployees") / col("sqft"))

Question 24

The code block shown below should return a new DataFrame from DataFrame storesDF where column modality is the constant string "PHYSICAL", Assume DataFrame storesDF is the only defined language variable. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block: storesDF. _1_(_2_,_3_(_4_))

  1. 1. withColumn 2. "modality" 3. col 4. "PHYSICAL"
  2. 1. withColumn 2. "modality" 3. lit 4. PHYSICAL
  3. 1. withColumn 2. "modality" 3. lit 4. "PHYSICAL"
  4. 1. withColumn 2. "modality" 3. SrtringType 4. "PHYSICAL"
  5. 1. newColumn 2. modality 3. SrtringType 4. PHYSICAL

Question 25

Which of the following code blocks returns a DataFrame where column storeCategory from DataFrame storesDF is split at the underscore character into column storeValueCategory and column storeSizeCategory? A sample of DataFrame storesDF is displayed below:

  1. (storesDF.withColumn("storeValueCategory", split(col("storeCategory"), "_")[1]) .withColumn("storeSizeCategory", split(col("storeCategory"), "_")[2]))
  2. (storesDF.withColumn("storeValueCategory", col("storeCategory").split("_")[0]) .withColumn("storeSizeCategory", col("storeCategory").split("_")[1]))
  3. (storesDF.withColumn("storeValueCategory", split(col("storeCategory"), "_")[0]) .withColumn("storeSizeCategory", split(col("storeCategory"), "_")[1]))
  4. (storesDF.withColumn("storeValueCategory", split("storeCategory", "_")[0]) .withColumn("storeSizeCategory", split("storeCategory", "_")[1]))
  5. (storesDF.withColumn("storeValueCategory", col("storeCategory").split("_")[1]) .withColumn("storeSizeCategory", col("storeCategory").split("_")[2]))