QuestionQ238

VerifiedUsing Spark SQL

The following code block must return a DataFrame that contains an openDateString column, which is a string representation using Java’s SimpleDateFormat. Choose the response that correctly completes the numbered blanks in the code block.

Note that the openDate column is an integer representing a UNIX-epoch date—the number of seconds since midnight on January 1, 1970.

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

A sample of storesDF is shown below:

Question Image

Code block:

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

withColumn returns a DataFrame with a new column, while from_unixtime converts seconds since the Unix epoch to a formatted timestamp string. Passing col("openDate") supplies the epoch-seconds column, and EEEE, MMM d, yyyy h:mm a formats a full weekday, abbreviated month, day, year, 12-hour clock time, minutes, and AM/PM marker.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!