A map processor transforms every input message into a new message. Its function receives the original key and value and returns a new key and value, making it suitable for reshaping raw stream data or changing record identity. Use mapValues() instead when only the value changes; preserving the key avoids the repartitioning and performance cost that often follows key changes. section 12.2.1
Choose the processor according to the part of the record that must change:
- Use map() to transform both fields, such as turning an unkeyed value {id: "Apple", price: 1.50} into key Apple and value 1.50. section 12.2.1
- Use mapValues() to convert, mask, or transform values while retaining the key, such as converting prices from dollars to cents. section 12.2.1
- Place transformed records into another Kafka topic with to(topicName), forming part of a larger processor topology. section 12.2.1 section 12.7
Creating a key from a raw price record
Starting with a value such as {id: "Apple", price: 1.50} and no key, map((key, value) -> (value.id, value.price)) produces a record keyed by Apple with value 1.50. If the key already identifies the record and only the price needs conversion, mapValues((key, value) -> value.price * 100) changes the value without triggering a key change. section 12.2.1
Figure 12.2 The filter and map processors
Use the processor diagram to compare filter(), which selects records, with map(), which transforms their key-value representation. section 12.2.1







