错误: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
(解决问题最好的方法还是定位官方最权威的资料)