Skip to content

Instantly share code, notes, and snippets.

@TomLous
Created June 13, 2017 14:29
Show Gist options
  • Select an option

  • Save TomLous/ae2c14633ab1df4349eb7595c988e84b to your computer and use it in GitHub Desktop.

Select an option

Save TomLous/ae2c14633ab1df4349eb7595c988e84b to your computer and use it in GitHub Desktop.
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.from_unixtime
val spark = SparkSession.builder()
.master("local[2]")
.appName("test")
.getOrCreate()
import spark.implicits._
val input = List(
("a",1497348453L),
("b",1497345453L),
("c",1497341453L),
("d",1497340453L)
).toDF("name", "timestamp")
input.select(
'name,
from_unixtime('timestamp, "yyyy.MM.dd.HH.mm.ss").alias("timestamp_formatted")
).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment