重载方法值聚合与替代

时间:2018-01-08 06:52:04

标签: scala apache-kafka

我有以下功能,不能编译:

interface ComponentState {
    results: InChartModel[];
    loading: boolean;
    control: string;
    modalValue: GridValue; // not an array
}

错误信息是:

  private def save(pea: KStream[String, String]): Unit = {
    pea
      .groupByKey()
      .aggregate(() => """{folder: ""}""",
        (_: String, _: String, value: String) => value,
        EventStoreTopology.Store)
  }

聚合的签名是:

[error]   [VR](x$1: org.apache.kafka.streams.kstream.Initializer[VR], x$2: org.apache.kafka.streams.kstream.Aggregator[_ >: String, _ >: String, VR], x$3: org.apache.kafka.streams.processor.StateStoreSupplier[org.apache.kafka.streams.state.KeyValueStore[_, _]])org.apache.kafka.streams.kstream.KTable[String,VR] <and>
[error]   [VR](x$1: org.apache.kafka.streams.kstream.Initializer[VR], x$2: org.apache.kafka.streams.kstream.Aggregator[_ >: String, _ >: String, VR], x$3: org.apache.kafka.common.serialization.Serde[VR])org.apache.kafka.streams.kstream.KTable[String,VR] <and>
[error]   [VR](x$1: org.apache.kafka.streams.kstream.Initializer[VR], x$2: org.apache.kafka.streams.kstream.Aggregator[_ >: String, _ >: String, VR], x$3: org.apache.kafka.streams.kstream.Materialized[String,VR,org.apache.kafka.streams.state.KeyValueStore[org.apache.kafka.common.utils.Bytes,Array[Byte]]])org.apache.kafka.streams.kstream.KTable[String,VR]
[error]  cannot be applied to (() => String, (String, String, String) => String, io.khinkali.eventstore.EventStoreTopology.Persistent)
[error]       .aggregate(() => """{folder: ""}""",
[error]        ^
[error] one error found
[error] (eventstore/compile:compileIncremental) Compilation failed 

<VR> KTable<K, VR> aggregate(final Initializer<VR> initializer, final Aggregator<? super K, ? super V, VR> aggregator, final Materialized<K, VR, KeyValueStore<Bytes, byte[]>> materialized); 定义为:

EventStoreTopology.Store

我做错了什么?

1 个答案:

答案 0 :(得分:0)

编译器需要一些帮助来推断aggregator参数的正确类型。

要进行编译,您可以尝试:

val store: Materialized[String, String, KeyValueStore[Bytes, Array[Byte]]] = ???

private def save(pea: KStream[String, String]): Unit = {
  val aggregator: Aggregator[String, String, String] = (_, _, value: String) => value
  pea
    .groupByKey()
    .aggregate(() => """{folder: ""}""",
      aggregator,
      store)
}