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 transform.
For each row processed by the Rules Executor transform 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 transform is configured to pick up these generated objects by name.
The Rules tab is where you enter your rule definition or a reference to the rule file..
Rules script to execute
All Rule Definitions should contain "import org.apache.hop.pipeline.transforms.drools.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 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 transform can be told to pickup a generated Rules.Column object by defining the Rules.Column name in the transform’s Results tab. Type conversions can be applied by setting the Result column type as well.