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

Certified Associate Developer for Apache Spark Exam - Question 88


The code block shown below contains an error. The code block intended to return a DataFrame containing a column dayOfYear, an integer representation of the day of the year from column openDate from DataFrame storesDF. Identify the error.

Note that column openDate is of type integer and represents a date in the UNIX epoch format – the number of seconds since midnight on January 1st, 1970.

A sample of storesDF is displayed below:

Code block:

storesDF.withColumn("dayOfYear", dayofyear(col("openDate")))

Show Answer
Correct Answer: A

The dayofyear() operation requires the input column to be of type Timestamp. Given that the openDate column in storesDF is of type integer which represents the number of seconds since the UNIX epoch, this column must first be converted to a Timestamp type before the dayofyear() function can accurately extract the day of the year.

Discussion

3 comments
Sign in to comment
kaisa1234
Sep 24, 2023

But question 50 is the same question and states that the code block with an error is the correct

newusername
Nov 9, 2023

the answer there is wrong. I posted the correct one.

newusernameOption: A
Nov 9, 2023

A is correct

tangerine141Option: A
Feb 23, 2024

A is correct