Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qlexpress #2978

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Qlexpress #2978

wants to merge 29 commits into from

Conversation

taokan
Copy link

@taokan taokan commented Dec 22, 2024

支持切换ognl语法为qlexpress,具体详情输入options语句查看,默认ognl
除了ognl命令,其余的命令均支持切换,使用的qlexpress语法为qlexpress4的语法

对于观察表达式,默认值:OGNL用法{params, target, returnObj} --> QLEXPRESS用法[params, target, returnObj]

举例
OGNL语法
$ watch demo.MathGame primeFactors '{params, returnObj}' '#cost>200' -x 2
QLEXPRESS4语法
$ watch demo.MathGame primeFactors '[params, returnOb]' '#cost>200' -x 2

条件表达式同样需要满足qlexpress语法
https://github.com/alibaba/QLExpress/tree/v4.0.0-beta.1

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hengyunabc
Copy link
Collaborator

缺少测试,有冲突需要解决。

* 是否切换使用表达式ognl/qlexpress开关
*/
@Option(level = 1,
name = "express-type",

Choose a reason for hiding this comment

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

是不是可以考虑短一点,比如就缩写成 el(expression language)

* qlexpress使用参数
*/
@Option(level = 1,
name = "qlexpress-config",

Choose a reason for hiding this comment

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

这么复杂的东西暂时没必要交给用户设置吧。我们直接给一个最推荐的就行了,没必要暴露给用户,毕竟这个场景比较单一,给个通用配置就够了

Copy link
Author

Choose a reason for hiding this comment

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

ok

public QLExpress(ClassSupplier classResolver) {
initQLExpress(classResolver);
initConfig();
initContext();

Choose a reason for hiding this comment

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

其实这三个函数就是分别初始化三个成员变量,下面这种写法可能更加清晰:

this.expressRunner = initQLExpress(classResolver);
this.qlOptions = initConfig();
this.qlGlobalContext = initContext();

尽量不要使用有副作用的函数

Copy link
Author

Choose a reason for hiding this comment

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

fix


@Override
public Express bind(String name, Object value) {
qlGlobalContext.put(name, value);

Choose a reason for hiding this comment

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

个人觉得在 put 的是很加上 "#" 前缀,要比 get 的时候 replace 要好。这样 context 的逻辑更加简单纯粹。replace 可能会导致改变不该改变的字符。

Copy link
Author

Choose a reason for hiding this comment

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

ok


public void clear() {
context.clear();
this.context.put("reflectLoader",reflectLoader);

Choose a reason for hiding this comment

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

这里的用处是?

Copy link
Author

Choose a reason for hiding this comment

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

每次bind之前调用清理现成参数

if ((this.reflectLoader != null) && (this.object != null) && !variableName.startsWith("#")) {
return this.reflectLoader.loadField(this.object, variableName, true, PureErrReporter.INSTANCE);
}
String newVariableName = variableName.replace("#","");

Choose a reason for hiding this comment

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

个人觉得在 put 的时候加上前缀,比 get 的时候隐藏一个 # 替换逻辑要更好

@Override
public Value get(Map<String, Object> attachments, String variableName) {
if ((this.reflectLoader != null) && (this.object != null) && !variableName.startsWith("#")) {
return this.reflectLoader.loadField(this.object, variableName, true, PureErrReporter.INSTANCE);

Choose a reason for hiding this comment

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

这个 api 有点底层,可以考虑继承 ObjectFieldExpressContext,然后额外加一个 map 功能,而不是直接调用 reflectLoader。或者我直接在 Express4Runner 上开个 api

Copy link
Author

Choose a reason for hiding this comment

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

待讨论点

* @Author TaoKan
* @Date 2024/9/22 12:39 PM
*/
public class QLGlobalContext implements ExpressContext {

Choose a reason for hiding this comment

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

考虑继承 ObjectFieldExpressContext 添加额外功能

Choose a reason for hiding this comment

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

new ObjectFieldExpressContext(runner);

+ " ognl -c 5d113a51 '@com.taobao.arthas.core.GlobalOptions@isDump' \n"
+ Constants.WIKI + Constants.WIKI_HOME + "ognl\n"
+ " https://commons.apache.org/proper/commons-ognl/language-guide.html")
+ " ognl '@java.lang.System@out.println(\"hello \\u4e2d\\u6587\")' \n"

Choose a reason for hiding this comment

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

是不是也得有一个类似 ognl 这样的纯执行 qlexpress 表达式的命令

Copy link
Author

Choose a reason for hiding this comment

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

待讨论点

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.

4 participants