Hi, team. I want to extract timestamp from a Kafka...
# troubleshooting
a
Hi, team. I want to extract timestamp from a Kafka topic. There’re two kinds of message structure in this topic. One message structure is like { “version”: “2.0", “body”: { “timestamp”: { “$time”: “1655768409120" } } } Another message structure is like: { “version”: “3.0", “body”: { “timestamp”: 1655768409120 } } I can use jsonPathString to extract “timestamp” separately. { “columnName”: “timestamp”, “transformFunction”: “jsonPathLong(body, ‘$.timestamp.$time’)” } { “columnName”: “timestamp”, “transformFunction”: “jsonPathLong(body, ‘$.timestamp’)” } Any idea how to extract “timestamp” from the above two message structures using just one function?
m
lemme try. Will get back to you shortly
a
👍 Thank you.
m
This doesn't work for some reason, but I thought it would as it does in a SQL query!
Copy code
{
  "columnName": "ts",
  "transformFunction": "CASE WHEN version = '2.0' THEN jsonPathLong(body, '$.timestamp.$time') ELSE jsonPathLong(body, '$.timestamp') END"
}
a
Thank you all the same.🌷
m
annoyingly it seems like only scalar functions can be used for transform functions 😞 So I don't think we can do what you're trying to do
a
It’s ok.🤣 I’ll try another way. Maybe Groovy.
m
yeh Groovy would work, but it's kinda frustrating you can't do it in a simpler way!