
Answer-first summary for fast verification
Answer: 1.`spark` 2. `createDataset` 3. `years` 4. `toDF()`
**Correct Answer: B** * **Why B is correct:** In Scala, `spark.createDataset(years)` takes a local collection and turns it into a `Dataset[Int]`. Appending `.toDF()` converts that Dataset into a `DataFrame` (equivalent to `Dataset[Row]`). This is the standard pipeline for converting local Scala data into a Spark DataFrame. * **Why A & D are wrong:** `spark.createDataFrame` typically requires a `List` of **Rows** and a defined **Schema**. It cannot directly convert a `List[Int]` without additional boilerplate code. * **Why C is wrong:** Because `years` is already a list, `List(years)` creates a **nested** list. Spark would interpret this as a single record containing an array, rather than multiple records (rows) of integers.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Create a single-column DataFrame from a Scala list of integers named years by correctly filling in the numbered blanks in the following code block:
Code block:
1.2(3).4
A
1.spark 2. createDataFrame 3. years 4. toDF
B
1.spark 2. createDataset 3. years 4. toDF()
C
1.spark 2. createDataset 3. List(years) 4. toDF()
D
1.spark 2. createDataFrame 3. years 4. IntegerType