- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 05:11 AM
Hi @Johan Van Noten
I got it to work, its a very different kind of SQL then what i am used to but it works, you could try the below and tweak it to your needs. Basically spark sql does not like predicates that are not equal, so you will need to use a self join to the same table and create a column that equates to your conditions and then join that back to your main table to get the desired result. Very different from our daily SQL 😀
CREATE FUNCTION
averageTemperatureUDF(ovenID STRING, startTime TIMESTAMP, endTime TIMESTAMP)
RETURNS FLOAT
READS SQL DATA SQL SECURITY DEFINER
RETURN SELECT avg(ovenTemperature) as averageTemperature
from oventemperatures base
INNER JOIN (SELECT ovenTimestamp BETWEEN startTime AND endTime AS label, ovenTimestamp FROM oventemperatures) *****
ON base.ovenTimestamp = *****.ovenTimestamp
where *****.label IS true