QuestionQ80

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

Which of the following code blocks returns a DataFrame with a month column containing an integer representation of the day of the year from the openDate column in the storesDF DataFrame?

Note that openDate has integer type and represents a UNIX-epoch date format—the number of seconds since midnight on January 1st, 1970.

A sample of storesDF appears below:

Question Image

Code block:

stored.withColumn(“openTimestamp”, col(“openDate”).cast(__1__))  
.withColumn(__2__, __3__(__4__))  
Explanation

Spark SQL accepts Timestamp as a timestamp type name. withColumn takes a string column name and a column expression; month(col("openTimestamp")) extracts the month component of a timestamp as an integer, so the resulting column must be named "month".

Learn more

Community Discussion

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