IBM / JSONata4Java

Open Source Java version of JSONata
Apache License 2.0
88 stars 36 forks source link

The $sum and $average functions do not appear to allow expressions to be provided as parameters. #307

Closed brainesy closed 1 month ago

brainesy commented 1 month ago

When passing an expression to the $sum function, the error "Argument 1 of function "$sum" must be an array of "number" is returned. This also occurs for the $average function, but works fine when using the $min and $max functions.

Example using jsonata4java version 2.4.9

    $sum( $map(  [ "1", "2" ], $number) )

Expected result: 3 Actual result: Error: Argument 1 of function "$sum" must be an array of "number Result using Javascript version 2.0.5: 3

Other examples using jsonata4java version 2.4.9

    $average( $map(  [ "1", "2" ], $number) )  /* Returns: Argument 1 of function "$sum" must be an array of "number */
    $min( $map(  [ "1", "2" ], $number) )   /* Returns: 1*/
    $max( $map(  [ "1", "2" ], $number) )  /* Returns: 2 */

Other examples using javascript version 2.0.5

    $average( $map(  [ "1", "2" ], $number) )  /* Returns: 1.5 */
    $min( $map(  [ "1", "2" ], $number) )   /* Returns: 1*/
    $max( $map(  [ "1", "2" ], $number) )  /* Returns: 2 */
wnm3 commented 1 month ago

This was a bug because the FunctionUtils used to checkArgument against the signature didn't allow for function calls to match... I've added this check. The min/max functions were not checking arguments so I've added that to those functions.

wnm3 commented 1 month ago

I just pushed version 2.5.0 to Maven Central. It should be there in an hour or so (10:02am EDT). If you agree this problem was fixed, please close this issue. Thanks.

brainesy commented 1 month ago

Thanks for your time in resolving this. I can confirm the issue is resolved in v2.5.0.