Drools Rules executor
Rules executor
Rules executorDescription
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.
Drools is the present rule engine implementation and its rule language can be referenced for use by this transform. Drools documentation.
Hop Engine
✓
Spark
?
Flink
?
Dataflow
?
Details
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.
Rules Tab
The Rules tab is where you enter your rule definition or a reference to the rule file..
Rules filename
Rules script to execute
Rules result Tab
Rules result tab defines the layout of the Rules output fields.
Result column name
Result column type
Example
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:
fica_seed
Integer
-3561151667
hi
String
test
fica
Integer
bad
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");
endRules.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.
Last updated