2016-03-01 78 views
1
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

當使用弗林克的斯卡拉DataSet的API,需要以下導入添加到您的代碼:import org.apache.flink.api.scala._

當使用Flink的Scala DataStream API時,您必須導入import org.apache.flink.streaming.api.scala._

原因是包對象包含一個函數,該函數會生成缺少的TypeInformation實例。

+0

謝謝你的工作。 – balaji