读取test.csv的内容,map将内容转换为Row类型,然后注册为table
val stream = env.readFile(inputFormat,"D://fsimage.csv",FileProcessingMode.PROCESS_CONTINUOUSLY,1000L).setParallelism(1)
val streamRow = stream.map(new TransType())
tableEnv.registerDataStream("test",streamRow)
运行时报以下异常
Exception in thread "main" org.apache.flink.table.api.ValidationException: An input of GenericTypeInfo<Row> cannot be converted to Table. Please specify the type of the input with a RowTypeInfo.
at org.apache.flink.table.typeutils.FieldInfoUtils.getFieldsInfo(FieldInfoUtils.java:187)
at org.apache.flink.table.api.scala.internal.StreamTableEnvironmentImpl.$anonfun$asQueryOperation$2(StreamTableEnvironmentImpl.scala:247)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.flink.table.api.scala.internal.StreamTableEnvironmentImpl.asQueryOperation(StreamTableEnvironmentImpl.scala:247)
at org.apache.flink.table.api.scala.internal.StreamTableEnvironmentImpl.fromDataStream(StreamTableEnvironmentImpl.scala:76)
at org.apache.flink.table.api.scala.internal.StreamTableEnvironmentImpl.registerDataStream(StreamTableEnvironmentImpl.scala:86)
at test$.main(test.scala:27)
at test.main(test.scala)
解决方法
val tableEnv = StreamTableEnvironment.create(env)
val stream = env.readFile(inputFormat,"D://fsimage.csv",FileProcessingMode.PROCESS_CONTINUOUSLY,1000L).setParallelism(1)
val streamRow = stream.map(new TransType())(new RowTypeInfo())
tableEnv.registerDataStream("test",streamRow)
加入(new RowTypeInfo())转换为RowTypeInfo类型