mirror of https://github.com/apache/kafka.git
MINOR: Pass materialized to the inner KTable instance (#11888)
Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
parent
3a8f6b17a6
commit
e5eb180a6f
|
@ -249,7 +249,7 @@ class KTable[K, V](val inner: KTableJ[K, V]) {
|
|||
* @see `org.apache.kafka.streams.kstream.KTable#mapValues`
|
||||
*/
|
||||
def mapValues[VR](mapper: (K, V) => VR, materialized: Materialized[K, VR, ByteArrayKeyValueStore]): KTable[K, VR] =
|
||||
new KTable(inner.mapValues[VR](mapper.asValueMapperWithKey))
|
||||
new KTable(inner.mapValues[VR](mapper.asValueMapperWithKey, materialized))
|
||||
|
||||
/**
|
||||
* Create a new [[KTable]] by transforming the value of each record in this [[KTable]] into a new value
|
||||
|
|
|
@ -496,4 +496,42 @@ class KTableTest extends TestDriver {
|
|||
assertTrue(joinNodeLeft.name().contains("my-name"))
|
||||
assertTrue(joinNodeRight.name().contains("my-name"))
|
||||
}
|
||||
|
||||
@Test
|
||||
def testMapValuesWithValueMapperWithMaterialized(): Unit = {
|
||||
val builder = new StreamsBuilder()
|
||||
val sourceTopic = "source"
|
||||
val stateStore = "store"
|
||||
val materialized = Materialized.as[String, Long, ByteArrayKeyValueStore](stateStore)
|
||||
|
||||
val table = builder.stream[String, String](sourceTopic).toTable
|
||||
table.mapValues(value => value.length.toLong, materialized)
|
||||
|
||||
val testDriver = createTestDriver(builder)
|
||||
val testInput = testDriver.createInput[String, String](sourceTopic)
|
||||
|
||||
testInput.pipeInput("1", "topic1value1")
|
||||
assertEquals(12, testDriver.getKeyValueStore[String, Long](stateStore).get("1"))
|
||||
|
||||
testDriver.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
def testMapValuesWithValueMapperWithKeyAndWithMaterialized(): Unit = {
|
||||
val builder = new StreamsBuilder()
|
||||
val sourceTopic = "source"
|
||||
val stateStore = "store"
|
||||
val materialized = Materialized.as[String, Long, ByteArrayKeyValueStore](stateStore)
|
||||
|
||||
val table = builder.stream[String, String](sourceTopic).toTable
|
||||
table.mapValues((key, value) => key.length + value.length.toLong, materialized)
|
||||
|
||||
val testDriver = createTestDriver(builder)
|
||||
val testInput = testDriver.createInput[String, String](sourceTopic)
|
||||
|
||||
testInput.pipeInput("1", "topic1value1")
|
||||
assertEquals(13, testDriver.getKeyValueStore[String, Long](stateStore).get("1"))
|
||||
|
||||
testDriver.close()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue