rdd

197 Spark DataFrames概述

三世轮回 提交于 2019-11-27 08:10:10
与RDD类似,DataFrame也是一个分布式数据容器。然而DataFrame更像传统数据库的二维表格,除了数据以外,还记录数据的结构信息,即schema。 同时,与Hive类似,DataFrame也支持嵌套数据类型(struct、array和map)。 从API易用性的角度上 看,DataFrame API提供的是一套高层的关系操作,比函数式的RDD API要更加友好,门槛更低。由于与R和Pandas的DataFrame类似,Spark DataFrame很好地继承了传统单机数据分析的开发体验。 来源: https://blog.csdn.net/qq_20042935/article/details/99587044

好程序员大数据学习路线分享SparkSQl

旧城冷巷雨未停 提交于 2019-11-27 08:09:48
  好程序员大数据学习路线分享SparkSQl,Spark SQL是Spark用来处理结构化数据的一个模块,它提供了一个编程抽象叫做DataFrame并且作为分布式SQL查询引擎的作用。SparkSql中返回的数据类型是DataFrame 1.1.1. 为什么要学习 Spark SQL 我们已经学习了Hive,它是将Hive SQL转换成MapReduce然后提交到集群上执行,大大简化了编写MapReduce的程序的复杂性,由于MapReduce这种计算模型执行效率比较慢。所有Spark SQL的应运而生,它是将Spark SQL转换成RDD,然后提交到集群执行,执行效率非常快! HIVE:简化编写MapReduce的程序的复杂性 Spark SQL转换成RDD:替代MapReduce,提高效率 Spark1.0版本开始就推出了SparkSQL,最早是叫Shark 1、内存列存储--可以大大优化内存使用效率,减少了内存消耗,避免了gc对大量数据的性能开销 2、字节码生成技术(byte-code generation)--可以使用动态字节码生成技术来优化性能 3、Scala代码的优化   结构化数据是指任何有结构信息的数据。所谓结构信息,就是每条记录共用的已知的字段集合。当数据符合 这样的条件时,Spark SQL 就会使得针对这些数据的读取和查询变得更加简单高效。具体 来说

Spark Java Map function is getting executed twice

◇◆丶佛笑我妖孽 提交于 2019-11-27 08:01:10
问题 I have above code as Spark driver, when I execute my program it works properly saving required data as Parquet file. String indexFile = "index.txt"; JavaRDD<String> indexData = sc.textFile(indexFile).cache(); JavaRDD<String> jsonStringRDD = indexData.map(new Function<String, String>() { @Override public String call(String patientId) throws Exception { return "json array as string" } }); //1. Read json string array into a Dataframe (execution 1) DataFrame dataSchemaDF = sqlContext.read().json

Python+spark编程实战!

怎甘沉沦 提交于 2019-11-27 07:54:45
0、前提 0.1 配置 可参考: windows上配置 Python+spark开发环境 0.2 有关spark 说明: spark 不兼容 Python3.6 安装注意版本 可下载: anaconda4.2 一、实例分析 1.1 数据 student.txt Python资源共享群:484031800 1.2 代码 #studentExample 例子 练习 def map_func(x): s = x.split() return (s[0], [int(s[1]),int(s[2]),int(s[3])]) #返回为(key,vaklue)格式,其中key:x[0],value:x[1]且为有三个元素的列表 #return (s[0],[int(s[1],s[2],s[3])]) #注意此用法不合法 def has100(x): for y in x: if(y == 100): #把x、y理解为 x轴、y轴 return True return False def allis0(x): if(type(x)==list and sum(x) == 0): #类型为list且总分为0 者为true;其中type(x)==list :判断类型是否相同 return True return False def subMax(x,y): m = [x[1][i] if(x[1][i

Why does Spark RDD partition has 2GB limit for HDFS?

