资源简介

flinkdemo, 里面分别介绍了流式计算的单词统计,聚合,从kafka的数据生产,到flink从kafka消费再写入mysql,源是mysql消费数据再写入目标数据等一系列的代码,经过测试,完成能运行的

资源截图

代码片段和文件信息

package com.hy.flinktest;

import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.AggregateOperator;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.core.fs.FileSystem;
import org.apache.flink.util.Collector;

/**
 * ClassName: BatchWordCountJava
 * Description: 统计单词批量统计(java实现)
 * Date: 2020/9/23 10:10
 *
 * @Author dengchangshi
 */
public class BatchWordCountJava {
    public static void main(String[] args) {
        String input = “d://tmpdata/test1.txt“;
        String output = “d://tmpdata/result“;
        //初始化环境
        ExecutionEnvironment environment = ExecutionEnvironment.getExecutionEnvironment();
        environment.setParallelism(1);
        //读取数据
        DataSource data = environment.readTextFile(input);

        AggregateOperator> res = data.flatMap(new SplitFunction()).groupBy(0).sum(1);
        res.writeAsCsv(output FileSystem.WriteMode.OVERWRITE);
        //res.writeAsText(output FileSystem.WriteMode.OVERWRITE);
        try {
            environment.execute(“BatchWordCountJava“);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    private static class SplitFunction implements FlatMapFunction>{
        public void flatMap(String value Collector> collector) throws Exception {
            String[] words = value.split(“ “);
            for (String word : words) {
                if(StringUtils.isNotBlank(word)){
                    collector.collect(new Tuple2(word1L));
                }
            }

        }
    }


}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件          1  2020-09-23 11:52  flinkdemo\.gradle\5.2.1\fileChanges\last-build.bin

     文件         17  2020-09-23 11:52  flinkdemo\.gradle\5.2.1\fileHashes\fileHashes.lock

     文件          0  2020-09-23 11:52  flinkdemo\.gradle\5.2.1\gc.properties

     文件         17  2020-09-23 11:52  flinkdemo\.gradle\buildOutputCleanup\buildOutputCleanup.lock

     文件         53  2020-09-23 11:52  flinkdemo\.gradle\buildOutputCleanup\cache.properties

     文件          0  2020-09-23 11:52  flinkdemo\.gradle\vcs-1\gc.properties

     文件       1185  2020-09-23 11:47  flinkdemo\.idea\$PRODUCT_WORKSPACE_FILE$

     文件        153  2020-09-23 11:47  flinkdemo\.idea\codestyles\codestyleConfig.xml

     文件        709  2020-09-25 14:50  flinkdemo\.idea\compiler.xml

     文件        170  2020-09-23 11:47  flinkdemo\.idea\dictionaries

     文件        294  2020-09-24 15:02  flinkdemo\.idea\encodings.xml

     文件        816  2020-09-24 09:15  flinkdemo\.idea\gradle.xml

     文件        184  2020-09-23 11:50  flinkdemo\.idea\kotlinc.xml

     文件        531  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__commons_cli_commons_cli_1_3_1.xml

     文件        619  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__commons_collections_commons_collections_3_2_2.xml

     文件        506  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__commons_io_commons_io_2_4.xml

     文件        496  2020-09-24 09:58  flinkdemo\.idea\libraries\Maven__com_alibaba_druid_1_1_20.xml

     文件        517  2020-09-24 15:38  flinkdemo\.idea\libraries\Maven__com_alibaba_fastjson_1_2_62.xml

     文件        545  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__com_esotericsoftware_kryo_kryo_2_24_0.xml

     文件        546  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__com_esotericsoftware_minlog_minlog_1_2.xml

     文件        544  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__com_github_scopt_scopt_2_11_3_5_0.xml

     文件        548  2020-09-23 11:50  flinkdemo\.idea\libraries\Maven__com_google_code_findbugs_jsr305_1_3_9.xml

     文件        577  2020-09-24 09:53  flinkdemo\.idea\libraries\Maven__com_google_protobuf_protobuf_java_3_6_1.xml

     文件        524  2020-09-24 15:11  flinkdemo\.idea\libraries\Maven__com_twitter_chill_2_11_0_7_6.xml

     文件        524  2020-09-24 15:11  flinkdemo\.idea\libraries\Maven__com_twitter_chill_java_0_7_6.xml

     文件        590  2020-09-25 12:27  flinkdemo\.idea\libraries\Maven__com_typesafe_akka_akka_actor_2_11_2_4_20.xml

     文件        611  2020-09-25 12:27  flinkdemo\.idea\libraries\Maven__com_typesafe_akka_akka_protobuf_2_11_2_4_20.xml

     文件        590  2020-09-25 12:27  flinkdemo\.idea\libraries\Maven__com_typesafe_akka_akka_slf4j_2_11_2_4_20.xml

     文件        597  2020-09-25 12:27  flinkdemo\.idea\libraries\Maven__com_typesafe_akka_akka_stream_2_11_2_4_20.xml

     文件        500  2020-09-25 12:27  flinkdemo\.idea\libraries\Maven__com_typesafe_config_1_3_0.xml

............此处省略107个文件信息

评论

共有 条评论