feat:首次提交
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.example.spark
|
||||
|
||||
import org.apache.spark.{SparkConf, SparkContext}
|
||||
|
||||
object App {
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
val sparkConf = new SparkConf()
|
||||
.setMaster("local[2]")
|
||||
.setAppName("scala spark app")
|
||||
.set("spark.driver.host", "127.0.0.1")
|
||||
.set("spark.driver.bindAddress", "127.0.0.1")
|
||||
|
||||
val sc = new SparkContext(sparkConf)
|
||||
|
||||
val textFile = sc.textFile("src/main/resources/word.txt")
|
||||
|
||||
println(textFile.count())
|
||||
|
||||
val me = textFile.filter(line => line.contains("me"))
|
||||
println("me.collect() = " + me.collect().mkString(","))
|
||||
|
||||
val value = textFile
|
||||
.flatMap(_.split(" "))
|
||||
.map((_, 1))
|
||||
.reduceByKey(_+_)
|
||||
|
||||
println(value.collect().mkString("\n"))
|
||||
|
||||
|
||||
sc.stop()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.example.spark
|
||||
|
||||
import org.apache.spark.{SparkConf, SparkContext}
|
||||
|
||||
object test {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val sc = new SparkContext(new SparkConf()
|
||||
.setMaster("local")
|
||||
.setAppName("test")
|
||||
.set("spark.driver.host", "127.0.0.1")
|
||||
.set("spark.driver.bindAddress", "127.0.0.1"))
|
||||
sc.textFile("src/main/resources/word.txt").foreach(println)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user