0
ScalaでflatMapValuesをKafkaライブラリで使用するとエラーが発生します。ここに私のコードは次のとおりです。KafkaでflatMapValuesを使用する方法
val builder: KStreamBuilder = new KStreamBuilder()
val textLines: KStream[String, String] = builder.stream("streams-plaintext-input")
import collection.JavaConverters.asJavaIterableConverter
val wordCounts: KTable[String, JLong] = textLines
.flatMapValues(textLine => textLine.toLowerCase.split("\\W+").toIterable.asJava)
.groupBy((_, word) => word)
.count("word-counts")
と私はflatMapValues
内textLine
のエラーmissing parameter type
を取得しています。 flatMapValues((textLine: String) => textLine.toLowerCase.split("\\W+").toIterable.asJava)
に置き換えても、それでも動作しません。
誰か知っていますか?私はこのような解決のScala 2.12.4での作業 おかげで、フェリペ
は、手動で出力タイプを指定する必要があります。 Scalaはしばしばジェネリックを反転できません:https://docs.confluent.io/current/streams/faq.html#scala-compile-error-no-type-parameter-java-defined-trait-is-invariant-in-type- t –
'flatMapValues {case textLine:String => ...}' –
を試してみてください。カフカがJavaで構築されているため、これが起こっているようです(https://docs.confluent.io/current/streams/faq.html#scala-コンパイルエラーなし型パラメータのjava-defined-trait-is-invariant-in-type-t) –