中国铁建网站,wordpress工作原理,成都电商网站,网站内部链接怎麽做FlinkSql一个简单的测试程序 以下是一个简单的 Flink SQL 示例#xff0c;展示了如何使用 Flink Table API 和 Flink SQL 进行基本的数据流处理。 定义数据实体 CC #xff1a; - CC 类表示数据流中的元素#xff0c;包含两个字段#xff1a; character #xff08;字符展示了如何使用 Flink Table API 和 Flink SQL 进行基本的数据流处理。 定义数据实体 CC - CC 类表示数据流中的元素包含两个字段 character 字符和 count 计数。 - 提供了无参构造函数和带参构造函数用于创建 CC 对象。 // 1. 定义数据实体public static class CC {public String character;public long count;public CC() {}public CC(String character, long count) {this.character character;this.count count;}} 创建执行环境并模拟数据流 - 创建了 Flink 执行环境 StreamExecutionEnvironment 和 StreamTableEnvironment 。 - 创建了一个包含字符串元素的数据流 inputStream 其中包括 “hello”, “world” 和 “!!!”。 // 2. 创建执行环境并模拟数据流StreamExecutionEnvironment env StreamExecutionEnvironment.getExecutionEnvironment();env.setParallelism(1);EnvironmentSettings environmentSettings EnvironmentSettings.newInstance().useBlinkPlanner().inStreamingMode().build();StreamTableEnvironment tableEnv StreamTableEnvironment.create(env, environmentSettings);DataStreamString inputStream env.fromElements(hello,world,!!!).uid(source).name(source);对数据流进行 flatMap 操作 - 使用 flatMap 对每个输入字符串进行拆分并将每个字符映射为一个 CC 对象。 // 3. 对数据流进行flatMap()操作SingleOutputStreamOperatorCC streamOperator inputStream.flatMap(new FlatMapFunctionString, CC() {Overridepublic void flatMap(String value, CollectorCC out) throws Exception {for (char c : value.toCharArray()) {out.collect(new CC(c ,1L));}}});将数据流转为 Table - 使用 tableEnv.fromDataStream 将 streamOperator 转换为一个 Table 对象。 // 4. 将数据流转为TableTable table tableEnv.fromDataStream(streamOperator);使用 Table API 操作数据流 - 对 table 进行选择和过滤操作保留字符不为空的记录。 - 对过滤后的数据进行分组并计算每个字符的计数总和将结果存储在 result 中。 // 5. 使用tableApi操作数据流并输出结果Table filter table.select($(character), $(count)).filter($(character).isNotEqual());Table result filter.groupBy($(character)).select($(character), $(count).sum().as(character_count));tableEnv.toRetractStream(result, Row.class).print();使用 Flink SQL 操作数据流 - 将 table 注册为临时视图 “CC”。 - 执行 SQL 查询对 “CC” 进行分组计算每个字符的计数总和并将结果存储在 result2 中。 // 6. 使用FlinkSql操作数据流并输出结果tableEnv.createTemporaryView(CC, table);Table result2 tableEnv.sqlQuery(SELECT character, SUM(count) FROM CC group by character);tableEnv.toRetractStream(result2, Row.class).print();执行任务 - 使用 env.execute(“Flink Sql Test”) 启动 Flink 作业处理数据流并输出结果。 // 7.执行任务env.execute(Flink Sql Test);执行结果
(true,I[h, 1])
(true,I[e, 1])
(true,I[l, 1])
(false,-U[l, 1])
(true,U[l, 2])
(true,I[o, 1])
(true,I[w, 1])
(false,-U[o, 1])
(true,U[o, 2])
(true,I[r, 1])
(false,-U[l, 2])
(true,U[l, 3])
(true,I[d, 1])
(true,I[!, 1])
(false,-U[!, 1])
(true,U[!, 2])
(false,-U[!, 2])
(true,U[!, 3])Process finished with exit code 0通过这段代码您可以了解如何使用 Flink Table API 和 Flink SQL 对数据流进行简单的处理和分析包括数据拆分、选择、过滤、分组和计算。最后通过 toRetractStream 方法将结果打印输出。
文章转载自: http://www.morning.flzqq.cn.gov.cn.flzqq.cn http://www.morning.pqwhk.cn.gov.cn.pqwhk.cn http://www.morning.mrfjr.cn.gov.cn.mrfjr.cn http://www.morning.lmfmd.cn.gov.cn.lmfmd.cn http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn http://www.morning.bpmfn.cn.gov.cn.bpmfn.cn http://www.morning.tqpr.cn.gov.cn.tqpr.cn http://www.morning.grlth.cn.gov.cn.grlth.cn http://www.morning.bxhch.cn.gov.cn.bxhch.cn http://www.morning.ydyjf.cn.gov.cn.ydyjf.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.jngdh.cn.gov.cn.jngdh.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.nckjk.cn.gov.cn.nckjk.cn http://www.morning.fcxt.cn.gov.cn.fcxt.cn http://www.morning.krhkn.cn.gov.cn.krhkn.cn http://www.morning.nkcfh.cn.gov.cn.nkcfh.cn http://www.morning.mygbt.cn.gov.cn.mygbt.cn http://www.morning.zqnmp.cn.gov.cn.zqnmp.cn http://www.morning.ftmp.cn.gov.cn.ftmp.cn http://www.morning.yntsr.cn.gov.cn.yntsr.cn http://www.morning.wrbnh.cn.gov.cn.wrbnh.cn http://www.morning.gzgwn.cn.gov.cn.gzgwn.cn http://www.morning.tgcw.cn.gov.cn.tgcw.cn http://www.morning.hcsqznn.cn.gov.cn.hcsqznn.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.fbdkb.cn.gov.cn.fbdkb.cn http://www.morning.cpwmj.cn.gov.cn.cpwmj.cn http://www.morning.bmmyx.cn.gov.cn.bmmyx.cn http://www.morning.qdzqf.cn.gov.cn.qdzqf.cn http://www.morning.litao4.cn.gov.cn.litao4.cn http://www.morning.rqkck.cn.gov.cn.rqkck.cn http://www.morning.hryhq.cn.gov.cn.hryhq.cn http://www.morning.blznh.cn.gov.cn.blznh.cn http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn http://www.morning.ypxyl.cn.gov.cn.ypxyl.cn http://www.morning.ngcw.cn.gov.cn.ngcw.cn http://www.morning.fbpdp.cn.gov.cn.fbpdp.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.pqndg.cn.gov.cn.pqndg.cn http://www.morning.qkqgj.cn.gov.cn.qkqgj.cn http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn http://www.morning.lxfqc.cn.gov.cn.lxfqc.cn http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn http://www.morning.rcww.cn.gov.cn.rcww.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.bpmnx.cn.gov.cn.bpmnx.cn http://www.morning.ggtkk.cn.gov.cn.ggtkk.cn http://www.morning.qbkw.cn.gov.cn.qbkw.cn http://www.morning.wbdm.cn.gov.cn.wbdm.cn http://www.morning.kchwr.cn.gov.cn.kchwr.cn http://www.morning.yprnp.cn.gov.cn.yprnp.cn http://www.morning.rnxw.cn.gov.cn.rnxw.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.mtbth.cn.gov.cn.mtbth.cn http://www.morning.nnttr.cn.gov.cn.nnttr.cn http://www.morning.zcfmb.cn.gov.cn.zcfmb.cn http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn http://www.morning.nbpqx.cn.gov.cn.nbpqx.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.bykqg.cn.gov.cn.bykqg.cn http://www.morning.byjwl.cn.gov.cn.byjwl.cn http://www.morning.yjprj.cn.gov.cn.yjprj.cn http://www.morning.zlcsz.cn.gov.cn.zlcsz.cn http://www.morning.rptdz.cn.gov.cn.rptdz.cn http://www.morning.srgwr.cn.gov.cn.srgwr.cn http://www.morning.mgmqf.cn.gov.cn.mgmqf.cn http://www.morning.bxbkq.cn.gov.cn.bxbkq.cn http://www.morning.dwyyf.cn.gov.cn.dwyyf.cn http://www.morning.mtsck.cn.gov.cn.mtsck.cn http://www.morning.fnbtn.cn.gov.cn.fnbtn.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.gwsll.cn.gov.cn.gwsll.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.tsdjj.cn.gov.cn.tsdjj.cn http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn http://www.morning.zrwlz.cn.gov.cn.zrwlz.cn http://www.morning.cnqwn.cn.gov.cn.cnqwn.cn