Flink Scala API“参数不足" [英] Flink Scala API "not enough arguments"

查看:24
本文介绍了Flink Scala API“参数不足"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having troubles using Apache Flink Scala API

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

For example, even when I take the examples from the official documentation, the scala compiler gives me tons of compilation errors.

代码:

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

Scala IDE outputs the following for the line 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) 这样简单的事情,我得到了非常相似的东西

It's not just fromElements method: even if I read from a file and then try to do something as simple as ds.map(r => r), I get something very similar

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 存储库的最新版本.

I tried two versions of Flink: 0.8.1 from Maven Central and the most fresh one from the github repository.

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

I'm running Windows 7, scala 2.10.4, jdk 1.7.0_25, Scala IDE version is 3.0.3-20140327-1716-Typesafe on top of Eclipse 4.3.0

我做错了什么?

推荐答案

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

You need to add the following import to your code:

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

然后这个例子就起作用了.

Then the example works.

这篇关于Flink Scala API“参数不足"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