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'…
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)- A87% (40)
- B4% (2)
- C2% (1)
- E7% (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
Community Discussion
No community discussion yet for this question.