Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Certified Associate Developer for Apache Spark All Questions

View all questions & answers for the Certified Associate Developer for Apache Spark exam

Exam Certified Associate Developer for Apache Spark topic 1 question 143 discussion

Which of the following code blocks returns a DataFrame containing a column openDateString, a string representation of Java’s SimpleDateFormat?

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:

  • A. storesDF.withColumn("openDatestring", from unixtime(col("openDate“), “EEEE, MMM d, yyyy h:mm a"))
  • B. storesDF.withColumn("openDateString", from_unixtime(col("openDate“), "EEEE, MMM d, yyyy h:mm a", TimestampType()))
  • C. storesDF.withColumn("openDateString", date(col("openDate"), "EEEE, MMM d, yyyy h:mm a"))
  • D. storesDF.newColumn(col("openDateString"), from_unixtime("openDate", "EEEE, MMM d, yyyy h:mm a"))
  • E. storesDF.withColumn("openDateString", date(col("openDate“), "EEEE, MMM d, yyyy h:mm a", TimestampType))
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
oussa_ama
3 months ago
Selected Answer: A
pyspark.sql.functions.from_unixtime(timestamp: ColumnOrName, format: str = 'yyyy-MM-dd HH:mm:ss') → pyspark.sql.column.Column[source] Converts the number of seconds from unix epoch (1970-01-01 00:00:00 UTC) to a string representing the timestamp of that moment in the current system time zone in the given format.
upvoted 1 times
...
65bd33e
3 months, 1 week ago
Selected Answer: A
The correct code block that returns a DataFrame containing a column openDateString, which is a string representation of Java's SimpleDateFormat, is: A. storesDF.withColumn("openDatestring", from_unixtime(col("openDate"), "EEEE, MMM d, yyyy h:mm a")) This option correctly converts the openDate column from UNIX epoch format to a human-readable string format using the from_unixtime function in PySpark, which is equivalent to Java's SimpleDateFormat. The format "EEEE, MMM d, yyyy h:mm a" aligns with the example provided: "Sunday, Dec 4, 2008 1:05 pm".
upvoted 1 times
...
deadbeef38
5 months ago
Selected Answer: A
new column should be a String, existing column is Int
upvoted 1 times
...
Sowwy1
7 months, 2 weeks ago
A. storesDF.withColumn("openDatestring", from unixtime(col("openDate“), “EEEE, MMM d, yyyy h:mm a"))
upvoted 1 times
...
c3d91ee
8 months, 1 week ago
A is the right answer # Assuming you have a SparkSession created (replace with your setup if needed) from pyspark.sql import SparkSession from pyspark.sql.functions import from_unixtime # Sample data (replace with your actual DataFrame) data = [("store1", 1668518400), ("store2", 1668432000)] # Sample UNIX epoch timestamps df = spark.createDataFrame(data, ["storeName", "openDate"]) # Convert openDate to formatted string formatted_df = df.withColumn( "openDateString", from_unixtime(col("openDate"), "EEEE, MMM d, yyyy h:mm a") ) # Print the resulting DataFrame formatted_df.show(truncate=False) # Stop the SparkSession (optional) #spark.stop()
upvoted 2 times
...
azure_bimonster
9 months, 2 weeks ago
Selected Answer: B
B is likely tru, because A option has some typo issue and the underscore in from keyword is missing before unixtime, and the return type is not specified.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...