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

Query DSL Collections - sum BigDecimal #779

Closed
ldez opened this Issue May 27, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@ldez

ldez commented May 27, 2014

Hi,

The function sum with BigDecimal sum only the integer part.

    @Test
    public void sum() throws Exception {
        final NumberPath<BigDecimal> num = new NumberPath<BigDecimal>(BigDecimal.class, "num");
        final CollQuery query = CollQueryFactory.from(num, Arrays.asList(new BigDecimal("1.6"), new BigDecimal("1.3")));

        // fail because sum use longValue
        assertEquals(new BigDecimal("2.9"), query.uniqueResult(num.sum()));
    }
public final class CollQueryFunctions {
...
    private static final BinaryFunction SUM = new BinaryFunction() {
        @Override
        public Number apply(Number num1, Number num2) {
            if (num1 instanceof Double || num1 instanceof Float) {
                return num1.doubleValue() + num2.doubleValue();
            } else {
                return num1.longValue() + num2.longValue();
            }
        }
    };
...
}

@timowest timowest added the bug label May 29, 2014

@timowest timowest added the fixed label May 29, 2014

@timowest timowest added this to the 3.4.0 milestone May 29, 2014

@ldez

This comment has been minimized.

Show comment
Hide comment
@ldez

ldez Jun 8, 2014

Thanks for this correction.

I saw that you used my test but without remove comment : "// fail because sum use longValue"

package com.mysema.query.collections;

import java.math.BigDecimal;
import java.util.Arrays;

import com.mysema.query.types.path.NumberPath;
import org.junit.Test;
import static org.junit.Assert.*;

public class NumberTest {

    @Test
    public void sum() throws Exception {
        final NumberPath<BigDecimal> num = new NumberPath<BigDecimal>(BigDecimal.class, "num");
        final CollQuery query = CollQueryFactory.from(num, Arrays.asList(new BigDecimal("1.6"), new BigDecimal("1.3")));

        // fail because sum use longValue
        assertEquals(new BigDecimal("2.9"), query.uniqueResult(num.sum()));
    }
}

ldez commented Jun 8, 2014

Thanks for this correction.

I saw that you used my test but without remove comment : "// fail because sum use longValue"

package com.mysema.query.collections;

import java.math.BigDecimal;
import java.util.Arrays;

import com.mysema.query.types.path.NumberPath;
import org.junit.Test;
import static org.junit.Assert.*;

public class NumberTest {

    @Test
    public void sum() throws Exception {
        final NumberPath<BigDecimal> num = new NumberPath<BigDecimal>(BigDecimal.class, "num");
        final CollQuery query = CollQueryFactory.from(num, Arrays.asList(new BigDecimal("1.6"), new BigDecimal("1.3")));

        // fail because sum use longValue
        assertEquals(new BigDecimal("2.9"), query.uniqueResult(num.sum()));
    }
}

timowest added a commit that referenced this issue Jun 8, 2014

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jun 9, 2014

Member

Released in 3.4.0

Member

timowest commented Jun 9, 2014

Released in 3.4.0

@timowest timowest closed this Jun 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment