Hello, we have changed the function as you mentioned but still the same issue is present.
%sql
create or replace function test_get(v_date DATE, days_before decimal(38) DEFAULT 1) returns DATE
return
select (xx) as l_result FROM
(select (t.xx), row_number() over (order by t.xx desc) as rn
from time_table t
where t.xx = (v_date)
and t.DA_WORK_DAYS = 1
) sub
where sub.rn= days_before;
analysis exception: Correlated scalar subqueries must be aggregated: Filter (cast(cast(rn#8811 as decimal(10,0)) as decimal(38,0)) = outer(p_days_before#8814))
+- SubqueryAlias sub
+- Window [xx#8846, row_number() windowspecdefinition(xx#8846 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rn#8811], [xx#8846 DESC NULLS LAST]
+- Project [xx#8846]
+- Filter ((xx#8846 = outer(p_date#8813)) AND (cast(DA_WORK_DAYS#8860 as int) = 1))
+- SubqueryAlias t
+- SubqueryAlias spark_catalog.time_table
+- Relation