alibaba / alibaba/QLExpress

设置别名问题

Open
#72 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

ExpressRunner runner = new ExpressRunner();
DefaultContext context = new DefaultContext();
runner.setShortCircuit(true);
runner.addOperatorWithAlias("而且", "and", "ERROR");
runner.addFunctionOfClassMethod("相等", Object.class.getName(), "equals", new String[]{Object.class.getName()}, "不相等");
runner.addFunctionOfClassMethod("相同", Object.class.getName(), "equals", new String[]{Object.class.getName()}, "不相同");
String express = "(相等 2) 而且 (相同 3)";
List errorList = new ArrayList();
runner.execute(express, context, errorList, false, false);
for (String errorInfo : errorList) {
System.out.println(errorInfo);
}

上述返回结果如下:
不相等
不相同
ERROR

上面test, 是一个 false && false 的测试, 当addOperatorWithAlias()方法设置了错误信息errorInfo的时候, ExpressRunner的逻辑短路属性没有生效, 照样计算了&&右边的操作, 当addOperatorWithAlias的errorInfo设置为null的时候, 逻辑短路属性生效, 没有计算&&右边的逻辑.

经过调试, 当errorInfo设置为null的时候, 指令集:
1:LoadData 2
2:OP : 相等 OPNUMBER[1]
3:GoToIf[false,isPop=false] +4
4:LoadData 3
5:OP : 相同 OPNUMBER[1]
6:OP : && OPNUMBER[2]
这个时候当执行到指令3的时候, 满足条件, 跳过后面的指令, 返回结果, 此时只计算&&左边.

而errorInfo有值的时候, 解析得到的指令集:
1:LoadData 2
2:OP : 相等 OPNUMBER[1]
3:LoadData 3
4:OP : 相同 OPNUMBER[1]
5:OP : 而且 OPNUMBER[2]
不会有GoToIf的指令, 继续执行了&&右边的逻辑, 此时逻辑短路属性不生效.

原因是:
addOperatorWithAlias()方法, 当参数errorInfo是否有值的是的时候, 内部走了不同的逻辑, errorInfo=null的时候, 生成的Node带有realNodeType参数:
![image](https://user-images.githubusercontent.com/53217224/61710519-6a2af800-ad84-11e9-9204-bd8350cd142a.png),
而errorInfo!=null的时候, 生成的Node不带有realNodeType参数:
![image](https://user-images.githubusercontent.com/53217224/61710627-98a8d300-ad84-11e9-996d-5a6ae45fb689.png)
后面解析的时候, errorInfo=null的因带有realNodeType, 会生成GoToIf指令且条件成立, 跳出后续指令, errorInfo!=null的, 不会生成GoToIf指令

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the behavior with ExpressRunner, addOperatorWithAlias, and the shown false-and-false expression, first comparing execution when errorInfo is null versus "ERROR". Trace how the alias is represented through realNodeType and how GoToIf instructions are generated. Done means errorInfo can be reported without disabling logical short-circuiting, with a regression test covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.