A. Code implementation
Package cn.socket Import org.apache.flink.streaming.api.scala._ // Data type of exception, the dynamic data into // Import org.apache.flink.api.scala._ // Data type of exception, the introduction of static data / ** * the Created by Administrator ON 2020/3/22. * / Object SocketWindowWordCount { DEF main (args: the Array [String]): Unit = { // the specified IP interfaces and val hostname: String = "192.168.136.7" Port Val: Int = 9001 // acquisition stream processing environment Val the env: = StreamExecutionEnvironment StreamExecutionEnvironment.getExecutionEnvironment // Get data calculation socket text Val: DataStream [String] = env.socketTextStream (hostname, Port, '\ n-' ) text.print () // WordCount Val windowCounts = text .flatMap {W => w.split ( "\\ S" )} .map (W => (W,. 1 )) .keyBy (_._. 1) .sum ( . 1 ) // set the degree of parallelism, printing windowCounts.print (). setParallelism (. 1 ) // execution env.execute ( "Socket the WordCount the Window " ) } }
II. Common exceptions
Error:(15, 16) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String] .flatMap { w => w.split("\\s") } ^
Error:(15, 16) not enough arguments for method flatMap: (implicit evidence$11: org.apache.flink.api.common.typeinfo.TypeInformation[String])
org.apache.flink.streaming.api.scala.DataStream[String]. Unspecified value parameter evidence$11. .flatMap { w => w.split("\\s") } ^
Figure:
Cause Analysis:
In most flink the operator, the definition does not default implicit type parameter, we do not explicitly specify the type in use, and therefore will be reported type of exception.
III. Solution
Import org.apache.flink.streaming.api.scala._ // Data type of exception, the dynamic data into Import org.apache.flink.api.scala._ // Data type of exception, the introduction of static data