课程主要实用内容:

1.spark实验环境的搭建
2.4个lab的内容
3.常用函数
4.变量共享
 
1.spark实验环境的搭建(windows)
 

a. 下载,安装visualbox

管理员身份运行;课程要求最新版4.3.28,如果c中遇到虚拟机打不开的,可以用4.2.12,不影响

b. 下载,安装vagrant,重启

管理员身份运行

c. 下载虚拟机

c1.将vagrant加入path,D:\HashiCorp\Vagrant\bin

c2.创建虚拟机存放的目录,比如myvagrant

c3.下载文件mooc-setup-master.zip,解压后,拷贝Vagrantfile到myvagrant

c4.打开visual box图形界面,进入cmd,cd到myvagrant,敲命令   vagrant up

开始下载虚拟机,并打开,如果下载完成,但是打开虚拟机出错;

可以到visual box 图形界面点击打开,碰到一下错误,可尝试用4.2.12版visual box

使用说明:i.打开关闭虚拟机:打开visual box 界面,cd进入myvagrant

vagrant up 打开虚拟机,vagrant halt 关闭虚拟机

ii.ipython notebook,进入http:\\localhost:8001

停止正在运行的notebook,点击running,停止

点某 .py文件,运行note book

iii.下载ssh软件,可登入虚拟机,地址为127.0.0.1,端口2222,用户名vagrant,密码vagrant

进入后,敲pyspark,可进入pyspark交互式界面

3.常用函数

Spark中Rdd的生命周期

创建RDD(parallelize、textFile等)

对RDD进行变换

(会创建新的RDD,不会改变原RDD,有

1.对每个元素进行操作-map,flatMap,mapValues

2.筛选  filter

3.排序 sortBy

3.合并结果 reduceByKey,groupByKey

4.合并两个rdd union,join,leftJoin,rightJoin)

以上步骤中rdd都只相当于一个操作手册,并没有真实地在内存中产生数据,称为lazy evaluation

缓存rdd到内存中 cache() ,判断是否cache,访问 .is_cached属性

触发evaluation(包括top,take,takeOrdered,takeSample,sum,count,distinct,reduce,collect,collectAsMap)

4.变量共享

spark有两种变量共享方式

a.广播 broadcast,broadcast后的变量每个partition都会存储一份,但是只能读取,不能修改

>>> b=sc.broadcast([1,2,3,4,5])

>>> sc.parallelize([0,0]).flatMap(lambdax:b.value)

b.累加器 accumulator,只能写,不能在worker被读取

如果累加器只是一个标量,使用很简单

>>> rdd = sc.parallelize([1,2,3])
>>> def f(x):
... global a
...  a += x
>>> rdd.foreach(f)
>>> a.value
13

如果累加器是一个向量,需要定义AccumulatorParam,且zero方法和addInPlace都要实现

>>> from pyspark.accumulators import AccumulatorParam
>>> class VectorAccumulatorParam(AccumulatorParam):
...  def zero(self, value):
...  return [0.0] * len(value)
...  def addInPlace(self, val1, val2):
...  for i in xrange(len(val1)):
...  val1[i] += val2[i]
...  return val1
>>> va = sc.accumulator([1.0, 2.0, 3.0], VectorAccumulatorParam())
>>> va.value
[1.0, 2.0, 3.0]>>> defg(x):
... global va
... va += [x] * 3
>>> rdd.foreach(g)
>>> va.value
[7.0, 8.0, 9.0]

Introduction to Big Data with Apache Spark 课程总结的更多相关文章

  1. CS100.1x Introduction to Big Data with Apache Spark

    CS100.1x简介 这门课主要讲数据科学,也就是data science以及怎么用Apache Spark去分析大数据. Course Software Setup 这门课主要介绍如何编写和调试Py ...

  2. Introduction to Big Data with PySpark

    起因 大数据时代 大数据最近太热了,其主要有数据量大(Volume),数据类别复杂(Variety),数据处理速度快(Velocity)和数据真实性高(Veracity)4个特点,合起来被称为4V. ...

  3. Why Apache Spark is a Crossover Hit for Data Scientists [FWD]

    Spark is a compelling multi-purpose platform for use cases that span investigative, as well as opera ...

  4. Introducing DataFrames in Apache Spark for Large Scale Data Science(中英双语)

    文章标题 Introducing DataFrames in Apache Spark for Large Scale Data Science 一个用于大规模数据科学的API——DataFrame ...

  5. Using Apache Spark and MySQL for Data Analysis

    What is Spark Apache Spark is a cluster computing framework, similar to Apache Hadoop. Wikipedia has ...

  6. Apache Spark : Introduction

    看了一点<数据算法:Hadoop/Spark大数据处理技巧>,觉得有必要了解一下 Spark . 以上. Spark was introduced by Apache Software F ...

  7. 【译】Using .NET for Apache Spark to Analyze Log Data

    .NET for Spark可用于处理成批数据.实时流.机器学习和ad-hoc查询.在这篇博客文章中,我们将探讨如何使用.NET for Spark执行一个非常流行的大数据任务,即日志分析. 1 什么 ...

  8. Apache Spark源码走读之5 -- DStream处理的容错性分析

    欢迎转载,转载请注明出处,徽沪一郎,谢谢. 在流数据的处理过程中,为了保证处理结果的可信度(不能多算,也不能漏算),需要做到对所有的输入数据有且仅有一次处理.在Spark Streaming的处理机制 ...

  9. Spark(1) - Getting Started with Apache Spark

    Introduction Apache Spark is a general-purpose cluster computing system to process big data workload ...

随机推荐

  1. Android中退出多个Activity的两个经典方法

    这里介绍两种方法:一种把每个activity记住,然后逐一干掉:另一种思路是使用广播. 方法一.用list保存activity实例,然后逐一干掉 上代码: import java.util.Linke ...

  2. UESTC_Ferris Wheel String 2015 UESTC Training for Search Algorithm & String<Problem L>

    L - Ferris Wheel String Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 43000/43000KB (Java/ ...

  3. Jump Game II 解答

    Question Given an array of non-negative integers, you are initially positioned at the first index of ...

  4. C++ classics

    common Business-Oriented LanguageBASIC(Beginner's All-purpose Symbolic Instruction Code)1972 C1983 C ...

  5. 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago

    # #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...

  6. android之ListPreference的用法_PreferenceActivity用法

    首先,我们明确,preference是和数据存储相关的.        其次,它能帮助我们方便的进行数据存储!为什么这个地方一定要强调下方便的这个词呢?原因是,我们可以根本就不使用,我们有另外的N种办 ...

  7. weblogic8.1在myeclipse中启动正常,在单独的weblogic中无法正常启动的解决方案.

    应用程序服务器weblogic8.1.5,项目在myeclipse中启动正常,在单独的服务器中启动就报错了.错误如下图: 经过观察,发现在myeclipse中设置了以下的jar包.估计是这个问题引起的 ...

  8. ModelAndView解析

    查看spring的帮助文档得到下面信息: org.springframework.web.servlet Class ModelAndViewjava.lang.Object org.springfr ...

  9. HTTP请求的TCP瓶颈分析[转]

    阅读目录 延迟的因素 速度延时 带宽延时 最后一公里延时-tracerouter 目标 rwnd的设置 慢启动过程 慢启动的影响 慢启动对HTTP影响的一次计算 拥塞窗口的合适值 服务器配置调优 应用 ...

  10. C# 获得两日期之间所有月份(包括跨年)

    前台: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...