OpenJPA
  1. OpenJPA
  2. OPENJPA-712

Not correctly parsing the "having" clause with aggregate functions (ie. max, min, etc)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 1.3.0
    • Fix Version/s: 1.2.3, 1.3.0
    • Component/s: kernel
    • Labels:
      None
    • Environment:
      Configuration:
      - OpenJPA 1.2.0 / OpenJPA 1.3.0 SNAPSHOT
      - Enhancing at Build Time
      - MySQL 5.0.22
    • Patch Info:
      Patch Available

      Description

      Per the discussion on the dev forum (http://n2.nabble.com/Bug-in-HAVING-clause-(JPQL)-td835780.html)...

      I found this easy to reproduce. It seems that our jjpql parser is not properly processing the aggregate functions within the Having clause.

      It seems that these two (valid?) queries are throwing an exception:

      select m.idPublisher, max(m.datePublished)
      from Magazine m
      group by m.idPublisher
      having max(m.datePublished) is null

      select m.idPublisher, max(m.datePublished)
      from Magazine m
      group by m.idPublisher
      having max(m.datePublished) = current_date

      The exception thrown is:

      <openjpa-1.3.0-SNAPSHOT-runknown nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Encountered "max ( m . datePublished ) is" at character 90, but expected: ["(", ")", "*", "+", "-", ".", "/", ":", "<", "<=", "<>", "=", ">", ">=", "?", "ABS", "ALL", "AND", "ANY", "AS", "ASC", "AVG", "BETWEEN", "BOTH", "BY", "CONCAT", "COUNT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "DELETE", "DESC", "DISTINCT", "EMPTY", "ESCAPE", "EXISTS", "FETCH", "FROM", "GROUP", "HAVING", "IN", "INNER", "IS", "JOIN", "LEADING", "LEFT", "LENGTH", "LIKE", "LOCATE", "LOWER", "MAX", "MEMBER", "MIN", "MOD", "NEW", "NOT", "NULL", "OBJECT", "OF", "OR", "ORDER", "OUTER", "SELECT", "SET", "SIZE", "SOME", "SQRT", "SUBSTRING", "SUM", "TRAILING", "TRIM", "UPDATE", "UPPER", "WHERE", <BOOLEAN_LITERAL>, <DECIMAL_LITERAL>, <IDENTIFIER>, <INTEGER_LITERAL>, <STRING_LITERAL>].
      at org.apache.openjpa.kernel.jpql.JPQL.generateParseException(JPQL.java:9501)
      at org.apache.openjpa.kernel.jpql.JPQL.jj_consume_token(JPQL.java:9378)
      ...

      For test case, one could use these classes:

      /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
      /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java

      1. openjpa-712.patch
        0.8 kB
        Fay Wang
      2. OPENJPA-712-1.2.x.patch
        12 kB
        Heath Thomann
      3. openjpa-712-1.patch
        3 kB
        Fay Wang

        Issue Links

          Activity

          Kevin Sutter created issue -
          Hide
          Fay Wang added a comment -

          The change in JPQL.jjt takes into account aggregate expression in the null expression and datetime expression. After apply the patch, you will need to do "mvn compile" for the change to take effect.

          Show
          Fay Wang added a comment - The change in JPQL.jjt takes into account aggregate expression in the null expression and datetime expression. After apply the patch, you will need to do "mvn compile" for the change to take effect.
          Fay Wang made changes -
          Field Original Value New Value
          Attachment openjpa-712.patch [ 12389444 ]
          Hide
          Fay Wang added a comment -

          Attached is the test case.

          Show
          Fay Wang added a comment - Attached is the test case.
          Fay Wang made changes -
          Attachment openjpa-712-1.patch [ 12389461 ]
          Hide
          Catalina Wei added a comment -

          Fix checked in under r692609

          Show
          Catalina Wei added a comment - Fix checked in under r692609
          Catalina Wei made changes -
          Fix Version/s 1.3.0 [ 12313326 ]
          Resolution Fixed [ 1 ]
          Assignee Catalina Wei [ fancy ]
          Status Open [ 1 ] Resolved [ 5 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Fay Wang made changes -
          Link This issue is related to OPENJPA-1814 [ OPENJPA-1814 ]
          Hide
          Heath Thomann added a comment -

          I'm providing patch OPENJPA-712-1.2.x.patch which, as its name implies, is for 1.2.x and includes a 'backport' of OPENJPA-712.patch and OPENJPA-712-1.patch.

          Thanks,

          Heath

          Show
          Heath Thomann added a comment - I'm providing patch OPENJPA-712 -1.2.x.patch which, as its name implies, is for 1.2.x and includes a 'backport' of OPENJPA-712 .patch and OPENJPA-712 -1.patch. Thanks, Heath
          Heath Thomann made changes -
          Attachment OPENJPA-712-1.2.x.patch [ 12455945 ]
          Michael Dick made changes -
          Fix Version/s 1.2.3 [ 12314517 ]
          Patch Info [Patch Available]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          2d 11h 17m 1 Catalina Wei 06/Sep/08 04:50
          Resolved Resolved Closed Closed
          593d 16h 42m 1 Donald Woods 22/Apr/10 21:32

            People

            • Assignee:
              Catalina Wei
              Reporter:
              Kevin Sutter
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development