DMN Collect hit policy with count is giving total count instead of distinct output values count

I’ve deployed the below DMN model. In the hit policy selected ‘Collect’ with ‘Count’ operator.

DMN XML Definition:

<definitions xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/" id="definition_6f84d420-6db7-11ea-a029-005056011ac8" name="DiscountTable" namespace="http://www.flowable.org/dmn">
  <decision id="DiscountTable" name="DiscountTable">
    <description>DiscountTable</description>
    <decisionTable id="decisionTable_6f84d420-6db7-11ea-a029-005056011ac8" hitPolicy="COLLECT" aggregation="COUNT">
      <input label="Category">
        <inputExpression id="inputExpression_1" typeRef="string">
          <text>Category</text>
        </inputExpression>
        <inputValues>
          <text>"bronze","silver","gold"</text>
        </inputValues>
      </input>
      <output id="outputExpression_2" label="Discount" name="Discount" typeRef="number">
        <outputValues>
          <text>"5","10","15","20"</text>
        </outputValues>
      </output>
      <rule>
        <inputEntry id="inputEntry_1_1">
          <text><![CDATA[== "silver"]]></text>
        </inputEntry>
        <outputEntry id="outputEntry_2_1">
          <text><![CDATA[10]]></text>
        </outputEntry>
      </rule>
      <rule>
        <inputEntry id="inputEntry_1_2">
          <text><![CDATA[== "bronze"]]></text>
        </inputEntry>
        <outputEntry id="outputEntry_2_2">
          <text><![CDATA[15]]></text>
        </outputEntry>
      </rule>
      <rule>
        <inputEntry id="inputEntry_1_3">
          <text><![CDATA[== "gold"]]></text>
        </inputEntry>
        <outputEntry id="outputEntry_2_3">
          <text><![CDATA[20]]></text>
        </outputEntry>
      </rule>
      <rule>
        <inputEntry id="inputEntry_1_4">
          <text><![CDATA[== "silver"]]></text>
        </inputEntry>
        <outputEntry id="outputEntry_2_4">
          <text><![CDATA[10]]></text>
        </outputEntry>
      </rule>
    </decisionTable>
  </decision>
</definitions>

When we execute this decision execute API with the input variable category as ‘silver’ we are getting the output as count as ‘2.0’
decision execute API Input:

{
“decisionKey”: “DiscountTable”,
“inputVariables”: [ {
“name”: “Category”,
“type”: “string”,
“value”: “silver”
}]
}

decision execute API result:

{
“resultVariables”: [
[ {
“name”: “Discount”,
“type”: “double”,
“value”: 2.0
}]
]
}

As from the flowable documentation, The Collect hit policy count gives the result the number of distinct outputs. here in our case for the silver category, we have the two outputs of the same value ‘10’.
In that case, the count should provide the value as ‘1’ instead of ‘2’. If the result ‘2’ is correct then how the count operator will work. Wll it counts all the occurrences or only distinct output values?.

Hi @HarishArawala.

The definition of the Collect Count hit policy has changed in version 1.2 of the spec.
Prior to 1.2 this was the definition;

# (count): the result of the decision table is the number of distinct outputs.

In 1.2 this changed to;

# (count): the result of the decision table is the number of outputs.

This ‘updated’ behaviour was implemented in the engine and is default now. However; the ‘1.1. behaviour’ can be forced by selecting force DMN 1.1 when saving a Decision Table in Flowable Modeler.

The documentation part you are referring to was not updated and thus not correct. This will be fixed ASAP.

Regards,

Yvo

1 Like

Thank you @yvo, Thanks for your reply.

In the execution result, we are getting the count value as double like ‘2.0’ instead of an integer ‘2’. Is it the expected behaviour?
eg:

{
“name”: “Discount”,
“type”: “double”,
“value”: 2.0
}

Yes. By default it is a Double.

Yvo