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

The code block shown below should return a DataFrame containing a column openDateString, a string representation of Java’s SimpleDateFormat. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.

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.

An example of Java’s SimpleDateFormat is "Sunday, Dec 4, 2008 1:05 pm".

A sample of storesDF is displayed below:

Code block:

storesDF.__1__("openDateString", __2__(__3__, __4__))

    Correct Answer: A

    To convert the UNIX epoch time to a formatted date string in the DataFrame, the code needs to add a new column 'openDateString' by using the 'withColumn' function. The 'from_unixtime' function converts the integer format epoch time to a readable timestamp, and the 'SimpleDateFormat' pattern 'EEEE, MMM d, yyyy h:mm a' ensures the date format is as specified. The components 'col(

Discussion
Sowwy1Option: A

A. 1. withColumn 2. from_unixtime 3. col("openDate") 4. “EEEE, MMM d, yyyy h:mm a"