[jboss-jira] [JBoss JIRA] (JBRULES-1075) Support overloading of accumulate functions: Add int (or long) based sum's, int based avarage's, etc

Geoffrey De Smet (Commented) (JIRA) jira-events at lists.jboss.org
Sat Nov 12 07:14:41 EST 2011


    [ https://issues.jboss.org/browse/JBRULES-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12642310#comment-12642310 ] 

Geoffrey De Smet commented on JBRULES-1075:
-------------------------------------------

Edson,

I 've been running into this issue a lot (with scary overflow or rounding errors such as 0.09 + 0.01 != 0.10).
Something needs to be done. I see 3 ways:

A) Stuff drools-planner with a kit functions, such as sumInteger, sumLong, sumDouble, ...
I'd even recommend people in the manual not to ever use sum.

B) Stuff drools-compiler itself with those functions.

C) Fail-fast overloading of accumulate functions:
Only the following sum functions are available: sum(Integer), sum(Double), sum(Long)
so when "the result type of the expression inside the function parenthesis" is not Integer, Double or Long
a compiler error is thrown.
This presumes that mvel is mostly hard typed.

If we wouldn't have to worry about backwards compatibility, I believe C) would be the best solution:
Using the wrong type to sum leads to bugs, so we can't afford to guess and just go with double,
because double only works for double and int: it does NOT work reliably for long and BigDecimal.

Wdyt?
                
> Support overloading of accumulate functions: Add int (or long) based sum's, int based avarage's, etc 
> -----------------------------------------------------------------------------------------------------
>
>                 Key: JBRULES-1075
>                 URL: https://issues.jboss.org/browse/JBRULES-1075
>             Project: Drools
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>          Components: drools-compiler
>    Affects Versions:  4.0.0.GA
>            Reporter: Geoffrey De Smet
>            Assignee: Edson Tirelli
>            Priority: Minor
>             Fix For: FUTURE
>
>         Attachments: JBRULES-1075.patch
>
>
> TTP nl10 solver has about a 3% performance increase when switching from sumDouble to sumLong (and possibly a bit more when switching to sumInteger)
> There are 2 ways I see to implement this:
> 1) Force the user to explicitly declare he wants to use an integer based sum and add a sumInteger.
> This is not so user-friendly. This is what I 've done in the patch.
> 2) Support overloading of accumulate functions based on the function arguments.
> AFAIK drl is strongly typed (at least with the java dialect), so it should be theoretically possible for the drl parser to see
>  sum($myInteger)
> and bind it to SumIntegerAccumulateFunction,
> while binding
>  sum($myInteger.doubleValue())
> to SumDoubleAccumulateFunction.
> And added advantage is that the drl compiler will also mark some bugs as compiler errors. For example
>   sum($myString)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list