nerdexam
Databricks

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

Which of the following code blocks returns a new DataFrame that is the result of a cross join between DataFrame storesDF and DataFrame employeesDF?

The correct answer is A. storesDF.crossJoin(employeesDF). In PySpark, DataFrame.crossJoin(other) is the dedicated method for computing a Cartesian product (cross join) between two DataFrames. storesDF.crossJoin(employeesDF) produces every combination of rows from both DataFrames. Choice B uses storesDF.join(employeesDF, 'storeId'…

Performing DataFrame Transformations

Question

Which of the following code blocks returns a new DataFrame that is the result of a cross join between DataFrame storesDF and DataFrame employeesDF?

Options

  • AstoresDF.crossJoin(employeesDF)
  • BstoresDF.join(employeesDF, "storeId", "cross")
  • CcrossJoin(storesDF, employeesDF)
  • Djoin(storesDF, employeesDF, "cross")
  • EstoresDF.join(employeesDF, "cross")

How the community answered

(46 responses)
  • A
    87% (40)
  • B
    4% (2)
  • C
    2% (1)
  • E
    7% (3)

Explanation

In PySpark, DataFrame.crossJoin(other) is the dedicated method for computing a Cartesian product (cross join) between two DataFrames. storesDF.crossJoin(employeesDF) produces every combination of rows from both DataFrames. Choice B uses storesDF.join(employeesDF, 'storeId', 'cross'), which specifies a join key - cross joins by definition have no join condition. Choices C and D use standalone crossJoin() and join() functions that do not exist in the PySpark API. Choice E uses storesDF.join(employeesDF, 'cross'), which incorrectly passes the join type as the column argument.

Topics

#Spark DataFrame#Cross Join#DataFrame Transformations#PySpark/Scala Spark API

Community Discussion

No community discussion yet for this question.

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