Skip to content

Instantly share code, notes, and snippets.

@toff63
Created October 26, 2015 01:23
Show Gist options
  • Save toff63/0a583f94ff1f0a06c2c7 to your computer and use it in GitHub Desktop.
Save toff63/0a583f94ff1f0a06c2c7 to your computer and use it in GitHub Desktop.
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object SimpleApp {
def main(args:Array[String]) {
val logFile = "/mnt/home2/Documents/bin/spark-1.5.1-bin-hadoop2.6/README.md"
val conf = new SparkConf().setAppName("Simple App")
val sparkContext = new SparkContext(conf)
val logData = sparkContext.textFile(logFile,2).cache()
val numberOfAs = logData.filter(line => line.contains("a")).count
val numberOfBs = logData.filter(line => line.contains("b")).count
println(s"Lines with a: $numberOfAs , Lines with b: $numberOfBs ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment