nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #79

The code block shown below should create a single-column DataFrame from Scala list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the code…

The correct answer is A. 1. spark. The code pattern __1__.__2__(__3__).__4__ maps to spark.createDataset(years).toDF("year"). Here: spark is the SparkSession, createDataset(years) converts the Scala List[Int] into a typed Dataset[Int], and toDF("year") converts it into a single-column DataFrame with the column…

Working with DataFrames

Question

The code block shown below should create a single-column DataFrame from Scala list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:

1.2(3).4

Options

  • A
    1. spark
  • B
    1. spark
  • C
    1. spark
  • D
    1. spark

How the community answered

(24 responses)
  • A
    71% (17)
  • B
    17% (4)
  • C
    8% (2)
  • D
    4% (1)

Explanation

The code pattern __1__.__2__(__3__).__4__ maps to spark.createDataset(years).toDF("year"). Here: spark is the SparkSession, createDataset(years) converts the Scala List[Int] into a typed Dataset[Int], and toDF("year") converts it into a single-column DataFrame with the column named "year". Option A correctly uses createDataset() for a typed Scala collection followed by toDF() to assign the column name. Using createDataFrame() directly on a plain list requires additional wrapping (e.g., as a list of tuples).

Topics

#DataFrame Creation#SparkSession#Scala Collections#Data Transformation

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice