标签:一个 vim 大数据 park import mic 用户 imp ring
学习于大数据原理与应用 第十六章 Spark 学习指南
三、独立应用程序编程
2.Scala应用程序代码
vim ./sparkapp/src/main/scala/SimpleApp.scala #在 ./sparkapp/src/main/scala 下建立一个名为 SimpleApp.scala 的文件,并添加如下代码
/* SimpleApp.scala */ import org.apache.spark.SparkContext import org.apache.spark.SparkContext._ import org.apache.spark.SparkConf object SimpleApp { def main(args: Array[String]) { val logFile = "file:///usr/local/spark/README.md" // Should be some file on your system val conf = new SparkConf().setAppName("Simple Application") val sc = new SparkContext(conf) val logData = sc.textFile(logFile, 2).cache() val numAs = logData.filter(line => line.contains("a")).count() val numBs = logData.filter(line => line.contains("b")).count() println("Lines with a: %s, Lines with b: %s".format(numAs, numBs)) } }
如图:
name := "Simple Project" version := "1.0" scalaVersion := "2.11.12" libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.4"
标签:一个 vim 大数据 park import mic 用户 imp ring
原文地址:https://www.cnblogs.com/my---world/p/12256665.html