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

【Flink 问题集】The generic type parameters of ‘Collector‘ are missing

错误展示:

在这里插入图片描述

Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(CollectionDemo.java:33)' 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:543)at org.apache.flink.streaming.api.datastream.DataStream.getType(DataStream.java:192)at org.apache.flink.streaming.api.datastream.KeyedStream.<init>(KeyedStream.java:117)at org.apache.flink.streaming.api.datastream.DataStream.keyBy(DataStream.java:292)at com.example.bigdata.flink.dataStreamApi.source.CollectionDemo.main(CollectionDemo.java:38)
Caused by: org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Collector' 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.FlatMapFunction' interface. Otherwise the type has to be specified explicitly using type information.at org.apache.flink.api.java.typeutils.TypeExtractionUtils.validateLambdaType(TypeExtractionUtils.java:371)at org.apache.flink.api.java.typeutils.TypeExtractionUtils.extractTypeFromLambda(TypeExtractionUtils.java:188)at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:560)at org.apache.flink.api.java.typeutils.TypeExtractor.getFlatMapReturnTypes(TypeExtractor.java:177)at org.apache.flink.streaming.api.datastream.DataStream.flatMap(DataStream.java:611)at com.example.bigdata.flink.dataStreamApi.source.CollectionDemo.main(CollectionDemo.java:33)

错误原因

The generic type parameters of 'Collector' 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.FlatMapFunction' interface. Otherwise the type has to be specified explicitly using type information.
// 缺少“Collector”的泛型类型参数。在许多情况下,当涉及Java泛型时,lambda方法不能为自动类型提取提供足够的信息

原因描述

java 8 在使用Java API 写 Lambda 的时候,JVM 运行时会擦除类型(泛型类型)
Flink 无法准确获取到数据类型,此时就需要我们手动指定类型

处理方案

source.flatMap(()->{...
//手动指定类型
},Types.类型)
  • 案例:
SingleOutputStreamOperator<Tuple2<Object, Integer>> map = flatMap.map(word -> Tuple2.of(word, 1),Types.TUPLE(Types.STRING, Types.INT));
http://www.lryc.cn/news/236160.html

相关文章:

  • 数据分析—将txt文件转为csv文件;将csv文件转为xls文件
  • 【算法】二分查找-20231120
  • WPF实现将鼠标悬浮在按钮上时弹出菜单
  • 车载以太网-传输层-UDP
  • uniapp如何上传文件,使用API是什么
  • 【狂神说Java】Docker概述 | Docker安装 | Docker的常用命令
  • Git精讲
  • 读书笔记:Effective C++ 3.0版2005年Scott Meyers : 55条建议(47-55)
  • Golang Context 的并发安全性探究
  • C++中只能有一个实例的单例类
  • 单张图像3D重建:原理与PyTorch实现
  • 340条样本就能让GPT-4崩溃,输出有害内容高达95%?OpenAI的安全防护措施再次失效
  • 2023.11.17使用flask将多个图片文件上传至服务器
  • 母婴服务预约小程序的效果如何
  • Flask实现cookie 开发
  • 2311rust,到60版本更新
  • 【开源】基于Vue和SpringBoot的微信小程序的音乐平台
  • adb手机调试常用命令
  • IDEA常用插件合集
  • 【算法】滑动窗口题单——2.不定长滑动窗口(求最长/最大)
  • 电子学会C/C++编程等级考试2022年03月(一级)真题解析
  • Libvirt-Qemu-Kvm 操作手记
  • 代码随想录算法训练营第二十八天| 78 子集 90 子集|| 93 复原IP地址
  • 9 HDFS架构剖析
  • Python中的迭代器、生成器和装饰器
  • 【NGINX--1】基础知识
  • 小米路由器AX1800降级后的SSH登录和关墙等命令
  • 5-什么是猴子补丁,有什么用途?什么是反射,python中如何使用反射?http和https的区别?
  • 深信服AC应用控制技术
  • 全新云开发工具箱:融合多项功能的微信小程序源码解决方案