For the list of all supported Decision Insight downloads and releases, see the Downloads page.

Decision table

The decision table component takes as input an object represented as a Map. It then evaluates this object against a set of rules and outputs a single value named the outcome. In this page, learn how to use the decision table component. 

Use case

Here is an example of a decision table that indicates whether you should go play golf or stay home depending on the current weather. The current weather is characterized by 4 indicators:

  • Outlook (string) – sunny, cloudy or rainy
  • Temperature (integer) – in degree Celsius
  • Humidity (string) – high, normal, low
  • Windy (boolean) – true or false

 

#outlook;temperature;humidity;windy;<outcome>
sunny;[-10..40];<any>;<any>;play-golf
rainy;[25..35];<any>;false;play-golf
rainy;<any>;<any>;<any>;stay-home
cloudy;<=15;<any>;true;stay-home
cloudy;<any>;high;<any>;stay-home
cloudy;<any>;<any>;false;play-golf
<any>;<any>;<any>;<any>;stay-home


To generate the outcome, the decision table engine evaluates rules one by one in order until it finds a matching rule. When a matching rule is found, the engine outputs the outcome (usually the first or last column).

For example let's that today,the weather is {outlook:rainy, temperature:30, humidity:high, windy:false}

  • The first rule does not match because it's not sunny.
  • The second rule does match: it's rainy, temperature is between 25 and 35 degrees and it's not windy. The outcome corresponding to the second rule is play-golf. Conclusion: you should go and play golf today!

Library

Create a new library with the following jar:

Camel version Library jars
2.18.3

See also How to retrieve the Camel version of Decision Insight.

The source for this component can also be downloaded. Feel free to report bugs and propose improvements.

Usage samples

  • Create a new library named camel_decisiontable and upload the camel decision table jar (see above).
  • Create a new resource named decisiontable1_rules with the following content:

    #outlook;temperature;humidity;windy;<outcome>
    sunny;[-10..40];<any>;<any>;play-golf
    rainy;[25..35];<any>;false;play-golf
    rainy;<any>;<any>;<any>;stay-home
    cloudy;<=15;<any>;true;stay-home
    cloudy;<any>;high;<any>;stay-home
    cloudy;<any>;<any>;false;play-golf
    <any>;<any>;<any>;<any>;stay-home
  • Create a new routing context named decisiontable1_test

    <routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
        <route>
            <from uri="timer:foo?repeatCount=1"/>
            <setBody>
                <u:map-create>
                    <u:map-entry key="outlook"><simple>rainy</simple></u:map-entry>
                    <u:map-entry key="temperature"><simple>30</simple></u:map-entry>
                    <u:map-entry key="humidity"><simple>high</simple></u:map-entry>
                    <u:map-entry key="windy"><simple>false</simple></u:map-entry>
                </u:map-create>
            </setBody>
            <log message="input: ${body}"/>
            <setHeader headerName="output">
                <language language="decision-table">resource:tnd-resource:decisiontable1_test</language>
            </setHeader>
            <log message="output: ${header.output}"/>
        </route>
    </routes>
  • Start the route and check out the logs. You should have the following logs:

    decisiontable1_test - input: {temperature=30, humidity=high, outlook=rainy, windy=false}
    decisiontable1_test - output: play-golf

Decision table resource syntax

A decision table contains a header and a set of rules.

Header

The header is the first line of a decision table and must start with #.

It contains a list of column separated by semicolons (;). One of the columns must be named <outcome> .

Example
#<outcome>;column1;column2

Body

The body of the decision table consists in a list of rule sets (i.e lines).

In a rule set, to escape the following characters, you should add a backslash (\) in front of them:

  • <
  • {
  • [
  • ,
  • ;
  • \

So for example to create a rule that matches the string "<null>" instead of null values, you should write \<null>.

Each rule sets contains a list of columns separated by semicolons (;).

Each column in a rule set contains a rule. The following rules are supported:

Rule Description
<anyspace> Matches any value.
<null> Matches null values.
<empty>

Matches null or empty strings, or strings containing only whitespaces.

Note: Values that are not strings are first converted into their string equivalent.

[x..y]

Matches any integer value in the range [x..y].

For example [1..3] matches 12 and 3.

{x,y,z}

Matches any value equal to x, y, or z.

For example {foo,bar} matches foo and bar.

not rule

Matches any value that do not match the rule.

For example not hot matches 'cool' and 'mild' or any other value different from hot.

xxxx

Matches any value whose string representation is xxxx.

For example foo matches 'foo'. 

Related Links