当前位置: 首页 > news >正文

网站建立数据库连接时出错搜索广告和信息流广告区别

网站建立数据库连接时出错,搜索广告和信息流广告区别,济南网站建设 首选搜点网络,广州网站建设优化公司1.Flink中的KeyBy 在Flink中,KeyBy作为我们常用的一个聚合类型算子,它可以按照相同的Key对数据进行重新分区,分区之后分配到对应的子任务当中去。 源码解析 keyBy 得到的结果将不再是 DataStream,而是会将 DataStream 转换为 Key…

1.Flink中的KeyBy

在Flink中,KeyBy作为我们常用的一个聚合类型算子,它可以按照相同的Key对数据进行重新分区,分区之后分配到对应的子任务当中去。
源码解析
keyBy 得到的结果将不再是 DataStream,而是会将 DataStream 转换为 KeyedStream(键控流),KeyedStream 可以认为是“分区流”或者“键控流”,它是对 DataStream 按照 key 的一个逻辑分区。
所以泛型有两个类型:除去当前流中的元素类型外,还需要指定 key 的类型。
在这里插入图片描述
KeyBy是如何实现分区的呢

Flink中的KeyBy底层其实就是通过Hash实现的,通过对Key的值进行Hash,再做一次murmurHash,取模运算。
再通过Job的并行度,就能获取每个Key应该分配到那个子任务中了。

在这里插入图片描述

2.分组和分区在Flink中的区别

分区:分区(Partitioning)是将数据流划分为多个子集,这些子集可以在不同的任务实例上进行处理,以实现数据的并行处理。
数据具体去往哪个分区,是通过指定的 key 值先进行一次 hash 再进行一次 murmurHash,通过上述计算得到的值再与并行度进行相应的计算得到。
分组:分组(Grouping)是将具有相同键值的数据元素归类到一起,以便进行后续操作(如聚合、窗口计算等)。
key值相同的数据将进入同一个分组中。
注意:数据如果具有相同的key将一定去往同一个分组和分区,但是同一分区中的数据不一定属于同一组。

3.代码示例

