1.什么是Spark

视频教程链接:

尚硅谷Spark从入门到精通:https://www.bilibili.com/video/BV11A411L7CK?p=90&spm_id_from=pageDriver

尚硅谷Spark性能调优:https://www.bilibili.com/video/BV1QY411x7xL

Spark简介

官方网站:

https://spark.apache.org/docs/1.3.1/

1.什么是Spark?

这里直接引用官网的介绍:

Spark是一个统一的大规模数据分析引擎

img

2.为什么Spark如此流行?

  • 速度快
  • 使用简单
  • 通用性
    • img
  • 运行在任何地方

3.Spark的组成

img

SparkCore作为核心处理引擎,在此之上支持:

  • Spark SQL:SQL处理数据集
  • SparkStreaming:流式处理
  • Mlib:机器学习
  • GraphX:支持图计算

4.开箱即用

文档准备:

[root@cloud-3 spark]# vim /tmp/words.txt 
hello me you her
hello me you
hello me
hello

代码编写:

scala> val textFile = sc.textFile("file:///tmp/words.txt")
textFile: org.apache.spark.rdd.RDD[String] = file:///tmp/words.txt MapPartitionsRDD[1] at textFile at <console>:23

scala> val counts = textFile.flatMap(_.split(" ")).map(_,1).reduceByKey(_+_)
<console>:23: error: missing parameter type for expanded function ((x$2: <error>) => textFile.flatMap(((x$1) => x$1.split(" "))).map(x$2, 1).reduceByKey(((x$3, x$4) => x$3.$plus(x$4))))
       val counts = textFile.flatMap(_.split(" ")).map(_,1).reduceByKey(_+_)
                                                       ^

scala> val counts = textFile.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_)
counts: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[4] at reduceByKey at <console>:23

scala> counts.collect
res0: Array[(String, Int)] = Array((hello,4), (me,3), (you,2), (her,1))         


[(String, Int)] = Array((hello,4), (me,3), (you,2), (her,1))         

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值