QuestionQ74

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

Which code block returns a DataFrame that contains a month column—an integer representation of the month derived from the openDate column in the storesDF DataFrame?

The openDate column has integer type and represents a UNIX-epoch date: the number of seconds since midnight on January 1st, 1970.

A sample of storesDF appears below:

Question Image

Explanation

A Unix-epoch value expressed in seconds must be interpreted as a timestamp before its calendar month can be extracted. Casting openDate to Timestamp performs that conversion, and month() returns the timestamp’s month as an integer. Spark documents that month returns the month component of a date or timestamp, and that epoch seconds can be converted to a timestamp.

Learn more

Community Discussion

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