RDD基础学习-[2]RDD分区
2016-12-05 22:45
211 查看
简介
[1]coalesce:对RDD重新分区
def coalesce(numPartitions : scala.Int, shuffle : scala.Boolean = { /* compiledcode */ })(implicit ord : scala.Ordering[T](1)若减少分区,直接设置新的分区数即可(2)若增加分区个数,设置shuffle = true 应用:当将大数据集过滤处理后,分区中数据很小,可以减少分区数当将小文件保存到外部存储系统时,将分区数设置为1, 将文件保存在一个文件中当分区数小会造成CUP的浪费,适当增加分区[2]repartition 和 coalesce 相似,只是将shuffle默认设置为true
def repartition(numPartitions : scala.Int)(implicit ord : scala.Ordering[T]package com.dt.spark.main.RDDLearn.RDDPartitionAPIimport org.apache.spark.{SparkConf, SparkContext}/*** Created by on 16/7/17.*///==========================================/*[1]coalesce:对RDD重新分区def coalesce(numPartitions : scala.Int, shuffle : scala.Boolean = { /* compiled code */ })(implicit ord : scala.Ordering[T](1)若减少分区,直接设置新的分区数即可(2)若增加分区个数,设置shuffle = true应用:当将大数据集过滤处理后,分区中数据很小,可以减少分区数当将小文件保存到外部存储系统时,将分区数设置为1, 将文件保存在一个文件中当分区数小会造成CUP的浪费,适当增加分区[2]repartition 和 coalesce 相似,只是将shuffle默认设置为truedef repartition(numPartitions : scala.Int)(implicit ord : scala.Ordering[T]*/object RDDPartitionAPI {def main(args: Array[String]) {val conf = new SparkConf()conf.setAppName("test")conf.setMaster("local")val sc = new SparkContext(conf)//==========================================/*构建RDD[1]从scala数据集构建RDD: parallelize()*/val listRDDExample = sc.parallelize(List("1","2","3"),2)//==========================================/*获取分区数*/val partitionsSzie = listRDDExample.partitions.sizeprintln(partitionsSzie)//2//==========================================/*coalesce:对RDD重新分区def coalesce(numPartitions : scala.Int, shuffle : scala.Boolean = { /* compiled code */ })(implicit ord : scala.Ordering[T](1)若减少分区,直接设置新的分区数即可(2)若增加分区个数,设置shuffle = true*/val rePartitionsSzie = listRDDExample.coalesce(1).partitions.sizeprintln(rePartitionsSzie)//1val rePartitionsSzie2 = listRDDExample.coalesce(3,true).partitions.sizeprintln(rePartitionsSzie2)//3sc.stop()}}相关文章推荐
- 从零开始学习Linux 基础(二)—磁盘、分区与文件系统
- c语言学习之基础知识点介绍(十八):几个修饰关键字和内存分区
- 【2018.04.09学习笔记】【linux基础知识4.1-4.4、扩展学习parted分区gpt格式】
- linux基础学习之磁盘分区及一般挂载
- Spark MLlib 学习入门笔记 - RDD基础
- spark内核源码学习-RDD基础篇
- 【Linux全面学习】2.Linux系统之硬盘与分区基础知识
- RDD基础学习-[4]PairRDD聚合函数基础
- RDD基础学习-[3]RDD聚合函数基础
- Spark2.x基础学习之RDD理解
- 【spark 深入学习 06】RDD编程之旅基础篇02-Spaek shell
- Linux基础学习-Linux系统分区及挂载点
- RDD基础学习-[1]RDD建立与WordCount
- Spark学习-RDD编程基础
- Spark MLlib 入门学习笔记 - RDD基础
- 有关RDD的基础学习1
- linux基础内容学习一:linux下的分区及安装
- Spark 基础学习第一讲:弹性分布式数据集RDD
- linux基础学习之开机自动挂载分区
- linux基础学习第十四天-磁盘管理(MBR、分区挂载、SWAP)