Flink TableAPI报错:Caused by: org.apache.flink.table.api.TableException: Only the first field can reference an atomic type.

报错:

Caused by: org.apache.flink.table.api.TableException: Only the first field can reference an atomic type.
at org.apache.flink.table.api.TableEnvironment$$anonfun$5.apply(TableEnvironment.scala:1117)
at org.apache.flink.table.api.TableEnvironment$$anonfun$5.apply(TableEnvironment.scala:1112)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
at scala.collection.mutable.ArrayOps$ofRef.flatMap(ArrayOps.scala:186)
at org.apache.flink.table.api.TableEnvironment.getFieldInfo(TableEnvironment.scala:1112)
at org.apache.flink.table.api.StreamTableEnvironment.registerDataStreamInternal(StreamTableEnvironment.scala:546)
at org.apache.flink.table.api.java.StreamTableEnvironment.registerDataStream(StreamTableEnvironment.scala:133)
at net.qutoutiao.Bootstrap.main(Bootstrap.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
... 13 invokeInteractiveModeForExecution

因为我的是DataSource转Table,使用的是Tuple,最后发现

tuple要使用java包里面的(scala import org.apache.flink.api.java.tuple._),而不是scala自带的tuple,不然会认为是geneic类型,导致报错。

此外如果是pojo类貌似必须携带 public pojo(){ }无参构造器,否则也会报错。

具体源码可以查看方法 env.fromCollection(),

这里面会维护一个TypeInformation<OUT>类型用于后续类解析。

flink 大神链接:http://ju.outofmemory.cn/feed/1264/?page=1

阿里链接:http://jm.taobao.org/

 

posted @ 2019-05-21 14:40  舞羊  阅读(5558)  评论(0编辑  收藏  举报