读learning spark lighting chapter1~chapter2
chapter 1 introduction to the analysis with spark
the conponents of Sparks
spark core(contains the basic functionality of sparks. spark Core is also the home to the APIs that defines the RDDs),
spark sql(structured data ) is the package for working with the structured data.it allow query data via SQL as well as Apache hive , and it support many sources of data ,including Hive tables ,Parquet And jason.also allow developers to intermix SQL queries with the programatic data manipulation supported By the RDDs in Python ,java And Scala .
spark streaming(real-time),enables processing the live of streaming of data.
MLib(machine learning)
GraphX(graph processing )is a library for manipulating the graph .
A Brief History of Spark
spark is a open source project that has beed And is maintained By a thriving And diverse community of developer .
chapter 2 downloading spark And getting started
walking through the process of downloding And running the sprak on local mode on single computer .
you don't needmaster Scala,java orPython.Spark itself is written in Scala, and runs on the Java Virtual Machine (JVM). To run Spark
on either your laptop or a cluster, all you need is an installation of Java 6 or newer. If you wish to use the Python API you will also need a Python interpreter (version 2.6 or newer).Spark does not yet work with Python 3.
downloading spark,select the "pre-build for Hadoop 2.4 And later".
tips:
widows user May run into issues installing .you can use the ziptool untar the .tar file Note :instatll spark in a directionalry with no space (e.g. c:\spark).
after you untar you will get a new directionaru with the same name but without the final .tar suffix .
damn it:
Most of this book includes code in all of Spark’s languages, but interactive shells are
available only in Python and Scala. Because a shell is very useful for learning the API, we recommend using one of these languages for these examples even if you are a Java
developer. The API is similar in every language.
change the directionaty to the spark,type bin\pyspark,you will see the logo.
Introduction to Core spark concepts
Driver program
|----your application
|----distributed datasets that you defined
usually weapply many operations on thedatasets.
***in the preceding example ,the Driver program was the spark she'll intself ,And you can type in the operation that you wanted.
***Driver program access the spark through a SparkContext object,which representing the connection to a computing cluster. what's more the sparkcontext is automatically created for you called as sc,in the pyspark ,you can print the infomation about this Object By typing "sc".well i think you will know the SparkContext have 3 kinds in java ,Python And Scala respectively.
SparkContext have many operations ,such as count(),first() and so on. Driver program typically manage a number of nodes called executors. when you call any operation on a cluster different machines might count in different ranges of the file.beacuse we run the spark shell locally,it execute all works on a single machine.
Passing Funtions to Spark
look at the following example in python:
lines = sc.textFile(""README.md);
pythonLines = lines.filter(lambda line : "Python" in line);
pythoLines.first();
if you are unfamilat with the lambda sytax. it's a shorthand way to define function inline in Python or Scala, then pass the function's name to the Spark. you can do like this :
def hasPython(line): # this function judge that wheter every line contain the "Python" in a file
return "Python" in line.
pythonLines = lines.filter(hasPython)
of course you can write in java.but they are defined as classes, implementing interface Funtion:
JavaRDD<String> pythonLines = filter(new Funtion<String, Bollean>()
{
Boolean call(String line)
{
return lines.contains(line);
}
});
nowadays java8 have supported lambda.
Spark qutomatically takes your functions (e.g. lines.contains("Python"))and ships it to executors nodes. Thus, you can write code in a single driver program and automatically have parts of it run on mutiple nodes.
Standalone Applications
Apart from running Spark interactively, Spark can be linked to standalone applications in either Java, Python or Scala. The main difference from using it in the shell is that you need to initialize your SparkContext.After that ,the functions is same.Remember , if you using it in the shell, the SparkContext is created automatically for you called "sc", you can use it direactly.
The proces linked to Spark varies from languages. In Java and Scala , you give your aplliation Maven dependency on the spark-core artifact.Maven is a popular package managerment tool for java-based languages let you link to libaries in public repositories.you can use Maven itself build your projet , or use other tools that can talk to the Maven repositories, including Scala's sbt od Gradle. Popular IDE like Eclipse also allow you to directly add a Maven dependency to a project.
In Python,you simply write application as Python scripts, but you must run them using the bin\spark-submit script included in Spark. The spark-submit script include the dependency for us in Python,what's more it sets up the enrivonment for Spark's Python API to function. Simply run your scripts like this:
bin\spak-submit my_script.py
(Note that you will have to use backslashes instead of forward slashes on Window)s
读learning spark lighting chapter1~chapter2的更多相关文章
- 【原】Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令
<Learning Spark>这本书算是Spark入门的必读书了,中文版是<Spark快速大数据分析>,不过豆瓣书评很有意思的是,英文原版评分7.4,评论都说入门而已深入不足 ...
- 【原】Learning Spark (Python版) 学习笔记(四)----Spark Sreaming与MLlib机器学习
本来这篇是准备5.15更的,但是上周一直在忙签证和工作的事,没时间就推迟了,现在终于有时间来写写Learning Spark最后一部分内容了. 第10-11 章主要讲的是Spark Streaming ...
- 【原】Learning Spark (Python版) 学习笔记(三)----工作原理、调优与Spark SQL
周末的任务是更新Learning Spark系列第三篇,以为自己写不完了,但为了改正拖延症,还是得完成给自己定的任务啊 = =.这三章主要讲Spark的运行过程(本地+集群),性能调优以及Spark ...
- Learning Spark: Lightning-Fast Big Data Analysis 中文翻译
Learning Spark: Lightning-Fast Big Data Analysis 中文翻译行为纯属个人对于Spark的兴趣,仅供学习. 如果我的翻译行为侵犯您的版权,请您告知,我将停止 ...
- Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令
<Learning Spark>这本书算是Spark入门的必读书了,中文版是<Spark快速大数据分析>,不过豆瓣书评很有意思的是,英文原版评分7.4,评论都说入门而已深入不足 ...
- 【原】Learning Spark (Python版) 学习笔记(二)----键值对、数据读取与保存、共享特性
本来应该上周更新的,结果碰上五一,懒癌发作,就推迟了 = =.以后还是要按时完成任务.废话不多说,第四章-第六章主要讲了三个内容:键值对.数据读取与保存与Spark的两个共享特性(累加器和广播变量). ...
- Learning Spark中文版--第三章--RDD编程(1)
本章介绍了Spark用于数据处理的核心抽象概念,具有弹性的分布式数据集(RDD).一个RDD仅仅是一个分布式的元素集合.在Spark中,所有工作都表示为创建新的RDDs.转换现有的RDD,或者调 ...
- Learning Spark 第四章——键值对处理
本章主要介绍Spark如何处理键值对.K-V RDDs通常用于聚集操作,使用相同的key聚集或者对不同的RDD进行聚集.部分情况下,需要将spark中的数据记录转换为键值对然后进行聚集处理.我们也会对 ...
- 线性回归的Spark实现 [Linear Regression / Machine Learning / Spark]
1- 问题提出 2- 线性回归 3- 理论推导 4- Python/Spark实现 # -*- coding: utf-8 -*- from pyspark import SparkContext t ...
随机推荐
- (四)Hololens Unity 开发之 凝视系统
学习源于官方文档 Gaze in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 HoloLens 有三大输入系统,凝视点.手势和声音 ~ 本文主要记录凝视 ...
- libMF阅读记录(一):首先要编译通过
libMF是林智仁老师开发的一个用于推荐系统的矩阵分解库,下载地址:libMF 测试用的数据集是MovieLen,一个给电影评分的数据集,下载在此:ML 最近在阅读libMF的源代码,并且准备开发其M ...
- Linux Platform驱动模型(二) _驱动方法
在Linux设备树语法详解和Linux Platform驱动模型(一) _设备信息中我们讨论了设备信息的写法,本文主要讨论平台总线中另外一部分-驱动方法,将试图回答下面几个问题: 如何填充platfo ...
- ubuntu下安装pdo和pdo_mysql扩展
ubuntu下安装好LAMP后默认情况没有安装mysql_pdo扩展,以下是安装步聚 1 安装pdo sudo pecl install pdo 出现以下错误是说明pdo已经加入了php的默认安装,不 ...
- arcpy.mapping-认识arcpy.mapping
arcpy.mapping-认识arcpy.mapping by 李远祥 ArcMap提供了强大的地图制图功能,在实际的工作中,只要涉及到专题地图和地图册的制作,难免会遇到非常多的出图工作和地图图面元 ...
- 体验 WebFont,网页上的艺术字
在最新项目中,由于要频繁使用艺术字, 而用户设备没有此字体,因此以往的经验都是使用图片... 所以在同事的瞩目期许之下,我开始实验研究这个问题的解决方案1. 直接使用字体文件 @font-face { ...
- matlab中axis的使用
% 提示 disp ('该功能练习axis功能'); %初始化快捷式数组 x=-*pi:pi/:*pi; y=sin(x); plot(x,y); title('sin(x)图形'); grid on ...
- 学习ui-router
ui-router的学习 在单页面应用中要把各个分散的视图给组织起来是通过路由机制来实现的.Angular原始的路由机制靠ngRoute提供,通过hash和history来实现的,可以检测浏览器是否支 ...
- phpcms的安装以及简单使用
先来说一下phpcms的安装 首先从网上下个phpcms的压缩包,解压 解压后就是个这样的文件夹 这里要注意,下载的时候要放在平时存动态网页的那个地址,www目录下,如图 点开phpcms文件夹,里面 ...
- Java安装
java特点:跨平台.简单.面向对像编译后解释再运行安装JDK 环境变量的配置:JAVA_HOME:JDK的根目录====C:\Program Files\Java\jdk1.7.0_25Path:J ...