TypeInformation未定义

时间:2016-03-01 16:16:19

标签: apache-flink

object EventConsumer {

  def main(args: Array[String]): Unit = {
    val env  = ExecutionEnvironment.getExecutionEnvironment

    val data1 =   env.readTextFile("file:////some_events.txt");
    // Define the data source
    data1 .map (new myMapFunction)
  }

  class myMapFunction extends MapFunction[String,Unit]
  {
    override def map(in: String): Unit = {
      println(in)
    }
  }
}

很长一段时间真的遇到这个编译错误,请帮忙。

Error:(27, 15) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String]
      flatMap { _.split("\n")}.filter(_.nonEmpty).map (new myMapFunction)

Error:(24, 15) not enough arguments for method map: (implicit evidence$2: org.apache.flink.api.common.typeinfo.TypeInformation[Unit], implicit evidence$3: scala.reflect.ClassTag[Unit])org.apache.flink.api.scala.DataSet[Unit].
Unspecified value parameters evidence$2, evidence$3.
    data1.map (new myMapFunction)
              ^
              ^

1 个答案:

答案 0 :(得分:2)

使用Flink的Scala DataSet API时,必须在代码中添加以下导入:import org.apache.flink.api.scala._

使用Flink的Scala DataStream API时,您必须导入import org.apache.flink.streaming.api.scala._

原因是包对象包含一个生成缺失TypeInformation实例的函数。