flink scala api“参数不足”

ztyzrc3y  于 2021-06-24  发布在  Flink
关注(0)|答案(1)|浏览(559)

我在使用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")
  }
}

scalaide为行输出以下内容 val text = env.fromElements ```
Multiple markers at this line

  • not enough arguments for method fromElements: (implicit evidence$14: scala.reflect.ClassTag[String], implicit evidence$15:
    org.apache.flink.api.common.typeinfo.TypeInformation[String])org.apache.flink.api.scala.DataSet[String]. Unspecified value parameter evidence$15.
  • 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$14: scala.reflect.ClassTag[String], implicit evidence$15:
    org.apache.flink.api.common.typeinfo.TypeInformation[String])org.apache.flink.api.scala.DataSet[String]. Unspecified value parameter evidence$15.
不仅仅是 `fromElements` 方法:即使我读了一个文件,然后试着做一些像 `ds.map(r => r)` ,我得到了非常相似的东西

Multiple markers at this line
- not enough arguments for method map: (implicit evidence$4: org.apache.flink.api.common.typeinfo.TypeInformation[K], implicit
evidence$5: scala.reflect.ClassTag[K])org.apache.flink.api.scala.DataSet[K]. Unspecified value parameters evidence$4, evidence$5.
- 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$4: org.apache.flink.api.common.typeinfo.TypeInformation[K], implicit
evidence$5: scala.reflect.ClassTag[K])org.apache.flink.api.scala.DataSet[K]. Unspecified value parameters evidence$4, evidence$5.

我尝试了两个版本的flink:maven central的0.8.1和github存储库中最新的版本。
我运行的是Windows7,Scala2.10.4,JDK1.7.0\u25,ScalaIDE版本是3.0.3-20140327-1716-typesafe,在Eclipse4.3.0之上
我做错什么了?
ryevplcw

ryevplcw1#

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

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

那么这个例子就行了。

相关问题