Decision Table Introduction

This topic explains what decision tables are and how to construct one that accurately reflects your enterprise's business rules.

Overview

Decision tables provide a way to build complex business rules, by defining threshold value conditions and actions in the cells of the table.

Each row can be thought of as single rule in a table made up of many rules. The individual rules are often straightforward, as shown in the examples below. When built into an EventFlow application, the Decision Table operator allows you to to run your decision table against incoming tuples.

Conditions and Actions in Decision Tables

A decision table is made up of columns where where each column represents one condition or one action.

A condition is a predicate test that must evaluate to true for the associated action to be executed. If a decision table rule uses multiple conditions, all conditions for a row must evaluate to true for the action to execute. Condition tests might be looking to match the exact value of an incoming field's value, or might be comparing an incoming value for whether it is greater than, less than, greater than or equal to, or less than or equal to a specified value.

In each rule's row, you define the specific conditions and actions that comprise that rule. For example, if a condition column is Age (comparing to an incoming tuple field of that name), then each row can define a different age range. The action for each row would define what action to take if an incoming tuple contains an Age value within the specified range.

If you add a second condition column called Name, then before the action is taken, the Decision Table operator tests both conditions to see if both the incoming Age and Name field values are within the ranges specified in the rules.

StreamBase decision tables support:

  • StreamBase Condition Columns that supports StreamBase expressions, including most StreamBase expression language functions, and supports data in the scope of the function at runtime. A StreamBase condition column can also contain complex formulas.

  • StreamBase Action Columns that support StreamBase expressions and functions, plus data in the scope of the function at runtime. StreamBase action columns can also contain complex formulas.

The Decision Table operator supports two types of expression syntax for condition and action columns: StreamBase expression or TIBCO BusinessEvents expression syntax. When editing decision tables with the Decision Table Editor, and you click the Add Column button, you can specify whether to add a Condition or Action column (which use BusinessEvents syntax) or a StreamBase Condition or StreamBase Action column (which use StreamBase syntax).

StreamBase expressions are visually distinguished from BusinessEvents expressions by hover text, and by italics in the condition and action columns:

StreamBase Condition Column Features:

  • Column is not necessarily associated with a specific field in the incoming tuple.

  • Cell content contains full StreamBase expressions that resolve to a boolean value.

  • Cell content can reference other fields in the incoming tuple.

  • String literals must be enclosed in double quotes.

BusinessEvents Condition Column Features:

  • Column is associated with a specific field in the incoming tuple, the field with the same name as the column.

  • Left side of cell expression is derived from the field associated with the column. For example, "< 10" becomes "FieldName < 10"

  • Cell content cannot reference other fields in the incoming tuple.

  • Cell content in string columns need not be enclosed in double quotes.

StreamBase Action Column Features:

  • Column is associated with a specific field in the outgoing action tuple.

  • Cell content can contain full StreamBase expressions that must evaluate to the type of the corresponding action tuple field.

  • Cell content can reference incoming tuple fields.

  • String literals must be enclosed in double quotes.

BusinessEvents Action Column Features:

  • Column is associated with a specific field in the outgoing action tuple.

  • Cell content is interpreted as a literal value.

  • Cell content cannot reference incoming tuple fields.

  • Cell content in string columns need not be enclosed in double quotes.

Condition and Action Cell Syntax

The syntax for decision table cell content depends upon the type of column the cell is in, as explained below.

StreamBase Condition Columns:

Cells within StreamBase condition columns can contain arbitrary StreamBase expressions ― with a few limitations ― that evaluate to boolean values. Expressions can reference one or more fields in the decision table operator's input schema. The limitations include:

  • No references to dynamic variables

  • No references to constants defined in .sbapp and .sbint files

  • Simple expression language functions only, no aggregate functions

<stream input="true" name="default.Input" schema="InputSchema">
    <schema name="InputSchema">
        <field description="" name="Name" type="string"/>
        <field description="" name="Age" type="int"/>
        <field description="" name="MyListOfDouble" type="list">
            <element-type type="double"/>
        </field>
        <field description="" name="MyTuple" type="tuple">
            <schema>
                <field description="" name="MyBool" type="bool"/>
                <field description="" name="MyInt" type="int"/>
                <field description="" name="MyString" type="string"/>
                <field description="" name="MyListOfString" type="list">
                    <element-type type="string"/>
                </field>
                <field description="" name="MyTimestamp" type="timestamp"/>
            </schema>
        </field>
    </schema>
