Skip to content

Commit 1f3ccc0

Browse files
committed
addFunctionsDefinedInScript doc
1 parent 5978eaf commit 1f3ccc0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README-EN-source.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ include::./src/test/java/com/alibaba/qlexpress4/test/function/HelloFunction.java
141141
include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=customComplexFunction]
142142
----
143143

144+
QLExpress4 also supports adding custom functions through QLExpress scripts. Note that variables defined outside of functions (such as defineTime in the example) are initialized when the function is defined and will not be recalculated when the function is subsequently called.
145+
146+
[source,java,indent=0]
147+
----
148+
include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=addFunctionsDefinedInScript]
149+
----
150+
151+
It is recommended to use Java to define custom functions as much as possible, as this can provide better performance and stability.
152+
144153
=== Validating Syntax Correctness
145154

146155
To validate syntax correctness without executing scripts: call `parseToSyntaxTree` and catch exceptions. If `QLSyntaxException` is caught, it indicates syntax errors exist.

README-source.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ include::./src/test/java/com/alibaba/qlexpress4/test/function/HelloFunction.java
143143
include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=customComplexFunction]
144144
----
145145

146+
QLExpress4还支持通过QLExpress脚本添加自定义函数。需要注意的是,在函数外定义的变量(如示例中的defineTime)在函数定义时就已初始化完成,后续调用函数时不会重新计算该变量的值。
147+
148+
[source,java,indent=0]
149+
----
150+
include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=addFunctionsDefinedInScript]
151+
----
152+
153+
建议尽可能使用Java方式定义自定义函数,这样可以获得更好的性能和稳定性。
154+
146155
=== 校验语法正确性
147156

148157
在不执行脚本的情况下,单纯校验语法的正确性: 调用 `parseToSyntaxTree` 并且捕获异常,如果捕获到 `QLSyntaxException`,则说明存在语法错误

0 commit comments

Comments
 (0)