上一页 1 2 3 4 5 6 7 8 ··· 21 下一页
摘要: sortByKey和sortBy都是transforamation算子; sortByKey 源码如下: def sortByKey(ascending: Boolean = true, numPartitions: Int = self.partitions.length) : RDD[(K, V 阅读全文
posted @ 2021-01-04 17:12 bioamin 阅读(171) 评论(0) 推荐(0) 编辑
摘要: reduceBykey是一个transformation 算子 reduceByKey: 使用 func 函数合并具有相同键的值。对于每个key对应的多个value进行了merge操作,最重要的是它能够先在本地进行merge操作。merge可以通过func自定义。 groupByKey : 对每个k 阅读全文
posted @ 2021-01-04 16:21 bioamin 阅读(120) 评论(0) 推荐(0) 编辑
摘要: sample算子通常用于抽样,是一个transformation算子 参数:withReplacement=true代表有放回抽样 参数:fraction 代表抽样的比例 使用: data.sample(withReplacement=true,fraction = 0.5).collect().f 阅读全文
posted @ 2021-01-04 15:51 bioamin 阅读(559) 评论(0) 推荐(0) 编辑
摘要: flatMap 算子在word count中经常使用,是一个transformation 算子 1、如果使用map val arr=sc.parallelize(Array(("A",1),("B",2),("C",3))) arr.map(x=>(x._1+x._2)).collect.forea 阅读全文
posted @ 2021-01-04 15:35 bioamin 阅读(629) 评论(0) 推荐(0) 编辑
摘要: 1、匿名函数 (参数:参数类型)=>函数体 匿名函数没有名字,使用 val f=(参数:参数类型)=>函数体 def f=(参数:参数类型)=>函数体 def test= (x:Int)=>{x*2} val test2=(x:Int)=>{x*3} println(test(2)) println 阅读全文
posted @ 2021-01-03 20:21 bioamin 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 1、与java switch类似 package com.cslc.day3 import scala.util.Random object MatchApp { def main(args: Array[String]): Unit = { val names=Array("liu","wang" 阅读全文
posted @ 2021-01-03 17:49 bioamin 阅读(125) 评论(0) 推荐(0) 编辑
摘要: scala 可变列表与不可变链表 package com.cslc.day2 object listApp { def main(args: Array[String]): Unit = { val l=List(1,2,3,4,5) println(l.head) println(l.tail) 阅读全文
posted @ 2021-01-03 16:12 bioamin 阅读(68) 评论(0) 推荐(0) 编辑
摘要: scala不可变数组和可变数组 package com.cslc.day2 object ArrayApp extends App { /* * 不可变数组 * */ //通过new和赋值进行初始化 val a:Array[String]=new Array[String](5) println(a 阅读全文
posted @ 2021-01-03 16:11 bioamin 阅读(53) 评论(0) 推荐(0) 编辑
摘要: object是静态的,只能做一次加载,调用时,不需要进行new class 类需要做new 新的对象,通过对象进行方法和属性调用trait 类是接口 1、与java类型,class 类里面有变量(类内部声明变量需要声明类型和占位符,或者初始化默认值;在类名后边进行变量定义只需要声明类型) packa 阅读全文
posted @ 2021-01-03 15:23 bioamin 阅读(98) 评论(0) 推荐(0) 编辑
摘要: map transformation算子 idea显示,map的输入参数是一个函数,其中函数的输入与数据有关,本次输入是一个字符串,输出可以是很多种数据类型 map 字符串转列表 data.map(fun1).foreach(println) def fun1(x:String):List[Stri 阅读全文
posted @ 2020-12-31 14:25 bioamin 阅读(235) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 21 下一页