DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #66
Which of the following operations performs a cross join on two DataFrames?
The correct answer is D. DataFrame.crossJoin(). DataFrame.crossJoin() is the correct method for performing a cross join (Cartesian product) in PySpark - it's an instance method called directly on a DataFrame, e.g., df1.crossJoin(df2), and returns every combination of rows between the two DataFrames. Why the distractors are…
Question
Which of the following operations performs a cross join on two DataFrames?
Options
- ADataFrame.join()
- BThe standalone join() function
- CThe standalone crossJoin() function
- DDataFrame.crossJoin()
- EDataFrame.merge()
How the community answered
(23 responses)- A9% (2)
- C4% (1)
- D87% (20)
Explanation
DataFrame.crossJoin() is the correct method for performing a cross join (Cartesian product) in PySpark - it's an instance method called directly on a DataFrame, e.g., df1.crossJoin(df2), and returns every combination of rows between the two DataFrames.
Why the distractors are wrong:
- A.
DataFrame.join()- performs conditional joins (inner, left, right, outer) using a specified condition or key column, not a cross join by default. - B. Standalone
join()function - no such standalone function exists in PySpark's DataFrame API for this purpose. - C. Standalone
crossJoin()function -crossJoinis not a standalone function; it only exists as a method on a DataFrame instance. - E.
DataFrame.merge()- this is a pandas method; PySpark DataFrames do not have amerge()method.
Memory tip: Think "cross is personal" - the cross join belongs to the DataFrame object itself (df.crossJoin()), not to any standalone function. If you remember that PySpark uses instance methods for joins, you can eliminate B and C immediately.
Topics
Community Discussion
No community discussion yet for this question.