No new data sinks have been defined since the last execution. The last execution refers to the lates

Flink 执行中报错:

Exception in thread "main" java.lang.RuntimeException: No new data sinks have been defined since the last execution. The last execution refers to the latest call to 'execute()', 'count()', 'collect()', or 'print()'.

代码如下:

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.operators.FlatMapOperator;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;

public class WordCount {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataSource<String> textFile = env.readTextFile("datas/1.txt");

        FlatMapOperator<String, Tuple2<String, Long>> flatMapOperator = textFile.flatMap((String line, Collector<Tuple2<String, Long>> out) -> {
            String[] words = line.split(" ");
            for (String word : words) {
                out.collect(Tuple2.of(word, 1L));
            }
        })
                // 为防止泛型擦除,使用returns指明数据类型
                .returns(Types.TUPLE(Types.STRING, Types.LONG));

        flatMapOperator
                .groupBy(0).sum(1).print();

        // env.execute();
    }
}

说明: 读取文件进行单词操作,属于批处理,最后 print() 已经触发程序执行了,execute 用于流式处理,在这没必要重复写了。

解决方法: 将最后一行 env.execute(); 注释掉即可

以下是一个flume的conf文件,请帮我逐行解释一下代码:“#定义三大组件的名称 a.sources = r a.sinks = k1 k2 k3 a.channels = c1 c2 c3 #将数据流复制给所有channel a.sources.r.selector.type = replicating  # 配置Source组件 a.sources.r.type = exec a.sources.r.command = cat /home/bit/novel/novel.csv # kafka a.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink a.sinks.k1.kafka.topic = data a.sinks.k1.kafka.bootstrap.servers = localhost:9092 a.sinks.k1.kafka.flumeBatchSize = 20 a.sinks.k1.kafka.producer.acks = 1 a.sinks.k1.kafka.producer.linger.ms = 1 a.sinks.k1.kafka.producer.compression.type = snappy a.channels.c1.type = memory a.channels.c1.capacity = 100000 a.channels.c1.transactionCapacity = 100 # mysql a.sinks.k2.type =com.us.flume.MysqlSink a.sinks.k2.hostname=localhost a.sinks.k2.port=3306 a.sinks.k2.databaseName=novel a.sinks.k2.tableName=table1 a.sinks.k2.user=bit a.sinks.k2.password=123456 a.channels.c2.type = memory a.channels.c2.capacity = 100000 a.channels.c2.transactionCapactiy = 2000 # hdfs a.sinks.k3.type = hdfs a.sinks.k3.hdfs.path = hdfs://localhost:9000/user/bit/novel #积攒多少个Event才flush到HDFS一次 a.sinks.k3.hdfs.batchSize = 100 #设置文件类型,可支持压缩 a.sinks.k3.hdfs.fileType = DataStream #多久生成一个新的文件 a.sinks.k3.hdfs.rollInterval = 5 a.channels.c3.type = memory a.channels.c3.capacity =100000 a.channels.c3.transactionCapacity = 100 # Bind the source and sink to the channel a.sources.r.channels = c1 c2 c3 a.sinks.k1.channel = c1 a.sinks.k2.channel = c2 a.sinks.k3.channel = c3”
最新发布
05-24
这个conf文件是用来配置Apache Flume进行数据采集、传输和存储的。下面是每一行代码的解释: ``` #定义三大组件的名称 a.sources = r a.sinks = k1 k2 k3 a.channels = c1 c2 c3 ``` 这三行代码定义了三个组件的名称,分别是源(source)、汇(sink)和通道(channel),这些名称将在接下来的配置中被用到。 ``` #将数据流复制给所有channel a.sources.r.selector.type = replicating ``` 这行代码配置了源组件的复制策略,即数据流将会被复制到所有的通道中。 ``` # 配置Source组件 a.sources.r.type = exec a.sources.r.command = cat /home/bit/novel/novel.csv ``` 这两行代码配置了源组件的类型和命令。这里使用的是exec类型的源组件,它会执行一个命令,这个命令将会输出一些数据,这些数据将会被Flume采集并传输到汇组件。 ``` # kafka a.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink a.sinks.k1.kafka.topic = data a.sinks.k1.kafka.bootstrap.servers = localhost:9092 a.sinks.k1.kafka.flumeBatchSize = 20 a.sinks.k1.kafka.producer.acks = 1 a.sinks.k1.kafka.producer.linger.ms = 1 a.sinks.k1.kafka.producer.compression.type = snappy ``` 这些代码配置了一个Kafka的汇组件,它将数据发送到一个名为"data"的Kafka主题中。其中kafka.bootstrap.servers指定了Kafka的服务器地址和端口,kafka.flumeBatchSize指定了每个批次发送的事件数量,producer.acks指定了要求的确认级别,producer.linger.ms指定了等待确认的时间,producer.compression.type指定了压缩方式。 ``` a.channels.c1.type = memory a.channels.c1.capacity = 100000 a.channels.c1.transactionCapacity = 100 ``` 这些代码配置了一个类型为内存的通道,它的容量为100000个事件,事务容量为100个事件。 ``` # mysql a.sinks.k2.type =com.us.flume.MysqlSink a.sinks.k2.hostname=localhost a.sinks.k2.port=3306 a.sinks.k2.databaseName=novel a.sinks.k2.tableName=table1 a.sinks.k2.user=bit a.sinks.k2.password=123456 a.channels.c2.type = memory a.channels.c2.capacity = 100000 a.channels.c2.transactionCapactiy = 2000 ``` 这些代码配置了一个MySQL的汇组件,它将数据写入到一个名为"table1"的表中。其中hostname指定了MySQL服务器的地址,port指定了端口号,databaseName指定了数据库名称,user和password指定了登录信息。 ``` # hdfs a.sinks.k3.type = hdfs a.sinks.k3.hdfs.path = hdfs://localhost:9000/user/bit/novel a.sinks.k3.hdfs.batchSize = 100 a.sinks.k3.hdfs.fileType = DataStream a.sinks.k3.hdfs.rollInterval = 5 a.channels.c3.type = memory a.channels.c3.capacity =100000 a.channels.c3.transactionCapacity = 100 ``` 这些代码配置了一个HDFS的汇组件,它将数据写入到HDFS中的一个目录中。其中hdfs.path指定了HDFS的地址和目录,hdfs.batchSize指定了每个批次发送的事件数量,hdfs.fileType指定了文件类型,hdfs.rollInterval指定了多久生成一个新的文件。 ``` # Bind the source and sink to the channel a.sources.r.channels = c1 c2 c3 a.sinks.k1.channel = c1 a.sinks.k2.channel = c2 a.sinks.k3.channel = c3 ``` 这些代码将源组件和汇组件分别绑定到相应的通道上。也就是说,源组件从c1、c2、c3中采集数据,并将数据发送到k1、k2、k3中去。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员老五

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值