Last active
February 27, 2016 19:45
-
-
Save oluies/9a2b7b220c9253b693c8 to your computer and use it in GitHub Desktop.
spark moving average
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
val schema = Seq("id", "cykle", "value") | |
val data = Seq( | |
(1, 1, 1), | |
(1, 2, 11), | |
(1, 3, 1), | |
(1, 4, 11), | |
(1, 5, 1), | |
(1, 6, 11), | |
(2, 1, 1), | |
(2, 2, 11), | |
(2, 3, 1), | |
(2, 4, 11), | |
(2, 5, 1), | |
(2, 6, 11) | |
) | |
val dft = sc.parallelize(data).toDF(schema: _*) | |
dft.select('*).show | |
// PARTITION BY id ORDER BY cykle ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING (5) | |
val w = Window.partitionBy("id").orderBy("cykle").rowsBetween(-2, 2) | |
val x = dft.select($"id",$"cykle",avg($"value").over(w)) | |
x.show |
Author
oluies
commented
Feb 27, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment