簡體   English   中英

如何在scala中使用flink fold函數

[英]How to use flink fold function in scala

這是一個非常有效的嘗試使用Flink折疊與scala匿名函數:

val myFoldFunction = (x: Double, t:(Double,String,String)) => x + t._1
env.readFileStream(...).
...
.groupBy(1)
.fold(0.0, myFoldFunction : Function2[Double, (Double,String,String), Double])

它匯編得很好,但在執行時,我得到了“類型擦除問題”(見下文)。 在Java中這樣做很好,但當然更冗長。 我喜歡簡潔明了的lambda。 我怎么能在scala中做到這一點?

Caused by: org.apache.flink.api.common.functions.InvalidTypesException:
Type of TypeVariable 'R' in 'public org.apache.flink.streaming.api.scala.DataStream org.apache.flink.streaming.api.scala.DataStream.fold(java.lang.Object,scala.Function2,org.apache.flink.api.common.typeinfo.TypeInformation,scala.reflect.ClassTag)' could not be determined. 
This is most likely a type erasure problem. 
The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type(s).

您遇到的問題是Flink [1]中的錯誤。 問題源於Flink的TypeExtractor以及Scala DataStream API在Java實現之上的實現方式。 TypeExtractor無法為Scala類型生成TypeInformation ,因此返回MissingTypeInformation 創建StreamFold運算符后,手動設置此缺失類型信息。 但是, StreamFold運算符的實現方式是它不接受MissingTypeInformation ,因此在設置正確的類型信息之前失敗。

我已經打開了一個拉取請求[2]來解決這個問題。 它應該在接下來的兩天內合並。 通過使用最新的0.10快照版本,您的問題應該得到解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM