首页 > 其他 > 详细

Spark操作

时间:2017-10-14 23:55:37      阅读:392      评论:0      收藏:0      [点我收藏+]
### scala源码
/* SimpleApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.log4j.Logger
import org.apache.log4j.Level

object SimpleApp {
  def main(args: Array[String]) {
    // stop spark console messaging
    Logger.getLogger("org").setLevel(Level.OFF)
    Logger.getLogger("akka").setLevel(Level.OFF)
    
    val logFile = "/data/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))
  }
}

### sbt打包
sbt package

### 将文件put到hdfs
su - hdfs
hdfs dfs -mkdir -p /data/spark/
hdfs dfs -chmod -R 777 /data/spark/
exit
hdfs dfs -put /usr/hdp/2.6.0.3-8/spark/README.md /usr/hdp/2.6.0.3-8/spark/README.md

### 提交spark任务
spark-submit     --class "SimpleApp"     --master local[4]      /root/_learn/scala/target/scala-2.10/simple-project_2.10-1.0.jar

 

Spark操作

原文:http://www.cnblogs.com/chenzechao/p/7668998.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!