DatabricksDatabricks
DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #175
DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Question #175: Real Exam Question with Answer & Explanation
The correct answer is D: (storesDF.withColumn("openTimestamp", col("openDate").cast("Timestamp")). See the full explanation below for the reasoning.
Transforming and manipulating data within Spark DataFrames, specifically handling date and time data types by converting UNIX epoch to a timestamp.
Question
Which of the following code blocks returns a DataFrame containing a column month, an integer representation of the month from column openDate from DataFrame storesDF? 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 1 st, 1970. A sample of storesDF is displayed below:
Options
- AstoresDF.withColumn("month", getMonth(col("openDate")))
- BstoresDF.withColumn("month", substr(col("openDate"), 4, 2))
- C(storesDF.withColumn("openDateFormat", col("openDate").cast("Date"))
- D(storesDF.withColumn("openTimestamp", col("openDate").cast("Timestamp"))
- EstoresDF.withColumn("month", month(col("openDate")))
Topics
#Spark DataFrames#Date/Time Functions#Type Casting#UNIX Epoch
Community Discussion
No community discussion yet for this question.