nerdexam
Databricks

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

The code block shown below should extract the integer value for column sqft from the first row of DataFrame storesDF. Choose the response that correctly fills in the numbered blanks within the code…

The correct answer is D. 1. storesDF. The code pattern __1__.__2__.__3__Int maps to storesDF.first().getAsInt. Here: first() retrieves the first Row object from the DataFrame, and getAsInt extracts the value of the sqft column from that Row, casting it to an integer. The type parameter [Int] is required to specify…

Work with Spark DataFrames

Question

The code block shown below should extract the integer value for column sqft from the first row of DataFrame storesDF. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:

1.2.3Int

Options

  • A
    1. storesDF
  • B
    1. storesDF
  • C
    1. storesDF
  • D
    1. storesDF

How the community answered

(34 responses)
  • A
    9% (3)
  • B
    3% (1)
  • C
    3% (1)
  • D
    85% (29)

Explanation

The code pattern __1__.__2__.__3__[Int](__4__) maps to storesDF.first().getAs[Int]("sqft"). Here: first() retrieves the first Row object from the DataFrame, and getAs[Int]("sqft") extracts the value of the sqft column from that Row, casting it to an integer. The type parameter [Int] is required to specify the return type at the call site. Option D is the only choice that correctly chains first(), then getAs[Int], passing the column name as a string argument.

Topics

#Spark DataFrame API#Scala#Row Object#Data Extraction

Community Discussion

No community discussion yet for this question.

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