博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
flink could not find implicit value for evidence parameter of type
阅读量:7027 次
发布时间:2019-06-28

本文共 1376 字,大约阅读时间需要 4 分钟。

hot3.png

大多数刚刚使用Apache 的人很可能在编译写好的程序时遇到如下的错误:

Error:(15, 26) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[Int]    socketStockStream.map(_.toInt).print()
package com.iteblog.streaming import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}  object Iteblog{  def main(args: Array[String]) {    val env = StreamExecutionEnvironment.getExecutionEnvironment    val socketStockStream:DataStream[String] = env.socketTextStream("www.iteblog.com", 9999)    socketStockStream.map(_.toInt).print()    env.execute("Stock stream")  }}

这种异常的发生通常是因为程序需要一个隐式参数(implicit parameter),我们可以看看上面程序用到的 map 在中的实现:

def map[R: TypeInformation](fun: T => R): DataStream[R] = {  if (fun == null) {    throw new NullPointerException("Map function must not be null.")  }  val cleanFun = clean(fun)  val mapper = new MapFunction[T, R] {    def map(in: T): R = cleanFun(in)  }   map(mapper)}

在 map 的定义中有个 [R: TypeInformation] ,但是我们程序并没有指定任何有关隐式参数的定义,这时候编译代码无法创建TypeInformation,所以出现上面提到的异常信息。解决这个问题有以下两种方法

(1)、我们可以直接在代码里面加上以下的代码:

implicit val typeInfo = TypeInformation.of(classOf[Int])

然后再去编译代码就不会出现上面的异常。

(2)、但是这并不是Flink推荐我们去做的,推荐的做法是在代码中引入一下包:

import org.apache.flink.streaming.api.scala._

如果数据是有限的(静态数据集),我们可以引入以下包:

import org.apache.flink.api.scala._

然后即可解决上面的异常信息。

转载于:https://my.oschina.net/u/2000675/blog/1819936

你可能感兴趣的文章
linux常用命令使用技巧
查看>>
企业架构 - 开篇:TOGAF介绍
查看>>
Windows数据类型探幽——千回百转你是谁?(4)
查看>>
WCF服务编程设计规范(1):最新版WCF Coding Standard 介绍和下载
查看>>
Apache Segmentaion Fault故障处理案例分析
查看>>
C# 温故知新 基础篇(5) 类<思维导图>
查看>>
ZeroMQ接口函数之 :zmq_send_const – 从一个socket上发送一个固定内存数据
查看>>
tomcat启动是报Multiple Contexts have a path of "/XXX"
查看>>
AC-50207: Fatal: Failed to execute one or more of the config tools during Contex
查看>>
读书笔记《集体智慧编程》Chapter 3 : Discovering Groups
查看>>
python大数据工作流程
查看>>
MySQL数据库学习研究(细究Percona Server 5.6)
查看>>
XCode快捷键
查看>>
人脸识别&ORC的Demo
查看>>
数据库设计(3/9):创建表
查看>>
【C#】SQL数据库助手类1.0(自用)
查看>>
任意次序的n个烙饼最小反转次数求解
查看>>
C# 使用List泛型读取和保存文本文件
查看>>
EBS R12中的 APPLTMP , APPLPTMP, UTL_FILE_DIR 设置
查看>>
Qt之ui在程序中的使用——(2)多继承法
查看>>