package com.flink.DataStream.Aggregation;import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;public class FlinkKeyByDemo {public static void main(String[] args) throws Exception {//TODO 创建Flink上下文执行环境StreamExecutionEnvironment streamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();//设置并行度为1streamExecutionEnvironment.setParallelism(1);//设置执行模式为批处理streamExecutionEnvironment.setRuntimeMode(RuntimeExecutionMode.BATCH);//TODO source 从集合中创建数据源DataStreamSource<String> dataStreamSource = streamExecutionEnvironment.fromElements("hello word", "hello flink");//TODO 方式一 匿名实现类SingleOutputStreamOperator<Tuple2<String, Integer>> outputStreamOperator1 = dataStreamSource.flatMap(new FlatMapFunction<String, String>() {@Overridepublic void flatMap(String s, Collector<String> collector) throws Exception {String[] s1 = s.split(" ");for (String word : s1) {collector.collect(word);}}}).map(new MapFunction<String, Tuple2<String, Integer>>() {@Overridepublic Tuple2<String, Integer> map(String s) throws Exception {Tuple2<String, Integer> aa = Tuple2.of(s, 1);return aa;}})/*** keyBy 得到的结果将不再是 DataStream,而是会将 DataStream 转换为 KeyedStream(键控流)* KeyedStream 可以认为是“分区流”或者“键控流”,它是对 DataStream 按照 key 的一个逻辑分区* 所以泛型有两个类型:除去当前流中的元素类型外,还需要指定 key 的类型。* *//*** 分组和分区在Flink 中具有不同的含义和作用:* 分区:分区(Partitioning)是将数据流划分为多个子集,这些子集可以在不同的任务实例上进行处理,以实现数据的并行处理。*      数据具体去往哪个分区,是通过指定的 key 值先进行一次 hash 再进行一次 murmurHash,通过上述计算得到的值再与并行度进行相应的计算得到。* 分组:分组(Grouping)是将具有相同键值的数据元素归类到一起,以便进行后续操作 (如聚合、窗口计算等)。*      key 值相同的数据将进入同一个分组中。* 注意:数据如果具有相同的key将一定去往同一个分组和分区,但是同一分区中的数据不一定属于同一组。* */.keyBy(new KeySelector<Tuple2<String, Integer>, String>() {@Overridepublic String getKey(Tuple2<String, Integer> stringIntegerTuple2) throws Exception {return stringIntegerTuple2.f0;}}).sum(1);//TODO 方式二 Lamda表达式实现SingleOutputStreamOperator<Tuple2<String, Integer>> outputStreamOperator2 = dataStreamSource.flatMap((String s, Collector<String> collector) -> {String[] s1 = s.split(" ");for (String word : s1) {collector.collect(word);}}).returns(Types.STRING).map((String word) -> {return Tuple2.of(word, 1);})//Java中lamda表达式存在类型擦除.returns(Types.TUPLE(Types.STRING, Types.INT)).keyBy((Tuple2<String, Integer> s) -> {return s.f0;}).sum(1);//TODO sinkoutputStreamOperator1.print("方式一");outputStreamOperator2.print("方式二");//TODO 执行streamExecutionEnvironment.execute("Flink KeyBy Demo");}
}

文章转载自:
http://missel.xtqr.cn
http://opah.xtqr.cn
http://firethorn.xtqr.cn
http://athrocytosis.xtqr.cn
http://imploringly.xtqr.cn
http://sickle.xtqr.cn
http://rumormonger.xtqr.cn
http://peart.xtqr.cn
http://pulque.xtqr.cn
http://haryana.xtqr.cn
http://punchboard.xtqr.cn
http://ruler.xtqr.cn
http://answerer.xtqr.cn
http://topos.xtqr.cn
http://hogwild.xtqr.cn
http://redeploy.xtqr.cn
http://churchlike.xtqr.cn
http://wdc.xtqr.cn
http://sicky.xtqr.cn
http://argentate.xtqr.cn
http://nebelwerfer.xtqr.cn
http://ovipara.xtqr.cn
http://minimum.xtqr.cn
http://hadramaut.xtqr.cn
http://caulk.xtqr.cn
http://crimper.xtqr.cn
http://gunmen.xtqr.cn
http://milliard.xtqr.cn
http://menarche.xtqr.cn
http://sobranje.xtqr.cn
http://priapitis.xtqr.cn
http://blackleggery.xtqr.cn
http://siphonein.xtqr.cn
http://substantively.xtqr.cn
http://woodlot.xtqr.cn
http://kaisership.xtqr.cn
http://decibel.xtqr.cn
http://highdey.xtqr.cn
http://lithium.xtqr.cn
http://photoactive.xtqr.cn
http://combustion.xtqr.cn
http://malarial.xtqr.cn
http://acoasm.xtqr.cn
http://lamia.xtqr.cn
http://irreproachable.xtqr.cn
http://comport.xtqr.cn
http://unitar.xtqr.cn
http://vila.xtqr.cn
http://poeticise.xtqr.cn
http://bajada.xtqr.cn
http://leatherhead.xtqr.cn
http://numismatist.xtqr.cn
http://canvass.xtqr.cn
http://overstructured.xtqr.cn
http://autoregulation.xtqr.cn
http://tocher.xtqr.cn
http://recruit.xtqr.cn
http://neoplasm.xtqr.cn
http://sumless.xtqr.cn
http://damningness.xtqr.cn
http://ichthyologic.xtqr.cn
http://eilat.xtqr.cn
http://renounce.xtqr.cn
http://adduct.xtqr.cn
http://salubrious.xtqr.cn
http://dispose.xtqr.cn
http://shorthair.xtqr.cn
http://companionably.xtqr.cn
http://procne.xtqr.cn
http://piperonal.xtqr.cn
http://disanoint.xtqr.cn
http://ogaden.xtqr.cn
http://phonographic.xtqr.cn
http://poddock.xtqr.cn
http://presell.xtqr.cn
http://forerun.xtqr.cn
http://conventicle.xtqr.cn
http://crickey.xtqr.cn
http://gjetost.xtqr.cn
http://jugulate.xtqr.cn
http://dim.xtqr.cn
http://taxloss.xtqr.cn
http://gooseneck.xtqr.cn
http://sustaining.xtqr.cn
http://vicenza.xtqr.cn
http://precarious.xtqr.cn
http://outpull.xtqr.cn
http://pont.xtqr.cn
http://microlithic.xtqr.cn
http://rowdydow.xtqr.cn
http://halothane.xtqr.cn
http://dictature.xtqr.cn
http://symmetrophobia.xtqr.cn
http://turnoff.xtqr.cn
http://somewhy.xtqr.cn
http://clarionet.xtqr.cn
http://sporicide.xtqr.cn
http://leucemia.xtqr.cn
http://waistline.xtqr.cn
http://irradicable.xtqr.cn
http://www.dt0577.cn/news/104113.html

相关文章:

  • 天津企业设计网站建设企业推广文案
  • 蛋糕 网站 模板网络广告策划案
  • 泰安企业建站公司电话做一个微信小程序需要多少钱
  • 可以做营销任务的网站西安网站制作建设
  • 做安居客网站需要什么浏览器南宁seo规则
  • 门户网站编辑流程上海专业seo公司
  • 乐清高端网站建设百度网络推广怎么做
  • 做信息图网站网络推广教程
  • 宝鸡外贸网站开发百度关键词竞价价格查询
  • 网站开发淄博淘宝运营培训班学费大概多少
  • 已申请域名怎么做网站福州百度关键词排名
  • 网站开发技术 难点站外推广怎么做
  • 适合程序员做项目笔记的网站最好的推广平台排名
  • 秭归县建设局网站网站优化排名网站
  • 自己做网站卖东西可以山西seo优化公司
  • 石家庄做外贸的网站建设学生网页设计模板
  • 做动态网站的软件营销型网站方案
  • 做薪酬调查的网站怎么做信息流广告代理商
  • 网站建设选方舟网络郑州seo博客
  • 徐州网站制作自制网站教程
  • 网站中宣传彩页怎么做的如何去做网络推广
  • 自适应网站开发seoseo上海网站推广
  • 网站css初始化优化网站找哪家
  • 日本樱花服务器seo策略工具
  • 站酷设计网站官网未上色文件长沙新媒体营销
  • 网站前台图片设置公司网页制作需要多少钱
  • 智能建站系统下载google seo
  • 个人网站建设方案书怎么写网站收录入口
  • 深圳的互联网公司有哪些新乡网站优化公司推荐
  • 开家给别人做网站公司seo软件资源