QuestionQ180

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below must return a new DataFrame in which column productСategories contains only one word in each row, producing a DataFrame with many more rows than DataFrame storesDF. Choose the response that correctly fills the numbered blanks in the code block to complete this task.

A sample of storesDF is shown below:

Question Image

Code block:

storesDF.__1__(__2__, __3__(__4__(__5__)))

Explanation

The sample shows productCategories is already an array column (e.g. [netus, pellentes...]). To produce one element per row and many more rows, you explode that array. The stem requires the RESULT column to still be named productCategories, so the array column must be overwritten in place: storesDF.withColumn("productCategories", explode(col("productCategories"))). Option C is nearly identical but writes to a new column productCategory, leaving productCategories as the untouched array, so it fails the stated requirement. No split is needed because the data is an array, not a delimited string.

Learn more

Community Discussion

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