confluentinc / confluentinc/kafka-tutorials

JDBC source connector --> Kafka Streams: handling Decimal types

Open
#127 0 comments 0 reactions 0 assignees View on GitHub
connect kstreams recipe
Dominant language
Java
Stars
39
Forks
91
PR merge metrics
No merged PRs in 30d

Description

An JDBC Source Connector publishes data to a kafka topic. In Kafka Streams, using `GenericAvroSerde`, for all the numeric fields, the streams application is printing bytes and not the decimal.

Sample code to address this:

```
LogicalTypes.Decimal decimal = (LogicalTypes.Decimal) value.getSchema().getField("NUMBER_VALUE").schema().getLogicalType();
ByteBuffer number = (ByteBuffer) value.get("NUMBER_VALUE");
byte[] numberArray = Utils.toArray(number);
BigDecimal decimal_number = new BigDecimal(new BigInteger(numberArray), decimal.getScale());
```

reference: [Slack convo](https://confluentcommunity.slack.com/archives/C48AHTCUQ/p1566381843422700?thread_ts=1525962908.000612&cid=C48AHTCUQ)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.