简体   繁体   中英

Flink DataSet.map get 'error: missing parameter type'

I am just start to learn Scala and Flink. When I try to run demo codes as follow:

private def demoFunction[T <: Vector](dataSet: DataSet[T])
  : DataSet[(linalg.Vector[Double], linalg.Vector[Double])] = {

  val metrics = dataSet.map{
    v => (1.0, v.asBreeze, linalg.Vector.zeros[Double](v.size))
  }.reduce{
    // reduce code..
  }
  // ...
}

I got err info:

Error: missing parameter type v => (1.0, v.asBreeze, linalg.Vector.zeros[Double](v.size))

The dependencies are follow:

  • linalg: import breeze.linalg
  • DataSet: import org.apache.flink.api.scala.DataSet
  • Vector: a custom trait
  • Scala==2.12.8, JDK==1.8

If you have any ideas, please help. Thanks in advance.


Update on December 12.

I fix this problem after adding a :T after v , It seems to clarify which type v is. But I am still confused with it.

val metrics = dataSet.map{
  v:T => (1.0, v.asBreeze, linalg.Vector.zeros[Double](v.size))
}// ...

If Vector in T <: Vector is the same as linalg.Vector then it takes a type parameter

trait Vector[@spec(Int, Double, Float) V] extends VectorLike[V, Vector[V]] { 
...

so it can't be just T <: Vector , it should be T <: Vector[...something...] .

If Vector in T <: Vector is different from linalg.Vector , then maybe you import breeze.linalg._ and Vector is resolved as linalg.Vector . So use fully qualified name

private def demoFunction[T <: yourpackage.yoursubpackage.Vector] ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM