Skip to Content

Databricks Certified Associate Developer for Apache Spark: Return new DataFrame result of inner join between DataFrame storesDF and DataFrame employeesDF.

Question

The code block shown below contains an error. The code block intended to return a new DataFrame that is the result of an inner join between DataFrame storesDF and DataFrame employeesDF on column storeId. Identify the error.

Code block:

StoresDF.join(employeesDF, "inner", "storeID")

A. The key column storeID needs to be wrapped in the col() operation.
B. The key column storeID needs to be in a list like [“storeID”].
C. The key column storeID needs to be specified in an expression of both DataFrame columns like storesDF.storeId == employeesDF.storeId.
D. There is no DataFrame.join() operation – DataFrame.merge() should be used instead.
E. The column key is the second parameter to join() and the type of join in the third parameter to join() – the second and third arguments should be switched.

Answer

E. The column key is the second parameter to join() and the type of join in the third parameter to join() – the second and third arguments should be switched.

Explanation

The correct answer is E. The column key is the second parameter to join() and the type of join in the third parameter to join() – the second and third arguments should be switched. Here is a detailed explanation:

E. The column key is the second parameter to join() and the type of join in the third parameter to join() – the second and third arguments should be switched.

This is true because the join() operation of DataFrames uses standard SQL semantics for join operations. The syntax of the join() operation is as follows:

join(other, on=None, how=None)

where other is another DataFrame, on is a column name or a list of column names, and how is a string specifying the type of join. The code block shown in the question has the on and how arguments in reverse order, which will cause an error. The correct code block should be:

StoresDF.join(employeesDF, “storeID”, “inner”)

A. The key column storeID needs to be wrapped in the col() operation. This is false because the col() operation is not necessary when specifying a single column name or a list of column names as the on argument. The col() operation is used to create a Column object that can be used for expressions or conditions.

B. The key column storeID needs to be in a list like [“storeID”]. This is false because the on argument can accept either a single column name or a list of column names. Both forms are equivalent when joining on a single column.

C. The key column storeID needs to be specified in an expression of both DataFrame columns like storesDF.storeId == employeesDF.storeId. This is false because this form of expression is only needed when joining on multiple columns or when using different column names in each DataFrame. When joining on a single column with the same name in both DataFrames, it is sufficient to use the column name as the on argument.

D. There is no DataFrame.join() operation – DataFrame.merge() should be used instead. This is false because there is a DataFrame.join() operation in PySpark that performs SQL-style joins on DataFrames. DataFrame.merge() is a pandas operation that performs similar functionality but with different syntax and options.

Reference

Databricks Certified Associate Developer for Apache Spark certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Databricks Certified Associate Developer for Apache Spark exam and earn Databricks Certified Associate Developer for Apache Spark certification.