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

查看:551
本文介绍了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版本是Eclipse 4.3.0之上的3.0.3-20140327-1716-Typesafe

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._ 

然后该示例起作用.

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

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