【已解决 Flink Java API问题】The return type of function ‘xxx‘ could not be determined automatically

Flink1.12-RocketMQ4.5.1-Source Flink1.12-RocketMQ4.5.1-Source KeyValueDeserializationSchema package com.flink_rmq_source; import org.apache.flink.api.java.typeutils.ResultTypeQueryable; import java.io.Serializable; public interface KeyValueDeserializationSchema<T> extends Resu 阅读详情

Flink Java API不像Scala API可以随便写lambda表达式,写完以后需要使用returns方法显式指定返回值类型,否则会报下面错误,大概意思就是说Java的lambda表达式不能提供足够的类型信息,需要指定返回值类型。不推荐使用lambda表达式而是使用匿名类。

log4j:WARN No appenders could be found for logger (org.apache.flink.api.java.ClosureCleaner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(WindowDemo.java:19)' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your function implement the 'ResultTypeQueryable' interface.
	at org.apache.flink.api.dag.Transformation.getOutputType(Transformation.java:451)
	at org.apache.flink.streaming.api.datastream.DataStream.addSink(DataStream.java:1289)
	at org.apache.flink.streaming.api.datastream.DataStream.print(DataStream.java:971)
	at it.kenn.window.WindowDemo.main(WindowDemo.java:23)
Caused by: org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Tuple3' are missing. In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved. An easy workaround is to use an (anonymous) class instead that implements the 'org.apache.flink.api.common.functions.MapFunction' interface. Otherwise the type has to be specified explicitly using type information.
	at org.apache.flink.api.java.typeutils.TypeExtractionUtils.validateLambdaType(TypeExtractionUtils.java:350)
	at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:579)
	at org.apache.flink.api.java.typeutils.TypeExtractor.getMapReturnTypes(TypeExtractor.java:175)
	at org.apache.flink.streaming.api.datastream.DataStream.map(DataStream.java:599)
	at it.kenn.window.WindowDemo.main(WindowDemo.java:19)

Process finished with exit code 1

解决方法就是显式指定返回值即可,如下

public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream<Tuple3<String, Long, Double>> readyStream = env.socketTextStream("localhost", 9999)
                .map(event -> {
                    String[] strings = event.split(",");
                    return new Tuple3<>(strings[0], Long.parseLong(strings[1]), Double.parseDouble(strings[2]));
                })
                //这里指定返回值类型
                .returns(TypeInformation.of(new TypeHint<Tuple3<String,Long,Double>>(){}));
        readyStream.print();
        
        env.execute();
    }

 

Flink InvalidTypesException: The return type of function could not be determined automatically... Flink InvalidTypesException: The return type of function could not be determined automatically... 初学Flink时遇到的小问题,后发现其实挺常见的,但还是稍作记录。 在WordCount的示例代码中有如下代码: public static final class Tokenizer implements FlatMapFunction<String, Tuple2<String, Integer& 阅读详情

相关推荐

【Flink】Flink中的泛型擦除问题

The return type of function 'main(Transformation_returnType.java:23)' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting y

克里斯的博客 3895

org.apache.flink.api.common.functions.InvalidTypesException

Caused by: org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Collector' are missing. It seems that your compiler has not stored them into the .class file. ...

weixin_41608066的博客 3735

【Flink】The return type of function ‘Custom Source‘ could not be determined automatically

The return type of function ‘Custom Source‘ could not be determined automatically

一杯咖啡半杯糖的博客 1008

The return type of function ‘Custom Source‘ could not be determined automatically, due to type erasu

问题描述 Flink 在使用 自定义一个 Source 时,抛出错误 解决办法 在自定义 Source时, 需要指定泛型

weixin_44904163的博客 2701

