Databricks Certified Associate Developer for Apache Spark — Question 42

The code block shown below contains an error. The code block is intended to return a new DataFrame that is the result of a position-wise union between DataFrame storesDF and DataFrame acquiredStoresDF. Identify the error.
Code block:
storesDF.unionByName(acquiredStoresDF)

Answer options

Correct answer: C

Explanation

The correct answer is C because the unionByName() function merges DataFrames based on matching column names rather than their positions. Option A is incorrect because unionByName() is a valid operation. Options B and E are wrong as the function does not require key columns or column positions. Option D is also incorrect since unionByName() is a method of DataFrame, not a standalone operation.