-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array/list inputs to engine and/or simulator? #23
Comments
Hi @michaelglasson , I have an idea, just need to prepare and test the samples. Will get back to you |
Hi @adamecr, my colleague and I have confirmed some really good news about DMNEngine. In code, we found that we can pass arrays and other complex data structures to a literal expression. We can use a range of C# expressions and are not limited just to S-FEEL. This is great news. One thing we have not quite conquered is the possibility to use an array as a column input for a decision table. We tried a couple of things, but in each case, the exception we encountered was the unary test input == expression. Ideally, for example, we could put an expression into an input cell in a decision table and use the column input in the expression. For example, in Camunda 7, the default input variable is called 'cellInput'. We can use it in an expression in a table cell like, 'list contains("x", cellInput). We are working on it. |
Hi @michaelglasson , The "magic" is not to do the contains check in a rule cell, but to do it as a column definition ( You can also do and use the check in table output (for example when not a necessary part of decision table but might be used further in decisions tree) or in the expression decision. Hope this helps, I will prepare the equivalent DMN if needed.
|
@michaelglasson - this is the DMN that can be parsed and executed in code. |
To make it work in Simulator, it's necessary to tweak it a bit :-(
Then modify
This would "inject" the string extension method |
@adamecr, I am not sure what I have done to cause you to devote so much of your 'hobby time' to my enquries, but thank you very much. I think I understand the approach you have outlined. I have downloaded the DMN and looked at the code you posted above. If we provide a list as an inputParameter, we can use it in the column definition expression. Very nice. I will certainly be able to use that. The simulator modification is not only helpful, but gives some insight into the code. So thanks for that. I have an additional comment which I will post separately so as not to confuse the issue. |
No, I don't think DMNEngine supports either the use of ? or the variable name in the inputParameter. Exception while parsing the expression list==list.Contains(5) and Exception while parsing the expression list==?.Contains(5). The issue appears to be that '==' operator is applied even when it is not needed. Perhaps what we should see is that when the inputParameter includes the '?' symbol or - perhaps better - the name of the input variable, then the cell is evaluated as a literal expression returning a Boolean. |
Now all I have to do is find the place in the DMNEngine code where this logic is handled. |
OK. The SfeelParser is the component that puts in left == right like this:
Maybe we can do something like:
The first one would stay true to DMN, but might stop us from using the c# ?: ternary operator. We could get around that by allowing us to select the expression language either for the whole column (S-FEEL or C#) or for each individual cell. If we select C#, then we need to distinguish between the ? in the ?: operator and the ? that stands for the input variable. I can have a go at making the changes, but hopefully, you can spare the time to do the update? Let me know what you think. |
@michaelglasson - I'll think about it. I would say, that conceptually, you can achieve the change from left==right into right-> bool the way that the column expression will be true. This will transform to true==right and you can already use any variable (input) in the rule expression (right side) . I'm out of computer, so can't give it a try, but I believe it's the way... The midnight is approaching here, tomorrow I'll also show you how to extend the functionality for the right side. these two things together should give you all you need, however, to manage the expectations, it will not be FEEL syntax |
Hi @michaelglasson , I used the custom execution context with following extensions:
This helped me to play a bit with following decision table: Actually, it's possible to have a DE (=Dynamic Expresso) expression in the rule, but there are limits due to SfeelParser logic. For example I was not able to do Bringing the function But still, extensions only can do quite some work.... |
Those changes might just enrich DMNEngine enough to allow me to express all the rules in my use cases. I agree that hacks are not necessarily the best way to keep your code maintainable and that putting them in does not give as much satisfaction as finding a more elegant solution :). I wonder if you have looked at DMN 1.3 Specification section 8.3.3 on page 77. It talks about 4 criteria by which an inputExpression may satisfy its corresponding inputEntry. Item d) says One of the expressions in the inputEntry is a boolean expressions using the special ‘?’ variable and that I think that is the feature you are aiming for with the '#?' hack. If so, then, that may well be good enough for us at the moment. |
As an alternative to the SFeel vs Dynamic Expresso approach might be to enable the DMN feature that allows the expression language to be set for the whole DMN, for table column or for a table cell. |
And once again thanks for your engagement. I am an Australian enterprise architect looking for a solution for embedding rule processing within a larger .Net application. If we can do this, then we will be able to give our rule authors the graphic DMN rule creation experience, while allowing developers to embed those definitions into their code and evaluate them in place. |
Yep, it's not exact 1:1 match I think but the idea is to provide you with similar functionality (to be able to use the "column value" in the "rule cell" |
I'm a bit tempted to think about implementing the FEEL support and support additional DMN elements like boxed expressions. But I'm afraid this is not a "month or two" task :-( |
Cool! I'm always happy that something I do "for fun" can help the others to "do something real", so thanks for using it |
Hi again, Radek. I have reviewed the documentation and some of the source code, but I cannot confirm whether or not array/list inputs are usable either in the engine or the simulator. I am able to evaluate inputs like ["a","b","c"] in the Camunda engine using FEEL's 'some x in y satisfies z' construct.
I see that the simulator documentation says: When the type is not identified by parser from the definition (or it's identified but not as the known type), the entry is via text field and the combo box is provided to let the user choose a know type to which the raw value should be converted before passing to the execution context as the input parameter. I am guessing, however, that this does not allow me to enter an object like an array.
I think I can work around this by breaking my decision into two or more tables or expressions, so it's not a killer issue for me at the moment.
Cheers,
Michael
PS. It's really generous of you to contribute products like this to the public domain. Much appreciated.
The text was updated successfully, but these errors were encountered: