大斯卡拉 API "not enough arguments"

Flink Scala API "not enough arguments"

我在使用 Apache Flink Scala 时遇到问题API

例如,即使我从官方文档中获取示例,scala 编译器也会给我大量的编译错误。

代码:

object TestFlink {

  def main(args: Array[String]) {
    val env = ExecutionEnvironment.getExecutionEnvironment
    val text = env.fromElements(
      "Who's there?",
      "I think I hear them. Stand, ho! Who's there?")

    val counts = text.flatMap { _.toLowerCase.split("\W+") filter { _.nonEmpty } }
      .map { (_, 1) }
      .groupBy(0)
      .sum(1)

    counts.print()

    env.execute("Scala WordCount Example")
  }
}

Scala IDE 为行 val text = env.fromElements

输出以下内容
Multiple markers at this line
  - not enough arguments for method fromElements: (implicit evidence: scala.reflect.ClassTag[String], implicit evidence: 
   org.apache.flink.api.common.typeinfo.TypeInformation[String])org.apache.flink.api.scala.DataSet[String]. Unspecified value parameter evidence.
  - could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String]
  - could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String]
  - not enough arguments for method fromElements: (implicit evidence: scala.reflect.ClassTag[String], implicit evidence: 
   org.apache.flink.api.common.typeinfo.TypeInformation[String])org.apache.flink.api.scala.DataSet[String]. Unspecified value parameter evidence.

这不仅仅是 fromElements 方法:即使我从文件中读取然后尝试做一些像 ds.map(r => r) 这样简单的事情,我得到的东西也非常相似

Multiple markers at this line
    - not enough arguments for method map: (implicit evidence: org.apache.flink.api.common.typeinfo.TypeInformation[K], implicit 
     evidence: scala.reflect.ClassTag[K])org.apache.flink.api.scala.DataSet[K]. Unspecified value parameters evidence, evidence.
    - could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[K]
    - could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[K]
    - not enough arguments for method map: (implicit evidence: org.apache.flink.api.common.typeinfo.TypeInformation[K], implicit 
     evidence: scala.reflect.ClassTag[K])org.apache.flink.api.scala.DataSet[K]. Unspecified value parameters evidence, evidence.

我尝试了两个版本的 Flink:来自 Maven Central 的 0.8.1 和来自 github 存储库的最新版本。

我是运行Windows7,scala 2.10.4,jdk1.7.0_25,ScalaIDE版本是3.0.3- 20140327-1716-Eclipse 4.3.0 之上的类型安全

我做错了什么?

您需要将以下导入添加到您的代码中:

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

那么这个例子就可以了。