Rule Executor
Samples:
Overview
The Rules Executor allows fields of incoming rows to be executed against a rule set. This may be useful to determine additional information or route rows onto another step.
Drools is the present rule engine implementation and its rule language can be referenced for use by this step. Drools documentation
Details
For each row processed by the Rules Executor step each column is converted to a Rules.Column then injected into the rule engine and executed against the rules set. Rules.Column contains four properties:
externalSource: boolean property indicating if this Rules.Column was injected from an external source (a field from a processed row)
name: name of this field
type: type of data stored in payload (one of ValueMetaInterface.typeCodes - Number, String, Integer, Date, Boolean, etc...)
payload: value of this field
Results are generated by creating Rules.Column objects. The step is configured to pick up these generated objects by name.
Example
All Rule Definitions should contain "import org.pentaho.di.trans.steps.rules.Rules.Column;" to give access to the Rules.Column class.
For the input row: fica_seed (Integer), hi (String), fica (Integer); three Rules.Column objects will be created in the Rules Engine:
Rules.Column: name |
type |
payload |
---|---|---|
fica_seed |
Integer |
-3561151667 |
hi |
String |
test |
fica |
Integer |
620 |
Rules can be defined and applied:
rule "Decline" dialect "mvel" when $fica : Column(name == "fica", payload < 550) then Column approvalStatus = new Column(); approvalStatus.name = "approvalStatus" approvalStatus.type = String.class approvalStatus.payload = "declined" Column approvalClassification = new Column(); approvalClassification.name = "approvalClass" approvalClassification.type = String.class approvalClassification.payload = "Declined: fica too low" insert(approvalStatus); insert(approvalClassification); System.out.println("Declined"); end
Rules.Column properties can be checked as in the above's left hand side.
Rules.Column objects can be created for pickup as in the above's right hand side.
The step can be told to pickup a generated Rules.Column object by defining the Rules.Column name in the steps Results tab. Type conversions can be applied by setting the Result column type as well.