QuestionQ200

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

The code block below has an error. It is intended to return a new DataFrame resulting from an inner join of DataFrame storesDF and DataFrame employeesDF on the storeId column. Identify the error.

Code block:

StoresDF.join(employeesDF, Seq("storeId")  
Explanation

The Spark DataFrame API's join(right, usingColumns) overload expects the shared key column(s) to be passed as string literals (or a Seq[String] of literals) naming the column, for example Seq("storeId"). Supplying the column name as a bare, unquoted identifier causes the Scala compiler to try to resolve it as a variable reference rather than as a column name, which fails to compile. The fix is to wrap the key column name in quotes so it is treated as the string "storeId", matching the join-column-name overload of DataFrame.join().

Community Discussion

No comments yet. Be the first to start the discussion!