You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* `request`, the incoming request as an [HttpServletRequest](https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html)
117
+
* `state`, a `HashMap<String, Object>` that allows passing arbitrary state from one rule evaluation to the next
118
+
* `result`, a `HashMap<String, String>` that is used to return the result of rule evaluation to the engine
119
+
120
+
In addition to the default objects, rules may optionally utilize
119
121
[trinoRequestUser](#trinorequestuser) and
120
122
[trinoQueryProperties](#trinoqueryproperties)
121
-
objects, which provide information about the user and query respectively.
123
+
, which provide information about the user and query respectively.
122
124
You must include an action of the form `result.put(\"routingGroup\", \"foo\")`
123
125
to trigger routing of a request that satisfies the condition to the specific
124
126
routing group. Without this action, the default adhoc group is used and the
125
127
whole routing rule is redundant.
126
128
127
129
The condition and actions are written in [MVEL](http://mvel.documentnode.com/),
128
-
an expression language with Java-like syntax. In most cases, you can write
129
-
conditions and actions in Java syntax and expect it to work. There are some
130
+
an expression language with Java-like syntax. Classes from `java.util`, data-type
131
+
classes from `java.lang` such as `Integer` and `String`, as well as `java.lang.Math`
132
+
and `java.lang.StrictMath` are available in rules. Rules may not use `java.lang.System`
133
+
and other classes that allow access the Java runtime and operating system.
134
+
In most cases, you can write
135
+
conditions and actions in Java syntax and expect it to work. One exception is
136
+
parametrized types. Exclude type parameters, for example to add a `HashSet` to the
137
+
`state` variable, use an action such as:
138
+
```java
139
+
actions:
140
+
- |
141
+
state.put("triggeredRules",new HashSet())
142
+
```
143
+
This is equivalent to `new HashSet<Object>()`.
144
+
145
+
There are some
130
146
MVEL-specific operators. For example, instead of doing a null-check before
131
147
accessing the `String.contains` method like this:
132
148
@@ -296,8 +312,8 @@ actions:
296
312
```
297
313
298
314
This can difficult to maintain with more rules. To have better control over the
299
-
execution of rules, we can use rule priorities and composite rules. Overall,
300
-
priorities, composite rules, and other constructs that MVEL support allows
315
+
execution of rules, we can use rule priorities. Overall,
316
+
priorities and other constructs that MVEL support allows
301
317
you to express your routing logic.
302
318
303
319
#### Rule priority
@@ -328,99 +344,52 @@ that the first rule (priority 0) is fired before the second rule (priority 1).
328
344
Thus `routingGroup` is set to `etl` and then to `etl-special`, so the
329
345
`routingGroup`is always `etl-special` in the end.
330
346
331
-
More specific rules must be set to a lesser priority so they are evaluated last
332
-
to set a `routingGroup`. To further control the execution of rules, for example
333
-
to have only one rule fire, you can use composite rules.
347
+
More specific rules must be set to a higher priority so they are evaluated last
348
+
to set a `routingGroup`.
334
349
335
-
##### Composite rules
350
+
##### Passing State
336
351
337
-
First, please refer to the [easy-rule composite rules documentation](https://github.com/j-easy/easy-rules/wiki/defining-rules#composite-rules).
338
-
339
-
The preceding section covers how to control the order of rule execution using
340
-
priorities. In addition, you can configure evaluation so that only the first
341
-
rule matched fires (the highest priority one) and the rest is ignored. You can
342
-
use `ActivationRuleGroup` to achieve this:
352
+
The `state` object may be used to pass information from one rule evaluation to
353
+
the next. This allows an author to avoid duplicating logic in multiple rules.
354
+
Priority should be used to ensure that `state` is updated before being used
355
+
in downstream rules. For example, the atomic rules may be re-implemented as
343
356
344
357
```yaml
345
358
---
346
-
name: "airflow rule group"
347
-
description: "routing rules for query from airflow"
348
-
compositeRuleType: "ActivationRuleGroup"
349
-
composingRules:
350
-
- name: "airflow special"
351
-
description: "if query from airflow with special label, route to etl-special group"
0 commit comments