DMNType: types within DMN models

31 views
Skip to first unread message

Andrew Higginbottom

unread,
Jan 16, 2023, 5:03:15 AM1/16/23
to Drools Usage
I have a DMN model defined in the KIE Sandbox which executes as expected in the runner within the sandbox.
The same model saved locally, packaged into a kjar and executed with the org.kie.dmn.api.core.DMNRuntime produces errors and cascading nulls due to type errors:

WARN org.kie.dmn.core.ast.DMNFunctionWithReturnType -
Error while evaluating node 'AssignLineIndex': the declared result type is
'DMNType{ my.name.space : tInputLine }'
but the actual value '{index=1, value=1000}' is not an instance of that type

I can "resolve" this issue by either:
1. Declaring the result types to be the Any type throughout the model
2. Disabling runtime type checking by not calling DMNRuntime.setOption(new RuntimeTypeCheckOption(true))

Neither of these feels satisfactory and it seems I'm missing something here.

What are the benefits and use cases of the RuntimeTypeCheckOption?

How can I define the types in the KIE Sandbox and have them correctly used/enforced at runtime?

Matteo Mortari

unread,
Jan 16, 2023, 5:39:53 AM1/16/23
to drools...@googlegroups.com
Hi Andrew,
I believe you can directly exclude bulletpoint 1; if you spent some time defining the ItemDefinition type+constraint, implementing bulletpoint1 would ignore it.
So, excluding bulletpoint 1.

By default, typeCheck is not enabled, neither in Drools DMN engine, neither in Kogito, neither in JITExecutor (used in KIE Sandbox extended service).
This is explicit in the documentation.

Bulletpoint 2 would explicitly enable it and so structural typing + domain constraint (say from ItemDefinition allowedValues) also when applied to InputData would be enforced, in parameters binding and return types, etc.

The correct way to enforce typeCheck is to use the org.kie.dmn.runtime.typecheck option, as you are setting in the trailing snippet of bulletpoint 2.

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/9c831fd7-6747-48e4-8b53-f32dba9b219an%40googlegroups.com.


--

Andrew Higginbottom

unread,
Jan 16, 2023, 6:00:26 AM1/16/23
to Drools Usage
Thank you Matteo

I have checked the documentation link and understand that type checking is not enabled by default. I really only discovered it by accident but now I'm interested in understanding what it is intended to do/prevent.

In my DMN model I have declared a Data Type for the structure I want to work with and configured the BKMs to return that type, yet I see this error at run time with type checking enabled. I don't have any constraints on the structure's fields (other than that they are both 'number').

Should my model, with all types defined and correctly assigned as return types, work with type checking enabled?

Thanks again for your help with this
Andrew

Matteo Mortari

unread,
Jan 16, 2023, 6:11:53 AM1/16/23
to drools...@googlegroups.com
Hi Andrew,
could you share a reproducer/a similar DMN model if the original is NDA to better understand your use-case, please?

> Error while evaluating node 'AssignLineIndex': the declared result type is 'DMNType{ my.name.space : tInputLine }' but the actual value '{index=1, value=1000}' is not an instance of that type
> I don't have any constraints on the structure's fields (other than that they are both 'number').

this could mean:
  • the index property, is not of the correct value
  • the value property, is not of the correct value
  • the tInputLine defines a composite type with some additional properties beyond index and value, which are missing for the value {index=1, value=1000}
  • etc.
With the relevant portion of the DMN model, this can be inspected better.

> Should my model, with all types defined and correctly assigned as return types, work with type checking enabled?

Yes, enabling typeChecking is meant to enforce the modeling aspects of types are actually respected in all capabilities at runtime.
If you get typeCheck errors with this setting enabled, means your runtime values are somehow not matching the original model intent (for their types).

Hope this helps!
MM

Andrew Higginbottom

unread,
Jan 17, 2023, 5:36:36 PM1/17/23
to Drools Usage
Nothing sensitive here. This came out of a personal project to learn more about DMN and Drools by attempting to complete the Advent of Code using DMN (and DRL, and Java, if necessary). I fully realise these are The Wrong Tools For The Job, but what better way to jump in the deep end. I wasn't sure how far I could get but after reading your blog post on Y Combinator in FEEL I'm starting to think anything is possible!

>  the tInputLine defines a composite type with some additional properties beyond index and value, which are missing for the value {index=1, value=1000}

It was this. Thank you for the additional pointers.

I was trying to implement an "enrichment" pattern, starting from an input node and progressing along through the DRD, calling BKMs at various points along the way and slowly "filling in" the properties of the Structure, as a way of breaking down the calculation into steps.

Updating the BKMs to return null for the not-yet-known properties resolves this, as expected.

It seems I need to avoid this pattern and perhaps look into other DMN capabilities for breaking the problem down.

Thanks again
Andrew

Matteo Mortari

unread,
Jan 19, 2023, 1:03:12 PM1/19/23
to drools...@googlegroups.com
Hi Andrew,
I'm glad to hear the pointers I've shared solved your problem.

I believe is worth mentioning the context put() eg: https://kiegroup.github.io/dmn-feel-handbook/#context-put-context-key-value
Is the foundation for context-enrichment of structural typing, in DMN: https://blog.kie.org/2022/01/data-enrichment-use-case-with-dmn-and-bpmn.html

> attempting to complete the Advent of Code using DMN

That sounds fun!
Please do share your findings with the community! Who knows, it might become great content for some guest blog post? ;)

And yes, everything is possible even with DMN... the fun of those exercises is indeed afterwards it's more clear which is the most appropriate tool for the job for different use-cases :)

Hope this helps, and let us know your progress on that fun adventure!
MM

Reply all
Reply to author
Forward
0 new messages