# Drools Rules executor

## <img src="/files/FmwXEjyzZYb00YHacd63" alt="" data-size="line"> Rules executor

### Description <a href="#description" id="description"></a>

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](https://www.drools.org/) is the present rule engine implementation and its [rule language](https://docs.drools.org/7.68.0.Final/drools-docs/html_single/index.html#_droolslanguagereferencechapter) can be referenced for use by this transform. [Drools documentation](https://docs.drools.org/7.68.0.Final/drools-docs/html_single/index.html#_welcome).

| Hop Engine | <sup>✓</sup> |
| ---------- | ------------ |
| 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..

| Option                  | Description |
| ----------------------- | ----------- |
| Rules filename          |             |
| Rules script to execute |             |

#### Rules result Tab

Rules result tab defines the layout of the Rules output fields.

| Option             | Description |
| ------------------ | ----------- |
| 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:

| Rules.Row→row (Map) | Type    | Payload     |
| ------------------- | ------- | ----------- |
| fica\_seed          | Integer | -3561151667 |
| hi                  | String  | test        |
| fica                | Integer | bad         |

Rules can be defined and applied:

```highlight
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.primeur.com/data-shaper-1.21/knowing-the-data-shaper-designer/pipelines/transforms/rulesexecutor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
