-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[DROOLS-1175] infer numeric type for sum expression in an accumulate … #827
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
Conversation
| if (functionName.equals( "sum" )) { | ||
| Class<?> exprClass = MVELExprAnalyzer.getExpressionType( context, declCls, source, fc.getParams()[0] ); | ||
| if (exprClass == int.class || exprClass == Integer.class) { | ||
| functionName = "sumI"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, I believe they should have been named "sumInteger" etc, but I believe that ship has already sailed, didn't it?
|
If you've seen any previous mails with stacktraces: those don't count - I had another local branch vs your branch name conflict issue locally. I deleted all those from the Github page, so only relevant comments are still on this github PR page. There's still an issue: with a sum of integers, the call to IntegerSumAccumulateFunction.accumulate(Serializable context, Object value) actually delivers a Long value (which is nicely cast to an int, except in my drools fork (which fixes some bugs) where it triggers a ClassCastException). It shouldn't be deliver an Long value. For example, in this rule: with this class That sum value should definitely be an |
… loss in Integer Long functions + remove unneeded "throws Exception"
|
I've send in a pull request for your branch that fixes the BigDecimal rounding issue and exposes the Long casting issue: mariofusco#1 |
Fix rounding issues in BigDecimal and BigInteger functions
|
@ge0ffrey I merged your PR into mine but I still have a doubt: can we safely assume that an accumulator of Numbers of a given class will be exclusively fed by instances of that class? E.g. is it correct that an accumulator on BigDecimal eventually throws a CCE if for some reason is passed with a double? I must admit that at the moment I have no evidence of how this could happen, I just wanted to be sure that this is acceptable. Also what happens if it is passed with a null? I'm afraid this is far more probable and at the moment it will throw a NPE. What should we do in that case? Propagate the NPE? Considering it as a zero? That said if I have understood correctly you're saying that this current implementation triggers an error in that requiredCpuPowerTotal rule? If so how could I reproduce this issue? |
|
This PR fails, probably because of the ClassCastExceptions that are happening. Before we revert those casting and head back to doubleValue() (which is a rounding error when done some BigDecimals and even some longs), we might want to check if we can fix that and keep the casts. About a double being passed to a BigDecimal accumulate: isn't that impossible because the compile time model guarantees that the parameter is of type BigDecimal? It's like saying that the method AtomicLong.addAndGet(long delta) should internally deal with delta not being a long but a double, no? About nulls: if for backwards compatibility you want to keep null + null = null and null + 7 = 7 etc, I wouldn't mind, but otherwise I 'd just fail fast on that too. Let's discuss Wednesday afternoon or Friday when I back in the home-office? |
|
Ok, let's discuss this when you'll be back at home. For now I just want to give a look at that CCE you mentioned (and possibly fix it if I'll have time). How can I reproduce it? |
|
To reproduce run AccumulateTest or any of the others that are failing on Jenkins. |
|
Replaced by #867 |
* KOGITO-5635 Added native LTS check * Apply suggestions from code review
…pattern