aviatorscript icon indicating copy to clipboard operation
aviatorscript copied to clipboard

报错 <Lambda, this> is not a sequence

Open AngeeloLee opened this issue 1 year ago • 1 comments

什么情况下面这段脚本会报错 <Lambda, this> is not a sequence?本地运行没有问题,但是提交到 Hive 在 UDF 中运行就会抛这个异常,百思不得其解😕

刚开始以为是有一个名为 dts 的匿名函数类型的全局环境变量,所以在执行时出错了,但本身是用单独实例来执行的脚本,应该不存在全局环境变量污染的问题,另外无论是给 dts 改名还是把 cnt 写成一个 Function 而不是一个 Lambda 后仍然报错,就很奇怪。

脚本:

let recall_days = 30; 
let order_rate = 0.7; 
let behave_rate = 0.3; 
let date_bound = Dates.format(Dates.sub(Dates.from(now()), recall_days, Dates.DAY), 'yyyyMMdd');  ## Dates 是一个 Java 工具类
let cnt = fn(dts) { count(filter(dts, lambda(dt) -> dt >= date_bound end)) }; 
let score = fn(mp) { cnt(mp.order) * order_rate + cnt(mp.behavior) * behave_rate }; 
into(seq.map(), map(interacts, lambda(etr) -> seq.entry(etr.key, double(score(etr.value))) end))

脚本传参结构: interactsMap<String, Map<String, List<String>>>,eg. {"1": {"order": ["20241110"], "behave": ["20241109"\]}}

脚本目的: 根据用户的订单和行为情况(互动天数)来计算其偏好得分

Aviator 实例构造方式:

AviatorEvaluatorInstance INSTANCE = AviatorEvaluator.getInstance();

完整的报错堆栈:

Caused by: java.lang.IllegalArgumentException: <Lambda, this> is not a sequence
	at com.googlecode.aviator.runtime.RuntimeUtils.seq(RuntimeUtils.java:83)
	at com.googlecode.aviator.runtime.function.seq.SeqFilterFunction.call(SeqFilterFunction.java:58)
	at Script_1731226617315_59/1456294453.execute0(Script_1731226617315_59:2)
	at com.googlecode.aviator.ClassExpression.executeDirectly(ClassExpression.java:67)
	at com.googlecode.aviator.runtime.function.LambdaFunction.call(LambdaFunction.java:122)
	at com.googlecode.aviator.RuntimeFunctionDelegator.call(RuntimeFunctionDelegator.java:58)
	at Script_1731226617316_61/1536557698.execute0(Script_1731226617316_61:2)
	at com.googlecode.aviator.ClassExpression.executeDirectly(ClassExpression.java:67)
	at com.googlecode.aviator.runtime.function.LambdaFunction.call(LambdaFunction.java:122)
	at com.googlecode.aviator.RuntimeFunctionDelegator.call(RuntimeFunctionDelegator.java:58)
	at Script_1731226617317_62/1731618599.execute0(Script_1731226617317_62:2)
	at com.googlecode.aviator.ClassExpression.executeDirectly(ClassExpression.java:67)
	at com.googlecode.aviator.runtime.function.LambdaFunction.call(LambdaFunction.java:122)
	at com.googlecode.aviator.runtime.function.seq.SeqMapFunction.call(SeqMapFunction.java:61)
	at Script_1731226617314_58/1282792046.execute0(Script_1731226617314_58:2)
	at com.googlecode.aviator.ClassExpression.executeDirectly(ClassExpression.java:67)
	at com.googlecode.aviator.BaseExpression.execute(BaseExpression.java:212)
	其他业务调用...

Aviator 版本: 5.4.3

AngeeloLee avatar Nov 10 '24 08:11 AngeeloLee

尝试把 cnt 函数的参数 dts 改名下? 实在找不到原因,可以开启 Options.TRACE_EVAL 看看,这将打印整个执行过程到标准输出,具体看文档。

killme2008 avatar Nov 20 '24 14:11 killme2008