flink DataStream[Row]注册为table报错:An input of GenericTypeInfo<Row> cannot be converted to Table.

读取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类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值