A DMN decision table that returns a list of matching rules?

173 views
Skip to first unread message

Leonard Budney

unread,
Mar 29, 2023, 9:36:07 PM3/29/23
to Drools Usage
Hi!

I'm building some DMN rules that include a decision table with a hit policy of "Collect." I expect the output from the table to be a list of all decisions corresponding to matching rows in the table. I've attached a simple example DMN that I created on Drools Workbench, and a unit test file to go with it.

The rules simply identify a number as "Small" if it's less than 10, "Positive" if it's greater than 0, "Even" if it's both even and less than 11, and "Odd" if it's odd and less than 10. So for example I expect the output for the number 8 to be: ["Small", "Positive", "Even"].

It's quite possible I'm setting up the table wrong, and it's also possible that my notation in the unit tests is wrong, but the documentation has me going in circles. For example, the docs explicitly state that Drools implements an enhancement over DMN by allowing explicit declaration of lists, but it doesn't actually specify how (perhaps using the "list" function?), and nowhere does it illustrate specifying that a decision table can return a list.

When I set the return type to "string," as in the attached example, but put "null" (without quotes) in the decision field, I got an error message that "[]" was not of type string, which I found encouraging, because an empty list is exactly what I was hoping to get back, but I couldn't find a way to set a list type.

One thing I tried was defining a type as an alias for string, but enabling the "is collection" attribute, and Drools did indeed allow me to select that type for the output of the table -- but when running the rule, I got an "unrecognized data type" error. The DMN file did contain the ItemDefinition elements, so I don't know why that would be.

Another thing I noticed was that, when just one rule matched, a string was returned rather than a one-element list. This was with the type set to "string" and the hit policy set to "Collect," though.

Can anyone point me to the right bit of documentation and/or tell me how to use a "Collect" hit policy to get a list of decisions corresponding to all matching rules?

Thanks!
Len.


DMN Decision Table Collect.zip
Message has been deleted
Message has been deleted

Yeser Amer

unread,
Mar 31, 2023, 8:23:20 AM3/31/23
to Drools Usage
Hi Leonard!

My first advice is to update your jBPM version, according to your scesim file you're using a very old version of the tool.

Your example is failing because you assigned a "string" as a return type of classification Decision, while the correct type is a List of Strings.
To fix that, you need to create a new Type in the DMN Editor as shown below:

Screenshot 2023-03-30 at 15.30.04.png
As you may notice, tResult is a List of String.

As the next step, please assign the newly create tResult DataType to the Decision output column, as shown below.

Screenshot 2023-03-30 at 15.33.57.png

Now your DMN asset is fixed. Let's update the scesim file accordingly.

Please open the scesim file, and re-assign the EXPECT column to the updated classifications fact. Now you should see it with "List" type

Screenshot 2023-03-30 at 15.39.43.png

After that, the Expected Data should be empty. If you try to add data to that column, a pop-up should appear. Here you can add the expected items list.

Screenshot 2023-03-30 at 15.42.06.png

Repeat the operation for all scenarios. The test should pass.

Screenshot 2023-03-30 at 15.37.59.png

If some step is not clear or you need further assistance, don't hesitate to contact us :)

Thank you, Yeser

Matteo Mortari

unread,
Mar 31, 2023, 9:03:17 AM3/31/23
to drools...@googlegroups.com
Hi Leonard,
I believe your DMN is almost fine, you are just experiencing some issue with the SceSim tool instead.

I would strongly recommend you to file a JIRA/kie-issues record, to describe your experience and difficulty in having a SceSim working as you expected.

My only feedback about the DMN model is that the element "classifications" is not of typeRef FEEL:string, but it's a list of strings.
You could define an ItemDefinition for a list-of-string and use it better.

Screenshot attached the DMN model is behaving correctly (regardless of typeRef for the element actually).

As with the design using the SceSim,
once the DMN is correctly set,
you could use the guided list composition since list-of-string is manageable with the guided modal dialog (screenshot attached).


Hope this helps!
MM


--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/5fcca065-bc76-4b8f-8f56-599706026f35n%40googlegroups.com.


--
Screenshot 2023-03-30 at 13.25.48.png
Screenshot 2023-03-30 at 13.17.49.png

Yeser Amer

unread,
Mar 31, 2023, 9:03:21 AM3/31/23
to drools...@googlegroups.com
Hi Leonard!

My first advice is to update your jBPM version, according to your scesim file you're using a very old version of the tool.

Your example is failing because you assigned a "string" as a return type of classification Decision, while the correct type is a List of Strings.
To fix that, you need to create a new Type in the DMN Editor as shown below:

Screenshot 2023-03-30 at 15.30.04.png
As you may notice, tResult is a List of String.

As the next step, please assign the newly create tResult DataType to the Decision output column, as shown below.

Screenshot 2023-03-30 at 15.33.57.png
Now your DMN asset is fixed. Let's update the scesim file accordingly.

Please open the scesim file, and re-assign the EXPECT column to the updated classifications fact. Now you should see it with "List" type

Screenshot 2023-03-30 at 15.39.43.png
After that, the Expected Data should be empty. If you try to add data to that column, a pop-up should appear. Here you can add the expected items list.

Screenshot 2023-03-30 at 15.42.06.png
Repeat the operation for all scenarios. The test should pass.

Screenshot 2023-03-30 at 15.37.59.png
If some step is not clear or you need further assistance, don't hesitate to contact us :)

Thank you, Yeser

Yeser Amer

Partner Engineer

IBM | Red Hat



Yeser Amer

unread,
Mar 31, 2023, 9:03:24 AM3/31/23
to drools...@googlegroups.com
Hi Leonard!

My first advice is to update your jBPM version, according to your scesim file you're using a very old version of the tool.

Your example is failing because you assigned a "string" as a return type of classification Decision, while the correct type is a List of Strings.
To fix that, you need to create a new Type in the DMN Editor as shown below:

Screenshot 2023-03-30 at 15.30.04.png

As you may notice, tResult is a List of String.

As the next step, please assign the newly create tResult DataType to the Decision output column, as shown below.

Screenshot 2023-03-30 at 15.33.57.png

Now your DMN asset is fixed. Let's update the scesim file accordingly.

Please open the scesim file, and re-assign the EXPECT column to the updated classifications fact. Now you should see it with "List" type

Screenshot 2023-03-30 at 15.39.43.png

After that, the Expected Data should be empty. If you try to add data to that column, a pop-up should appear. Here you can add the expected items list.

Screenshot 2023-03-30 at 15.42.06.png

Repeat the operation for all scenarios. The test should pass.

Screenshot 2023-03-30 at 15.37.59.png

If some step is not clear or you need further assistance, don't hesitate to contact us :)

Thank you, Yeser

Yeser Amer

Partner Engineer

IBM | Red Hat



On Thu, Mar 30, 2023 at 3:36 AM Leonard Budney <len.b...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages