Search code examples
javafilterapache-kafkaapache-kafka-connectjsonpath

Kafka transforms.Filter to filter records based on Odd/Even numbers is not working with bitwise operator & and remainder % operator


I have been trying to find a way to include a filter that discards the records with a particular value, in the Couchbase source connector. Lets say, I have the JSON: {"key":10004, "name":"testt"} and I want to discard all the records that have the key with all odd numbers . Is there a way to do that without having to use confluent platform?

I have installed confluent hub client and tried filter.condition": "$[?(@.key&1 == 0)]", (bitwise operator) and also tried "$[?(@.key % 2 != 0)]". Seems like these both are not working. I also checked that JsonPath(https://github.com/json-path/JsonPath) does not have this operators, does that mean these operatoes % & are not supported?


Solution

  • Bitwise operations are not supported by the JSONPath library being used.

    If you want to filter even/odds, use Kafka Streams or KSQL to create a new topic before writing to the database.