nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #84

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…

The correct answer is E. storesDF.union(acquiredStoresDF). storesDF.union(acquiredStoresDF) is the correct PySpark syntax because union() is an instance method on a DataFrame object that performs a position-wise row combination - equivalent to SQL's UNION ALL. Why the distractors fail: A & C - concat() and union() as standalone…

DataFrame Transformations and Operations

Question

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.

Options

  • Aconcat(storesDF, acquiredStoresDF)
  • BstoresDF.unionByName(acquiredStoresDF)
  • Cunion(storesDF, acquiredStoresDF)
  • DunionAll(storesDF, acquiredStoresDF)
  • EstoresDF.union(acquiredStoresDF)

How the community answered

(45 responses)
  • B
    2% (1)
  • C
    2% (1)
  • D
    4% (2)
  • E
    91% (41)

Explanation

storesDF.union(acquiredStoresDF) is the correct PySpark syntax because union() is an instance method on a DataFrame object that performs a position-wise row combination - equivalent to SQL's UNION ALL.

Why the distractors fail:

  • A & C - concat() and union() as standalone functions don't exist in PySpark's DataFrame API; concat is a string/array column function, not a DataFrame-level one.
  • B - unionByName() is a real PySpark method, but it matches columns by name, not by position - the wrong behavior for this task.
  • D - unionAll() was the original method but was deprecated in Spark 2.0 and replaced by union(); calling it as a standalone function is doubly wrong.

Memory tip: In PySpark, DataFrame operations are almost always method calls on an existing DataFrame (df.someOperation()), not standalone functions. If you see a union operation written without a DataFrame receiver (like options A, C, D), it's a red flag.

Topics

#DataFrame union operations#Position-wise union#Apache Spark#DataFrame API

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice