Search code examples
c#avroksqldb

How to deserialize the rowkey of a ksql query in c#?


I would like to display the ROWKEY of a query result. Unfortunately it is not serialized as this is currently not supported in ksql. No problem i could do this by myself. But i dont know how..

So if i do this via rest api:

SELECT ROWKEY FROM topic

How do i turn this result into something i can actually use in C#?

How is the result (eg: \u0000\u0000\u0000\u0000\u0001�\b\u0000�\f ) structured? Does it contain the magic byte or something else?

I tried the solutions from here:

Deserialize an Avro file with C#

all with different versions of the result byte[] ... eg with the magic byte appended, with removing bytes from the beginning .. replacing the bytes in the beginning to the magic byte etc.

EDIT: iam talking about a programmatic solution with C# and not KSQL Server alone


Solution

  • AFAIK you can't. KSQL doesn't currently support any keys other than strings. You can't pass through an Avro key from a topic through KSQL and out to a consumer that then deserialises the Avro.

    If you need to get the key, then just consume the Kafka topic that underpins the KSQL stream/table using a native consumer and deserialise it from there.