Trig function availability?

Hi All, probably a bit of a simple question here but I can’t for the life of me find anything in the references or guess keywords for applying trig, like sin/atan2/etc funcs in ksqldb?

My use case here is calculating bearing between two lat/lon points, I see geo_distance is implemented which should require trig under the hood, but no corresponding geo_bearing or exposed trig functions.


Hi @j4freeman , welcome to the forums!

Unfortunately, it doesn’t seem like ksqlDB has trig functions built in. I’ve been looking through what we have available in ksql/ksqldb-engine/src/main/java/io/confluent/ksql/function at master · confluentinc/ksql · GitHub, and it seems that while geo_distance is using the Math library under the hood, the individual Math functions are not exposed directly.

At this point, it looks like you’d need to write your own UDF for this functionality.

Hope this helps

1 Like

Hi @j4freeman, are you looking to use the Haversine formula or would you need the added precision for the Vincenty model?

Also, the current list of scalar functions is here in the documentation: ksqlDB Scalar Functions - ksqlDB Documentation

That may be easier to read than the code. Of course, if you want to implement or contribute the trig functions, reading the code will help you do so!

1 Like

I’m looking to calculate bearing rather than distance which relies on sin, cos, and atan2 availability. Looks like I’m going to have to get a local setup to get a UDF going at any rate, although it’s quite surprising basic trig isn’t yet available regardless.

This topic was automatically closed after 30 days. New replies are no longer allowed.