Good morning, I’m trying to create a KSQL table from a structured JSON topic.
A sample message looks like this:
{
“MessageType”: “TrailerMaintenanceInfo”,
“Payload”: {
“TrailerCompany”: “99”,
“TrailerNumber”: “AA109T”,
“LastMaintenanceDate”: “2021-11-08T00:00:00Z”,
“UtcDateTimeOfEventMessage”: “2022-12-21T20:05:39Z”
}
}
I’d like my key to be a concatination of the TrailerCompany and TrailerNumber columns, something like 99*AA109T or some such.
Does anyone know of a way to do this within the table creation?
One of my many attempts was as follows: (this didn’t work)
Create TABLE tbl_TrailerChanges
(
MessageType varchar
,Payload STRUCT <
TrailerCompany VARCHAR
,TrailerNumber VARCHAR
,LastMaintenanceDate VARCHAR
,UtcDateTimeOfEventMessage VARCHAR
>
) WITH (
KAFKA_TOPIC = ‘dev.DataChange.Trailers’
,VALUE_FORMAT = ‘JSON’
,KEY = ‘Payload->TrailerCompany’ + ‘*’ + ‘Payload->TrailerNumber’
);
I also added PRIMARY KEY to the TrailerNumber line, just to see if I could get part of the key defined, but it appears you cannot define a Primary Key from data inside a structure.
Thanks for your help.