Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 102


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__.__3__[Int](__4__)

Show Answer
Correct Answer: AD

To extract the integer value for column sqft from the first row of the DataFrame storesDF, we need to use the first() method to retrieve the first row as a Row object, then use the getAs method to access the value of the column. The correct code sequence is storesDF.first().getAs[Int]("sqft"), where storesDF is the DataFrame, first() retrieves the first row, getAs retrieves the value by column name, and "sqft" is the name of the column.

Discussion

4 comments
Sign in to comment
cookiemonster42Option: D
Aug 2, 2023

correct. we can use first and first() interchangeably, getAs works as getAs[int]("col_name")

thanabOption: A
Sep 7, 2023

A A is correct. D is incorrect. Option D is incorrect because it uses the first method without parentheses. The first method is a method of a DataFrame and must be called with parentheses to return the first row of the DataFrame. Here’s the corrected code block: ``` storesDF.first().getAsInt ```

carlosmps
Jun 22, 2024

on scala works

carlosmps
Jun 22, 2024

the using of first without parentheses

Sowwy1Option: D
Apr 6, 2024

This is part of the official databricks exam samples. This is the correct answer: D.1. storesDF 2. first 3. getAs 4. "sqft"

newusername
Nov 9, 2023

could anyone show working test case ?