不羁岁月 提交于 2019-11-27 07:53:42
I have get an error when using mllib RandomForest to train data. As my dataset is huge and the default partition is relative small. so an exception thrown indicating that "Size exceeds Integer.MAX_VALUE" ,the orignal stack trace as following, 15/04/16 14:13:03 WARN scheduler.TaskSetManager: Lost task 19.0 in stage 6.0 (TID 120, 10.215.149.47): java.lang.IllegalArgumentException: Size exceeds Integer.MAX_VALUE at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:828) at org.apache.spark.storage.DiskStore.getBytes(DiskStore.scala:123) at org.apache.spark.storage.DiskStore.getBytes(DiskStore

How to get element by Index in Spark RDD (Java)

£可爱£侵袭症+ 提交于 2019-11-27 07:26:39
I know the method rdd.first() which gives me the first element in an RDD. Also there is the method rdd.take(num) Which gives me the first "num" elements. But isn't there a possibility to get an element by index? Thanks. maasg This should be possible by first indexing the RDD. The transformation zipWithIndex provides a stable indexing, numbering each element in its original order. Given: rdd = (a,b,c) val withIndex = rdd.zipWithIndex // ((a,0),(b,1),(c,2)) To lookup an element by index, this form is not useful. First we need to use the index as key: val indexKey = withIndex.map{case (k,v) => (v

How to print accumulator variable from within task (seem to “work” without calling value method)?

坚强是说给别人听的谎言 提交于 2019-11-27 06:53:04
问题 I know the accumulator variables are 'write only' from the point of view of tasks, when they are in execution in worker nodes. I was doing some testing on this and I realized that I am able to print the accumulator value in the task. Here I am initializing the accumulator in the driver:- scala> val accum = sc.accumulator(123) accum: org.apache.spark.Accumulator[Int] = 123 Then I go on to define a function 'foo':- scala> def foo(pair:(String,String)) = { println(accum); pair } foo: (pair:

Random numbers generation in PySpark

一笑奈何 提交于 2019-11-27 06:49:48
问题 Lets start with a simple function which always returns a random integer: import numpy as np def f(x): return np.random.randint(1000) and a RDD filled with zeros and mapped using f : rdd = sc.parallelize([0] * 10).map(f) Since above RDD is not persisted I expect I'll get a different output every time I collect: > rdd.collect() [255, 512, 512, 512, 255, 512, 255, 512, 512, 255] If we ignore the fact that distribution of values doesn't really look random it is more or less what happens. Problem

Spark RDD高级编程:基于排序机制的wordcount程序+二次排序+topn

前提是你 提交于 2019-11-27 06:17:23
(1)基于排序机制的wordcount程序 对于以下文件 进行wordcount,并按照出现次数多少排序 代码如下: /** * 排序的wordcount程序 * @author Administrator * */ public class SortWordCount { public static void main(String[] args) { SparkConf conf=new SparkConf().setAppName("SortWordCount").setMaster("local"); JavaSparkContext sparkContext=new JavaSparkContext(conf); sparkContext.textFile("D://Bigdata//18.spark//wc.txt") .flatMap(new FlatMapFunction<String, String>() { @Override public Iterator<String> call(String s) throws Exception { return new Arrays.Iterator<>(s.split(" ")); } }).mapToPair(new PairFunction<String, String, Integer>() {

Spark学习之路 (二十二)SparkStreaming的官方文档

瘦欲@ 提交于 2019-11-27 05:56:09
讨论QQ:1586558083 目录 一、简介 1.1 概述 1.2 一个小栗子 2.2 初始化StreamingContext 2.3 离散数据流 (DStreams) 2.4 输入DStream和接收器 2.5 接收器可靠性 二、基本概念 2.1 链接依赖项 三、DStream支持的transformation算子 3.1 updateStateByKey算子 3.2 transform算子 3.3 基于窗口(window)的算子 3.4 Join相关算子 四、DStream输出算子 4.1 使用foreachRDD的设计模式 正文 官网地址: http://spark.apache.org/docs/latest/streaming-programming-guide.html 回到顶部 一、简介 1.1 概述 Spark Streaming 是 Spark核心 API的一个扩展,可以实现高吞吐量的、具备容错机制的实时流数据的处理。支持从多种数据源获取数据,包括 Kafk、 Flume、 Twitter、 ZeroMQ、 Kinesis 以及 TCP sockets,从数据源获取数据之后,可以使用诸如 map、 reduce、 join和 window等高级函数进行复杂算法的处理。最后还可以将处理结果存储到文件系统,数据库和现场仪表盘。在“ One Stack rule