</stream>
  • Name == "Peter"

  • length(Name) > 10

  • Age >= 18 && Age <= 21

  • length(MyListOfDouble) > 0 && MyListOfDouble [0] == 3.14159

  • MyTuple.MyBool

  • MyTuple.MyInt == 5

  • MyTuple.MyString == "Paul" && Age > 21

  • length(MyTuple.MyListOfString) > 2 && MyTuple.MyListOfString[2] == "Mary"

  • MyTuple.MyTimestamp > '2016-06-03 10:00:00.000-0400'

  • Age == 17 && Name == "Peter" && MyTuple.MyString == "Paul" && length(MyTuple.MyListOfString) > 2 && MyTuple.MyListOfString[2] == "Mary"

Note that since the last example rule above shares several conditions with rules that precede it, the rule will fire only if Single Row Execution is disabled.

BusinessEvents Condition Columns:

Cells within BusinessEvents condition columns conform ― with a few limitations ― to the shorthand syntax supported by BusinessEvents in which the left-hand side of the expression is implied from the column name and is there omitted in cell value. Cells can contain a combination of literal values, logical and relational operators, spaces, single and double quotes, and parentheses. The limitations include:

  • No references to list field elements

  • No references to dynamic variables

  • No references to constants defined in .sbapp and .sbint files

Literal types include:

Type Example Notes
Integer 123  
Long 1234l lower-case "L" suffix
Double 123.456  
String "This is a string" Single or double quotes are required if the string contains embedded space or single or double quotes. Use \' or \" to embed a single or double quote, respectively.
Timestamp 2016-06-03 10:00:00.000-0400 The hours, minutes, seconds, milliseconds, and timezone values are optional. An optional value must be present if any optional values to the right of it are present. That is, trim values from right to left.

The valid logical operators include:

Type Operator
Logical AND &&
Logical OR ||

The valid relational operators include:

Type Operator Notes
Less than <  
Less than or equal <=  
Greater than >  
Greater than or equal >=  
Equal == This operator is implied when no operator is present.
Not equal !=  

The following table provides alternatives to the examples above using one or more BusinessEvents condition columns:

StreamBase Expression BusinessEvents Condition Column Name(s) BusinessEvents Condition Column Value(s) Notes
Name == "Peter" Name Peter  
length(Name) > 10     Not possible to express using BusinessEvents condition columns.
Age >= 18 && Age <= 21 Age >= 18 && <= 21  
length(MyListOfDouble) > 0 && MyListOfDouble [0] == 3.14159     Not possible to express using BusinessEvents condition columns.
MyTuple.MyBool MyTuple.MyBool true  
MyTuple.MyInt == 5 MyTuple.MyInt 5  
MyTuple.MyString == "Paul" && Age > 21

MyTuple.MyString

Age

Paul

>21

 
length(MyTuple.MyListOfString) > 2 && MyTuple.MyListOfString[2] == "Mary"     Not possible to express using BusinessEvents condition columns.
MyTuple.MyTimestamp > '2016-06-03 10:00:00.000-0400' MyTuple.MyTimestamp > 2016-06-03 10:00:00.000-0400  
Age == 17 && Name == "Peter" && MyTuple.MyString == "Paul" && length(MyTuple.MyListOfString) > 2 && MyTuple.MyListOfString[2] == "Mary"     Not possible to express using BusinessEvents condition columns.

StreamBase Action Columns:

Cells within StreamBase action columns can contain arbitrary StreamBase expressions that evaluate to the data type of the corresponding field in decision table's action schema. Expressions can reference one or more fields in the decision table operator's input schema. StreamBase action column expressions have the same limitations as StreamBase condition column expressions.

BusinessEvents Action Columns:

Cells within BusinessEvents action columns contain literals whose types match those of the corresponding field in the decision table operator's action schema. See the BusinessEvents Condition Columns section above for a list of the supported literal types. BusinessEvents action column values have the same limitations as BusinessEvents condition column values.

Summary of Decision Table File Types

The Decision Table File property of the Decision Table operator can load three decision table file types into the operator, with four different origins, as shown in the following table:

File Type Extension Origin
StreamBase format decision table .sbdt Edited in and saved from the Decision Table Editor in StreamBase Studio.
Excel format decision table .xlsx, .xls Edited in and saved from Microsoft Excel on Windows with the StreamBase Excel Add-in installed.
Edited in and saved from Microsoft Excel on Windows or imported from TIBCO BusinessEvents® WebStudio to StreamBase Studio.
TIBCO BusinessEvents native decision table format .rulefunctionimpl Edited in and saved from TIBCO BusinessEvents. StreamBase Studio can import these files, but cannot edit them.

Debugging Limitation

When using EventFlow debugging, stepping into or over a Decision Table operator is not supported. However, you can still set breakpoints anywhere downstream of such operators. If you are stopped at a breakpoint on an arc feeding a Decision Table operator, you must resume to get across the operator.

For debugging a Decision Table operator, consider using the features of the Decision Table Analyzer's Show Coverage feature to get a debug-like view of how the operator responds to different input tuples.