OpenJPA
  1. OpenJPA
  2. OPENJPA-1794

Result of aggregate function MAX is 0 on empty table (instead of NULL).

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.3, 2.1.2, 2.2.1.1, 2.2.3, 2.3.0
    • Component/s: query
    • Labels:
      None

      Description

      Below is a snippet of a test case... the max should be null, but is zero.

      Object count = em.createQuery("Select count(p.pk) from Entity1 p where 1=1").getSingleResult();
      Object max = em.createQuery("Select max(p.pk) from Entity1 p where 1=1").getSingleResult();
      System.out.println("count:"count " max:"+max);

      > count:0 max:0

        Activity

        Hide
        Rick Curtis added a comment -

        Per the spec :
        > If SUM, AVG, MAX, or MIN is used, and there are no values to which the aggregate function can be applied, the result of the aggregate function is NULL.

        Something else to muddy the waters....
        > The Java type that is contained in the result of a query using an aggregate function is as follows:
        > ...
        > *MAX, MIN return the type of the state field to which they are applied.

        In the example detailed above, lets say the p.pk field is a primitive long... A NULL primitive is zero so in that case, it would appear that we are working properly. If p.pk is a java.lang.Long, we are not.

        Show
        Rick Curtis added a comment - Per the spec : > If SUM, AVG, MAX, or MIN is used, and there are no values to which the aggregate function can be applied, the result of the aggregate function is NULL. Something else to muddy the waters.... > The Java type that is contained in the result of a query using an aggregate function is as follows: > ... > *MAX, MIN return the type of the state field to which they are applied. In the example detailed above, lets say the p.pk field is a primitive long... A NULL primitive is zero so in that case, it would appear that we are working properly. If p.pk is a java.lang.Long, we are not.
        Hide
        Vera Filippova added a comment - - edited

        it's 0 for Integer field.

        Show
        Vera Filippova added a comment - - edited it's 0 for Integer field.
        Hide
        Jens Leisenberg added a comment -

        I'm still able to reproduce this problem. Is it planned to fix it for the current release?

        Show
        Jens Leisenberg added a comment - I'm still able to reproduce this problem. Is it planned to fix it for the current release?
        Hide
        Jeremy Bauer added a comment -

        Attaching patch for 2.1.x branch for review. I will be committing the fix to trunk soon.

        Show
        Jeremy Bauer added a comment - Attaching patch for 2.1.x branch for review. I will be committing the fix to trunk soon.
        Hide
        ASF subversion and git services added a comment -

        Commit 1506198 from Jeremy Bauer in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1506198 ]

        OPENJPA-1794 aggregate function with no result set must return null

        Show
        ASF subversion and git services added a comment - Commit 1506198 from Jeremy Bauer in branch 'openjpa/trunk' [ https://svn.apache.org/r1506198 ] OPENJPA-1794 aggregate function with no result set must return null
        Hide
        ASF subversion and git services added a comment -

        Commit 1529241 from Heath Thomann in branch 'openjpa/branches/2.1.x'
        [ https://svn.apache.org/r1529241 ]

        OPENJPA-1794: Return null, rather than 0, on MAX function - back ported to 2.1.x Jeremy Bauer's commit to trunk.

        Show
        ASF subversion and git services added a comment - Commit 1529241 from Heath Thomann in branch 'openjpa/branches/2.1.x' [ https://svn.apache.org/r1529241 ] OPENJPA-1794 : Return null, rather than 0, on MAX function - back ported to 2.1.x Jeremy Bauer's commit to trunk.
        Hide
        ASF subversion and git services added a comment -

        Commit 1529267 from Heath Thomann in branch 'openjpa/branches/2.2.1.x'
        [ https://svn.apache.org/r1529267 ]

        OPENJPA-1794: Return null, rather than 0, on MAX function - back ported to 2.2.1.x Jeremy Bauer's commit to trunk.

        Show
        ASF subversion and git services added a comment - Commit 1529267 from Heath Thomann in branch 'openjpa/branches/2.2.1.x' [ https://svn.apache.org/r1529267 ] OPENJPA-1794 : Return null, rather than 0, on MAX function - back ported to 2.2.1.x Jeremy Bauer's commit to trunk.
        Hide
        ASF subversion and git services added a comment -

        Commit 1529273 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1529273 ]

        OPENJPA-1794: Return null, rather than 0, on MAX function - back ported to 2.2.x Jeremy Bauer's commit to trunk.

        Show
        ASF subversion and git services added a comment - Commit 1529273 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1529273 ] OPENJPA-1794 : Return null, rather than 0, on MAX function - back ported to 2.2.x Jeremy Bauer's commit to trunk.
        Hide
        ASF subversion and git services added a comment -

        Commit 1529340 from Heath Thomann in branch 'openjpa/branches/2.2.1.x'
        [ https://svn.apache.org/r1529340 ]

        OPENJPA-1794: Return null, rather than 0, on MAX function - fixed previous 2.2.1.x commit.

        Show
        ASF subversion and git services added a comment - Commit 1529340 from Heath Thomann in branch 'openjpa/branches/2.2.1.x' [ https://svn.apache.org/r1529340 ] OPENJPA-1794 : Return null, rather than 0, on MAX function - fixed previous 2.2.1.x commit.
        Hide
        ASF subversion and git services added a comment -

        Commit 1529343 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1529343 ]

        OPENJPA-1794: Return null, rather than 0, on MAX function - fixed previous 2.2.x commit.

        Show
        ASF subversion and git services added a comment - Commit 1529343 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1529343 ] OPENJPA-1794 : Return null, rather than 0, on MAX function - fixed previous 2.2.x commit.
        Hide
        ASF subversion and git services added a comment -

        Commit 1624026 from Heath Thomann in branch 'openjpa/branches/2.0.x'
        [ https://svn.apache.org/r1624026 ]

        OPENJPA-1794: Return null, rather than 0, on MAX function - back ported to 2.0.x Jeremy Bauer's commit to trunk.

        Show
        ASF subversion and git services added a comment - Commit 1624026 from Heath Thomann in branch 'openjpa/branches/2.0.x' [ https://svn.apache.org/r1624026 ] OPENJPA-1794 : Return null, rather than 0, on MAX function - back ported to 2.0.x Jeremy Bauer's commit to trunk.

          People

          • Assignee:
            Jeremy Bauer
            Reporter:
            Vera Filippova
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development