org.apache.flink.api.common.functions.InvalidTypesException: The return type of function ‘main(Batch

使用Flink写一个批处理程序,然后提交运行出现了 `Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(BatchWordCount.java:28)' could not be determined automatically, due to type erasure. You can give type info

优快云 精品推荐 645

flink实战--开发中常见的错误与问题

常见错误集 1.Checkpoint失败:Checkpoint expired before completing env.enableCheckpointing(1000L) val checkpointConf = env.getCheckpointConfig checkpointConf.setMinPauseBetweenCheckp...

阿华田的博客 2万+

The return type of function ‘main(WordCountToObject.java:28)‘ could not be determined automatically,

java使用lamda表达式,出现类型无法自动识别到报一下异常 在这Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(XXX.java:28)' could not be determined automatically, due to type erasure. You can give type informat

qingmuchuan_er的博客 1630

手把手教学,Python 游戏编程之实现飞机大战(含源代码)

我想大家都是有玩过类似飞机大战的射击类游戏,也享受目标被消除通过后带来的愉悦感。那么如果用Python来实现飞机大战游戏?下面就跟大家一起用Python来做一个小游戏,不仅可以从中感受到乐趣,还可以提升自己的能力。

veratata的博客 1万+

Flink启动报错could not be determined automatically

今天发布Flink应用,报如下错误: The return type of function 'main(RyeCollectorLauncher.java:77)' could not be determined automatically, due to type erasure. You can give type information hints by using the returns...

不清不慎的博客 1万+

SAP-FICO LSMW实战:批量导入财务凭证与固定资产主数据(AS91)的完整指南

本文详细介绍了SAP-FICO中LSMW工具在批量导入财务凭证与固定资产主数据(AS91)的完整流程与实战技巧。从基础概念、环境准备到财务凭证导入全流程,特别针对AS91历史资产导入的日期逻辑和关键字段映射提供了专项指南,并分享了常见错误排查与性能优化建议,帮助用户高效完成SAP数据迁移任务。

weixin_29230649的博客 503

AltiumDesigner 09安装过程破解问题 .

首先分享一下破解文件,网上总是下载不到,好不容易下载到了,放在网盘上,有需要的自取。AltiumDesigner 09破解文件。链接:https://pan.baidu.com/s/1ZGvbR_6T51hpcaFbQiMX5w 密码:qwvaAltiumDesigner 09安装安装文件,比较大,包含破解文件:链接:https://pan.baidu.com/s/1mfgragB519jpGfR...

xiaoxiao_rabbit的博客 3万+

Timeout of 60000ms expired before the position for partition could be determined踩坑flink消费kafka2.3.0

flink消费kafka2.3.0,时报错,分区分配的不对 Kafka Client Timeout of 60000ms expired before the position for partition could be determined 在网上找了一波,没找到原因,后面,误打误撞,发现,是因为,kafka的配置文件,server.properties,使用了主机名作为配置,在server.properties中添加 host.name=192.168.0.30 (当前所在服务器的i.

RUIMENG061511332的博客 1万+

Go基础:Go语言详细介绍,环境搭建,及第一个程序详解

Go语言是Google开发的开源编程语言,具有高效、简洁、并发性强等特点。文章从Go语言的诞生背景、核心特性及应用领域展开介绍,并详细说明了Windows、Linux和macOS下的环境搭建步骤,包括安装、环境变量配置及测试方法。最后通过“Hello, World!”程序解析Go语言基本语法,并演示了编译发布和跨平台编译功能。全文涵盖了Go语言从入门到实践的完整流程,适合初学者快速上手。

数据知道的博客 6799

Flink-Java报错之org.apache.flink.api.common.functions.InvalidTypesException

An easy workaround is to use an (anonymous) class instead that implements the 'org.apache.flink.api.common.functions.FlatMapFunction' interface. Otherwise the type has to be specified explicitly using type information.可以搜索这个报错,有很多文章提到了解决方法,并给出了示例代码。

BugEveryday的博客 992

1、JMP脚本编程全面指南:从基础到高级应用

本博客全面介绍了JMP脚本编程的各个方面,从JMP基础和JSL入门,到数据类型、数据结构、编程方法、数据表操作、图形与三维场景脚本,再到应用程序创建与扩展功能。内容涵盖脚本工具使用、常见任务实现、兼容性说明及未来发展趋势,旨在帮助用户掌握JMP脚本语言的强大功能,提升数据分析的自动化与定制化能力。适合从初学者到高级用户的深入学习与实践参考。

flink9streamer的博客 266

SAP_通用模块-MASS批量操作技巧

SAP_MM模块-MASS/MM17批量更新主数据详细教程

风沙的博客 2164

解决Flink报错Exception in thread “main“ org.apache.flink.api.common.functions.InvalidTypesException

2种方式解决Flink报错Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException

虎鲸不是鱼 7303

AI自瞄原理剖析(四)从Yolo推理坐标到屏幕坐标:基于FOV视角与焦距的坐标变换与精准瞄准

从Yolo推理框架得到的坐标到屏幕坐标的转换是一个涉及到FOV视角、焦距以及分辨率的复杂过程。通过数学公式,我们可以将推理框坐标反推为游戏内的实际坐标,并最终映射到屏幕坐标系中。利用这些信息,AI自瞄系统能够精确计算出准星从当前位置移动到敌人位置的距离,实现精准的自动瞄准。通过这种方法,AI自瞄系统能够在不同的游戏环境下灵活应对,提供高度精确的操作体验。在AI自瞄系统中,目标检测仅仅是第一步,获取到预测框的坐标后,我们还需要将这些坐标转换为实际屏幕上的精确位置。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1333

Flink 自定义数据源Connector

flink自定义数据源

tianhouquan的专栏 5608

QT西游回合制源码+java后台管理系统

这是一套回合制游戏源码,很适合学习。

renkai721的专栏 2536

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

报错:java.lang.NoSuchMethodError:org.apache.flink.api.java.ClosureCleaner.clean(Ljava/lang/Object;Z)V

java.lang.NoSuchMethodError:org.apache.flink.api.java.ClosureCleaner.clean(Ljava/lang/Object;Z)V——flink使用时报错 原因 flink-streaming-java(或scala)包在pom文件的位置与其他包冲突,maven扫描时出现了异常 比如我负责的模块中涉及到了Redis,引入了 这个依赖,而该依赖中 也有一个相同的包且作用域只在test,它的位置在streaming之上所以导致先被扫描…(大意了)

weixin_52863669的博客 2952

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Sylph平台自定义数据源hdfs数据源

Sylph 是一个一站式的大数据流计算平台,通过编译Stream SQL,sylph会自动生成Apache Flink等分布式程序到Apache Yarn集群运行。 Sylph地址:https://github.com/harbby/sylph/ *以下开发基于Sylph 0.5.0版本 ***开发目标:***由于当前Sylph提供的数据流接入类型仅有kafka及一个test类型,希望可以支持从h...

807

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Flink 踩坑记

1、flink sink to kafka 报错 java.lang.NoSuchMethodError: org.apache.flink.api.java.ClosureCleaner.clean(Ljava/lang/Object;Z)V Caused by: java.lang.NoSuchMethodError: org.apache.flink.api.java.ClosureCl...

magic_kid_2010的专栏 8897

1.11.0 flinksql自定义oss connector 连接器

在tablesql中连接oss,暂时没找到线程的连接器,所以自己实现一个,根据阿里云oss的sdk进行读取数据和写数据到oss 代码结构 OssDynamicTableFactory import org.apache.flink.api.common.serialization.DeserializationSchema; import org.apache.flink.api.common.serialization.SerializationSchema; import org.apac.

u010034713的博客 2112

[Flink/FlinkCDC] 实践总结:Flink 1.12.6 升级 Flink 1.15.4

目录Flink DataStream/API未变的重要特性虽然官宣建议弃用 JDK 8,使用JDK 11+;但:仍继续支持 JDK 8依赖模块的变化Flink Cdc : flink cdc 2.0.0 之后,【groupId、包路径】 从 com.alibaba.ververica 变为 com.ververica各模块摆脱了 scala停止支持 scala 2.11,但支持 2.12table...

weixin_36879478的博客 390

Flink程序启动报错could not be determined automatically

could not be determined automatically 通过idea中的报错可以定位到错误位置 修改为如下的方式即可,根据你的返回值来定的,不要写和我一样的哦!!!

zggpdd的博客 832
上一篇: Flink累加器、计数器的使用
下一篇: Flink window function及常用窗口算子
iFence
博客等级 码龄9年 8051粉丝 111原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值