03 2022 档案
摘要:1.列转行 1.说明 -- 说明 : 将 一列数据 转换成一行数据 -- 使用函数 : collect_set : 返回分组内元素 的迭代器(对元素去重) collect_list : 返回分组内元素 的迭代器(对元素不去重) concat_ws('指定分隔符',iter) : 返回 将所有元素用指
阅读全文
摘要:1.数据准备 -- DDL create table bktab ( team string comment '球队名称', number int comment '球员号码', score_time string comment '得分时间', score int comment '得分分数',
阅读全文
摘要:1.定义 /* * 1.定义 * def foreach(f: T => Unit): Unit * 2.功能 * 分布式遍历 RDD 中的每一个元素,调用指定函数 * note : 在每个分区节点上,执行指定函数f * */ 2.示例 object foreachTest extends App
阅读全文
摘要:1.定义 /* * 1.定义 * def saveAsTextFile(path: String): Unit * def saveAsObjectFile(path: String): Unit * def saveAsSequenceFile( * path: String, * codec:
阅读全文
摘要:1.定义 /* * 1.定义 * def countByKey(): Map[K, Long] * 2.功能 * 统计每种 key 的个数 * 3.执行流程 * 1. 每个节点统计分区key,count(1) * 2. 拉取每个分区 key,count(1),再做聚合 * * */ 2.示例 obj
阅读全文
摘要:1.定义 /* * 1.定义 * def fold(zeroValue: T)(op: (T, T) => T): T * op : 分区内、分区间聚合函数 * 2.功能 * 分区的数据通过初始值和分区内的数据进行聚合,然后再和初始值进行分区间的数据聚合 * 3.执行流程 * 1. 分区内对元素聚合
阅读全文
摘要:1.定义 /* * 1.定义 * def aggregate[U: ClassTag](zeroValue: U)(seqOp: (U, T) => U, combOp: (U, U) => U): U * seqOp : 分区内聚合函数 * combOp : 分区间聚合函数 * 2.功能 * 分区
阅读全文
摘要:1.定义 /* * 1.定义 * def takeOrdered(num: Int)(implicit ord: Ordering[T]): Array[T] * 2.功能 * 返回该 RDD 排序后的前 n 个元素组成的数组 * 3.note * 1.默认为正序排序 * 逆序排序: Orderin
阅读全文
摘要:1.定义 /* * 1.定义 * def take(num: Int): Array[T] * 2.功能 * 返回一个由 RDD 的前 n 个元素组成的数组 * * */ 2.示例 object takeTest extends App { val sparkconf: SparkConf = ne
阅读全文
摘要:1.定义 /* * 1.定义 * def first(): T * 2.功能 * 返回 RDD 中的第一个元素 * * */ 2.示例 object firstTest extends App { val sparkconf: SparkConf = new SparkConf().setMaste
阅读全文
摘要:1.定义 /* * 1.定义 * def count(): Long * 2.功能 * 返回 RDD 中元素的个数 * * */ 2. 示例 object countTest extends App { val sparkconf: SparkConf = new SparkConf().setMa
阅读全文
摘要:1.定义 /* * 1.定义 * def collect(): Array[T] * 2.功能 * 拉取 Rdd所有的元素到 Driver上 存储到数组上 * 3.note * 1.当 Rdd元素数据量很到时,可能导致Driver 内存溢出 * * */ 2. 示例 object collectTe
阅读全文
摘要:1. 定义 /* * 1.定义 * def reduce(f: (T, T) => T): T * 2.功能 * 聚集 RDD 中的所有元素,先聚合分区内数据,再聚合分区间数据 * 3.note * 1.先在map端reduce,再将结果拉取到Driver上进行reduce * 2.当 计算不满足结
阅读全文
摘要:1. 文件说明 数据文件(用户点击行为数据) : agent.log:时间戳,省份,城市,用户,广告,中间字段使用空格分隔 2. 数据 1516609143867 6 7 64 16 1516609143869 9 4 75 18 1516609143869 1 7 87 12 1516609143
阅读全文
摘要:1. 需求说明 /* * 数据文件(用户点击行为数据) : * agent.log:时间戳,省份,城市,用户,广告,中间字段使用空格分隔 * 需求1 : * 统计出每一个省份每个广告被点击数量排行的 Top3 * 按 省份、广告 分组,统计指标为点击次数 * * */ 2. 代码示例 object
阅读全文
摘要:1. 定义 /* * 1.定义 * def cogroup[W](other: RDD[(K, W)]): RDD[(K, (Iterable[V], Iterable[W]))] * def cogroup[W1, W2](other1: RDD[(K, W1)], other2: RDD[(K,
阅读全文
摘要:1. join /* * 1.定义 * def join[W](other: RDD[(K, W)]): RDD[(K, (V, W))] * def join[W](other: RDD[(K, W)], numPartitions: Int): RDD[(K, (V, W))] * 2.功能 *
阅读全文
摘要:1.定义 /* * 1.定义 * def sortByKey(ascending: Boolean = true, numPartitions: Int = self.partitions.length) * : RDD[(K, V)] = self.withScope * ascending :
阅读全文
摘要:1. 说明 /* * 思考 : * reduceByKey、flodByKey、aggregateByKey、combineByKey 的区别? * 本质区别 : Map端聚合和Reduce聚合规则是否相同,是不是要在Map的实现合并器 * * 1. reduceByKey * 1. 定义 * de
阅读全文
摘要:1. 定义 /* * 1. 定义 * def combineByKey[C](createCombiner: V => C, * mergeValue: (C, V) => C, * mergeCombiners: (C, C) => C, * numPartitions: Int): RDD[(K
阅读全文
摘要:1. 定义 /* * 1. 定义 * def foldByKey(zeroValue: V)(func: (V, V) => V): RDD[(K, V)] * def foldByKey(zeroValue: V,partitioner: Partitioner)(func: (V, V) =>
阅读全文
摘要:1. 定义 /* * 1. 定义 * def aggregateByKey[U: ClassTag](zeroValue: U, partitioner: Partitioner) * (seqOp: (U, V) => U,combOp: (U, U) => U): RDD[(K, U)] * *
阅读全文
摘要:1. 定义 /* * 1. 定义 * def groupByKey(): RDD[(K, Iterable[V])] * def groupByKey(partitioner: Partitioner): RDD[(K, Iterable[V])] * def groupByKey(numParti
阅读全文
摘要:1. 定义 /* * 1. 定义 * def reduceByKey(func: (V, V) => V): RDD[(K, V)] * def reduceByKey(func: (V, V) => V, numPartitions: Int): RDD[(K, V)] * def reduceB
阅读全文
摘要:1. 定义 /* * 1. 定义 * def partitionBy(partitioner: Partitioner): RDD[(K, V)] * * 2. 功能 * 将数据类型为key-value的Rdd 按照指定 Partitioner 重新进行分区 * 默认分区器为 HashPartiti
阅读全文
摘要:1. 求交集-intersection /* * 1. 定义 * def intersection(other: RDD[T]): RDD[T] * * 2. 功能 * 对源 RDD 和参数 RDD 求交集后返回一个新的 RDD * 参与运算的两个Rdd 类型必须一致,会对返回的结果进行去重 * *
阅读全文
摘要:1. 定义 /* * 1. 定义 * def sortBy[K]( * f: (T) => K, * ascending: Boolean = true, * numPartitions: Int = this.partitions.length) * (implicit ord: Ordering
阅读全文
摘要:1.定义 /* * def repartition(numPartitions: Int)(implicit ord: Ordering[T] = null): RDD[T] = withScope { * coalesce(numPartitions, shuffle = true) * } *
阅读全文
摘要:1. 说明 /* * 1. 定义 * def coalesce(numPartitions: Int * , shuffle: Boolean = false * , partitionCoalescer: Option[PartitionCoalescer] = Option.empty) * (
阅读全文
摘要:1. 定义 /* * 1. 定义 * def distinct(): RDD[T] * 2. 功能 * 将Rdd 元素去重,返回去重后的Rdd * * */ object distinctTest extends App { val sparkconf: SparkConf = new SparkC
阅读全文
摘要:1. 定义 /* * 1. 定义 * def sample( * withReplacement: Boolean, * fraction: Double, * seed: Long = Utils.random.nextLong): RDD[T] * withReplacement : 抽取数据后
阅读全文
摘要:1. 定义 /* * 1. 定义 * def filter(f: T => Boolean): RDD[T] * * 2. 功能 * 根据 传输函数 对Rdd元素进行过滤,剔除不符合条件的元素 * * 3. note * 1. 当数据进行筛选过滤后,分区不变,但是分区内的数据可能不均衡,生产环境下,
阅读全文
摘要:1. 定义 /* * 1. 定义 * //使用 hasPartitioner ; 分区个数使用 父RDD分区个数 * def groupBy[K](f: T => K)(implicit kt: ClassTag[K]): RDD[(K, Iterable[T])] * //使用 HashParti
阅读全文
摘要:1. 说明 /* * 1. 定义 * def glom(): RDD[Array[T]] * * 2. 功能 * 返回一个RDD,将每个分区内的所有元素合并成一个数组 * */ object RddTransitionOperator_glom extends App { private val s
阅读全文
摘要:1. 说明 /* * 1.定义 * def flatMap[U: ClassTag](f: T => TraversableOnce[U]): RDD[U] * * 2.功能 * 1.先将元素转换成一个迭代器 * 2.再遍历迭代器 返回新的集合 * * 3.调用流程 * 参数: 定义一个函数,作用分
阅读全文
摘要:1. 说明 /* * 定义 : * def mapPartitionsWithIndex[U: ClassTag]( * f: (Int, Iterator[T]) => Iterator[U], * preservesPartitioning: Boolean = false): RDD[U] =
阅读全文
摘要:1. 说明 /* * 定义 : * def mapPartitions[U: ClassTag]( * f: Iterator[T] => Iterator[U], * preservesPartitioning: Boolean = false): RDD[U] * 功能 : * 1. 以分区为单
阅读全文
摘要:1. 说明 定义 : def map[U: ClassTag](f: T => U): RDD[U] 功能 : 通过对 RDD的所有元素应用一个函数 返回一个新的RDD 2. 思考 : map算子 和 Rdd分区 间的关系? object MapTestByPartition extends App
阅读全文
摘要:1. 什么是Rdd 算子 rdd的方法 => rdd的算子 => rdd的操作 2. Rdd 算子的分类 1. Transformation(转换) 算子 Transformation 操作是延迟计算的 也就是说 一个RDD转换生成另一个RDD操作时是不会马上执行的,需要等待有Actions操作时,
阅读全文
摘要:需求1 : 计算除去部门最高工资, 和最低工资的平均工资 (字节跳动面试) 1. 数据准备 -- DDL create table btab ( `id` string comment '员工id', `deptno` string comment '部门编号', `salary` int comm
阅读全文
摘要:1. 什么是Spark的并行度 、什么是Rdd的分区? 1. 什么是Spark的并行度 ? Driver 将任务进行切分成不同的Task, 再发送给 Executor 节点并行计算,并行计算的任务数量 我们称之为 并行度 2. 什么是Rdd的分区 ? 1. 将要操作的数据分成 若干份,以便 分布式计
阅读全文
摘要:1. 从集合(内存)中创建rdd //1. 从集合(内存)中创建rdd object initRddByList extends App { //1. 该对象用于 : Spark应用参数的配置 将Spark的各种参数设置为key,value // note : 1. 一旦一个SparkConf对象被
阅读全文
摘要:1. 思考 : 处理数据 需要哪些东西呢? 1. 计算资源(CPU&内存) 2. 计算模型(也就是计算逻辑) 2. 在Yarn 环境中,Rdd 执行流程 1. 启动 Yarn 集群环境 2. Spark 通过申请资源创建调度节点(ApplicationMaster)和计算节点(Executor) 3
阅读全文
摘要:* Internally, each RDD is characterized by five main properties:(在内部,每个RDD有五个主要特性) * * - A list of partitions /** * 方法描述 : * 1. 返回当前Rdd 的分区对象的数组 */ pr
阅读全文
摘要:1. Rdd 是什么? 1. RDD(Resilient Distributed DataSet) 弹性分布式数据集, 是Spark中最基本的数据处理模型 它代表一个弹性的、不可变、可分区、里面的元素可并行计算 的集合 2. 代码中Rdd是 抽象类 abstract class RDD[T: Cla
阅读全文
摘要:1. filter 过滤算子 object filterTest extends App { /* * filter * 作用 : 传输过滤集合元素的函数,返回一个符合条件元素的新数组(会改变集合元素个数,但不会改变元素类型) * * 定义 : def filter(p: A => Boolean)
阅读全文
摘要:/** 1. 什么是隐式转换?* 1. 当编译器第一次编译代码失败时* 会自动在当前环境中查找能使代码通过编译的方法(通常是数据类型转换)* 也可以称之为 二次编译** 2. 隐式转换发生在什么时候?* 1. 发生在编译时期,编译器会自动帮助我们做一些事情** 3. 隐式转换的修饰的位置* 1. 隐
阅读全文
摘要:1.查看客户端默认的Block大小 hdfs getconf -confKey dfs.blocksize 134217728=128M 2.查看指定文件的Block大小 hadoop fs -stat %o hdfs://localhost/user/harsh/file.txt 13421772
阅读全文