killme2008 / killme2008/aviatorscript
报错 <Lambda, this> is not a sequence
- Dominant language
- Java
- Stars
- 5.2k
- Forks
- 906
- PR merge metrics
- No merged PRs in 30d
Description
什么情况下面这段脚本会报错 ` is not a sequence`?本地运行没有问题,但是提交到 Hive 在 UDF 中运行就会抛这个异常,百思不得其解😕
刚开始以为是有一个名为 `dts` 的匿名函数类型的全局环境变量,所以在执行时出错了,但本身是用单独实例来执行的脚本,应该不存在全局环境变量污染的问题,另外无论是给 `dts` 改名还是把 `cnt` 写成一个 `Function` 而不是一个 `Lambda` 后仍然报错,就很奇怪。
**脚本:**
```lua
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))
```
**脚本传参结构:** `interacts`:`Map>>`,eg. `{"1": {"order": ["20241110"], "behave": ["20241109"\]}}`
**脚本目的:** 根据用户的订单和行为情况(互动天数)来计算其偏好得分
**Aviator 实例构造方式:**
```java
AviatorEvaluatorInstance INSTANCE = AviatorEvaluator.getInstance();
```
**完整的报错堆栈:**
```plaintext
Caused by: java.lang.IllegalArgumentException: 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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with RuntimeUtils.java and SeqFilterFunction.java at the stack-trace entries, then reproduce the supplied script and input in both local execution and the Hive UDF context. Compare the value passed to filter in each environment; done means identifying why a Lambda is treated as a non-sequence and documenting or correcting the version-specific behavior in Aviator 5.4.3.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100