Last active
December 20, 2015 20:57
-
-
Save zezutom/24c87900224969edc9d3 to your computer and use it in GitHub Desktop.
A list of commonly used words as a broadcast variable
This file contains 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
class TextAnalyser(val sc: SparkContext, ...) { | |
... | |
// Instance variable | |
val _commonWords = sc.broadcast(TextAnalyser.loadCommonWords()) | |
... | |
// In a worker thread | |
def analyse(rdd: RDD[String]): TextStats = { | |
// To prevent the whole class to be 'sucked' into serialization | |
val commonWords = _commonWords | |
... | |
// Like accumulators a Broadcast is a wrapper, the 'value' method provides access to the actual data. | |
.filter(!commonWords.value.contains(_)) // Filter out all too common words | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment