Flink第一个简单的demo ,wordCount
该问题参考引用如下:
自身代码中问题:
package cetc.flink
import org.apache.flink.api.scala.ExecutionEnvironment
object FlinKMain {
def main(args: Array[String]): Unit = {
// 1.设置运行环境
val env = ExecutionEnvironment.getExecutionEnvironment
//2.创造测试数据
val text = env.fromElements("To be, or not to be,that is the question")
//3.进行wordcount运算
val counts = text.flatMap(_.toLowerCase.split("\\W+"))
.map((_, 1)).groupBy(0).sum(1)
//4.打印测试结构
counts.print()
}
}
运行时候出错如下:
Error:(13, 32) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String]
val text = env.fromElements("To be, or not to be,that is the question")
Error:(13, 32) 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.
val text = env.fromElements("To be, or not to be,that is the question")
解决问题:
这是因为在当前环境之下找到不到scala的包,引入如下声明即可
import org.apache.flink.api.scala._
产生这个问题的原因(官网说明):
1:A frequent reason if that the code that generates the TypeInformation has not been imported. Make sure to import the entire flink.api.scala package.
2:Another common cause are generic methods, which can be fixed as described in the following section.
我碰到的是问题1的情况。