S02044

错误代码

S02044

报错信息

Unexpected function arguments in analytic function. RefId: S02044

错误原因

当查询语句中同时使用了分析函数和 GROUP BY 语句时,系统会在计算分析函数前检查它的合法性。如果参数数量与预期不符,则会抛出该错误。

id = `XOM`GS`AAPL
val = 102.1 33.4 73.6
date = 2020.01.01 2020.01.02 2020.01.01
t = table(id, val, date);

/*
select lead(val) over (partition by date) from t group by date, val;
date       val                 lead               
---------- ------------------- -------------------
2020.01.01 73.599999999999994  102.099999999999994
2020.01.01 102.099999999999994                    
2020.01.02 33.399999999999998 
*/                    

select lead() over (partition by date) from t group by date, val;
// select lead() over (partition by date range between unbounded preceding and unbounded following) as lead from t group by date,val => Unexpected function arguments in analytic function. RefId:S02044

解决办法

检查分析函数是否满足以下规则:

  1. 分析函数是否支持该函数。函数支持列表见 分析函数
  2. 函数参数的数量是否正确。
  3. 与 GROUP BY 连用时,函数的非常量参数必须是 GROUP BY 子句中指定的列(或列的表达式,如 val+1)之一,否则必须对该列应用聚合函数。