Skip to content

feat(express): 支持一元正负号运算符#355

Open
zgxkbtl wants to merge 1 commit intoalibaba:branch_version_3.x.xfrom
zgxkbtl:Issue345NegativeNumber
Open

feat(express): 支持一元正负号运算符#355
zgxkbtl wants to merge 1 commit intoalibaba:branch_version_3.x.xfrom
zgxkbtl:Issue345NegativeNumber

Conversation

@zgxkbtl
Copy link

@zgxkbtl zgxkbtl commented Oct 11, 2024

OperatorFactoryOperatorInstructionFactory 中增加了对一元正负号运算符的支持,并添加了相应的单元测试。同时更新了 KeyWordDefine4Java 以识别新的运算符。

  • 新增 OperatorUnaryPlusOperatorUnaryMinus
  • 更新 KeyWordDefine4Java 以支持一元正负号运算符
  • 添加 Issue345NegativeNumberTest 单元测试

在 `OperatorFactory` 和 `OperatorInstructionFactory` 中增加了对一元正负号运算符的支持,并添加了相应的单元测试。同时更新了 `KeyWordDefine4Java` 以识别新的运算符。

- 新增 `OperatorUnaryPlus` 和 `OperatorUnaryMinus` 类
- 更新 `KeyWordDefine4Java` 以支持一元正负号运算符
- 添加 `Issue345NegativeNumberTest` 单元测试
@CLAassistant
Copy link

CLAassistant commented Oct 11, 2024

CLA assistant check
All committers have signed the CLA.

Stack<ForRelBreakContinue> forStack, ExpressNode node, boolean isRoot) throws Exception {
boolean returnVal = false;
ExpressNode[] children = node.getChildrenArray();
//
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释代码删除

if (list[0] instanceof Number) {
return list[0];
}
throw new Exception("Cannot apply unary plus to non-number type");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抛 QLException

String express = "-b";
Object result = runner.execute(express, context, null, true, true);
//Assert.assertTrue((Boolean)result);
Assert.assertEquals(new BigDecimal("-12.22"), result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单元测试建议将所有的数字类型都进行一遍测试

@DQinYuan
Copy link
Collaborator

#345

@DQinYuan
Copy link
Collaborator

image

记得把单测整体运行下,大量单测不过

Copy link
Collaborator

@DQinYuan DQinYuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com.ql.util.express.test.NewExpressTest#testParse 单元测试还是过不了,原因猜测是

image

其中 findNodeType 获取参考操作符时获取错误,获取称了前缀 +,具体如何区分还要再想方案


"CAST_CALL:TYPE=EXPRESS,DEFINE=(LEFT_BRACKET~$CONST_CLASS$RIGHT_BRACKET~#cast)^*$((LAMBDA#LAMBDA)|ARRAY_CALL)",
"EXPRESS_OP_L1:TYPE=EXPRESS,DEFINE=OP_LEVEL1^*$CAST_CALL",
"EXPRESS_OP_L1:TYPE=EXPRESS,DEFINE=(OP_LEVEL1^$CAST_CALL)^*",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要从左边改成右边?如果使用原来的就能能通过大多数测试(和 addOperatorWithLevelOfReference 相关的依旧过不了,因为还有其他代码需要修改)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants