Skip to content

Instantly share code, notes, and snippets.

@marcovivero
Created July 28, 2015 01:27
Show Gist options
  • Save marcovivero/37fa531bf70a48a41436 to your computer and use it in GitHub Desktop.
Save marcovivero/37fa531bf70a48a41436 to your computer and use it in GitHub Desktop.
def timePartition (
data: DataFrame,
timeCol : String,
outputCol : String,
startTime : Long = 1404198000000L
) : DataFrame = {
val addTime : Long = 604800000L // Discretize time into weeks.
val udf : UserDefinedFunction = functions.udf(
(t : Timestamp) => ((t.getTime - startTime) / addTime).toInt
)
data.withColumn(outputCol, udf(data(timeCol)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment