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

【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.kler.cn/a/134184.html

相关文章:

  • Mockito+PowerMock+Junit单元测试
  • 前端项目搭建和基础配置
  • Unity2017 控制.abc格式的三维动画播放
  • 计算机网络-数据链路层
  • Android 项目依赖冲突问题:Duplicate class found in modules
  • 计算机网络 (47)应用进程跨越网络的通信
  • linux gdb调试
  • 【数据结构】图的简介(图的逻辑结构)
  • 【ATTCK】MITRE Caldera-emu插件
  • Windows网络「SSL错误问题」及解决方案
  • Python中的迭代器、生成器和装饰器
  • 蓝桥杯单片机综合练习——工厂灯光控制
  • 2311rust到31版本更新
  • 莹莹API管理系统源码附带两套模板
  • 二元分类模型评估方法
  • 6 Redis的慢查询配置原理
  • whisper large-v3 模型文件下载链接
  • 计算机视觉与机器学习D1
  • 软件测试面试-如何定位线上出现bug
  • python使用selenium webDriver时 报错
  • MongoDB随记
  • PHP 数组在底层的实现原理
  • 网页视频下载工具 iTubeGo mac中文版软件特色
  • Apache POI 使用
  • 【自然语言处理】【大模型】赋予大模型使用工具的能力:Toolformer与ART
  • 虹科案例 | AR内窥镜手术应用为手术节约45分钟?