gpt4 book ai didi

scala-ide - Flink Scala API "not enough arguments"

转载 作者:行者123 更新时间:2023-12-02 22:11:30 25 4
gpt4 key购买 nike

我在使用 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$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 存储库的最新版本。

我运行的是 Windows 7、scala 2.10.4、jdk 1.7.0_25,Scala IDE 版本为 3.0.3-20140327-1716-Typesafe,基于 Eclipse 4.3.0

我做错了什么?

最佳答案

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

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

然后该示例就可以运行。

关于scala-ide - Flink Scala API "not enough arguments",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29540121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com