UDF - Issue on returning Varchar

Hi guys!

I’m starting with Dremio for the first time and I need to create an UDF that should return just one string value. My query on the function only returns one value but whenever I try to execute the function Dremio tells me:This query cannot be decorrelated.

UDF:

CREATE OR REPLACE FUNCTION f_ratings_draft ( ratingweight double, ratingcategory varchar )
RETURNS VARCHAR
RETURN select max(X_RATING)
from rating_table
where WeightToAAA=round(ratingweight,0)

p.s: if I avoid using the input parameter on the “where” it works but obviously that is not what I need from the UDF. I need the UDF to return just one string value based on input parameter applied on the where clause

p.s 2: if I make the UDF to return a table, works fine! (returning just 1 row) but I need to return a varchar not a table, since function will be used at row level.

CREATE OR REPLACE FUNCTION f_ratings_draft
( p_ratingweight INT, p_ratingcategory VARCHAR )
RETURNS table (ratingtype varchar)
–RETURNS VARCHAR
RETURN
select RETURN select max(X_RATING)
from rating_table
where WeightToAAA=round(ratingweight,0)