No Implicit Value for Evidence Parameter Error

 错误:could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[Int]

解决办法:  import org.apache.flink.api.scala._

产生这个问题的原因:

1:A frequent reason if that the code that generates the TypeInformation has not been imported. Make sure to import the entire flink.api.scala package.

2:Another common cause are generic methods, which can be fixed as described in the following section.

  泛型方法:
def selectFirst[T](input: DataSet[(T, _)]) : DataSet[T] = {
  input.map { v => v._1 }
}

val data : DataSet[(String, Long) = ...

val result = selectFirst(data)


这个泛型方法存在的问题:
selectFirst这个方法在每一次调用的时候输入参数和返回值类型可能都是不一样的,而且在定时函数时候我们无法知道类型。因此上面调用处的代码导致 an error that not enough implicit evidence is available错误。
在这个例子中,类型信息必须在调用出生成并传递给方法,Scala提供隐式转换参数可以解决!
如下这个代码告诉Scala携带一个类型T传递给函数,这个类型信息将会在方法调用的地方产生,而不是方法的定义处!

def selectFirst[T : TypeInformation](input: DataSet[(T, _)]) : DataSet[T] = {
  input.map { v => v._1 }
}

 



解决方案官网定位:https://ci.apache.org/projects/flink/flink-docs-release-1.2/dev/types_serialization.html#type-information-in-the-scala-api 

(解决问题最好的方法还是定位官方最权威的资料)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值