Created
July 28, 2015 01:27
-
-
Save marcovivero/37fa531bf70a48a41436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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