Status
Current state: Accepted
Discussion thread: here
JIRA: here
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Motivation
KStream#print() prints records on console; But the output from KStream#print() is fixed, some user maybe want to customize it.
To do this, one good method is KStream#print(KeyValueMapper<K, V, String>)
.
For now, KStream.print() fixes output string as:
"[" + this.streamName + "]: " +keyToPrint + ", " + valueToPrint
And some users are asking to argument KStream#print() so that they can customize the output string as KStream#print(KeyValueMapper<K, V, String>):
"[" + this.streamName + "]: " + mapper.apply(keyToPrint, valueToPrint)
With above idea, we also can apply this on KStream#writeAsText() to allow user customized output string written to file.
Public Interfaces
Expanding KStream#print() and KStream#writeAsText() which also need to be extended another version of print.
void print(final KeyValueMapper<? super K, ? super V, String> mapper); void print(final KeyValueMapper<? super K, ? super V, String> mapper, final String streamName); void print(final KeyValueMapper<? super K, ? super V, String> mapper, final Serde<K> keySerde, final Serde<V> valSerde); void print(final KeyValueMapper<? super K, ? super V, String> mapper, final Serde<K> keySerde, final Serde<V> valSerde, final String streamName); void writeAsText(final String filePath, final KeyValueMapper<? super K, ? super V, String> mapper); void writeAsText(final String filePath, final String streamName, final KeyValueMapper<? super K, ? super V, String> mapper); void writeAsText(final String filePath, final Serde<K> keySerde, final Serde<V> valSerde, final KeyValueMapper<? super K, ? super V, String> mapper); void writeAsText(final String filePath, String streamName, final Serde<K> keySerde, final Serde<V> valSerde, final KeyValueMapper<? super K, ? super V, String> mapper);
Proposed Changes
A straightforward first pass is on GitHub PR#3085.
Compatibility, Deprecation, and Migration Plan
No compatibility issues foreseen.
Rejected Alternatives
Base on KStream#print() and KStream#writeAsText()
, some users seek for a new option which can customize the output but not should be restricted by fixed format.
To let user can customize output we think argument KStream#print() and KStream#writeAsText() is best option for usage(Intuition) and implementation(expand exist method with adding argument).