No announcement yet.
  • Filter
  • Time
Clear All
new posts

    Enhancement: Declarative COUNT (DISTINCT x) in OperationBinding's summaryFunctions

    Hello Isomorphic,

    I just read the ServerSummaries docs because I wanted to apply a "DISTINCT" to a field I am counting.

    I noticed this part:
    Fields with customSelectExpression
    Fields with customSelectExpression can be used with server summaries as both groupBy fields or fields with summaryFunction. In case of summaryFunction requested on field with customSelectExpression we will wrap SQL function around the expression, which may or may not be correct.
    which solves the problem for me with customSelectExpression="DISTINCT x" (thanks again for the framework, impressive!).

    But this only works as I'm never using this DataSource in a non-aggregating manner.
    Therefore, an enhancement for the SummaryFunctionType enum would be the following values: COUNTDISTINCT (and SUMDISTINCT, AVGDISTINCT), which would allow a normal use of the DSField as well.

    Best regards

    PS: Regarding the SummaryFunctionType-docs: In the "Enum Constant Summary"-table, for some values details are given, for some not. Below in "Enum Constant Detail" everything becomes clear (e.g. MULTIPLIER handling in server).

    Further on in the same doc the section "Grouping without Summarizing" discusses how to get the equivalent of "select distinct .." without SQL customization. It seems that this approach also makes your proposed new enum values unnecessary.


      Hi Isomorphic,

      it doesn't. I'm talking about statements like
      SELECT a, COUNT(DISTINCT x) FROM table WHERE defaultWhereCondition GROUP BY a
      Use case:
      Count different items while still having the possibility to filter: I want the user to be able to filter on "a" and list the number of different items "x".
      [B]a x[/B]
      1 x
      1 y
      2 x
      2 y
      2 z
      3 x
      Desired result with no filter: 3
      Desired result with filter a=1: 2
      Desired result with filter a=2: 3
      Desired result with filter a=3: 1

      Best regards,


        Ah, yes that makes sense. This would be a valid Feature Sponsorship, but note that it's non-trivial since it needs to be tested across a variety of databases, and implemented for Hibernate and JPA as well as for SQLDataSource.


          Hi Isomorphic,

          thanks, good to know.
          This is not important for me currently, as it can be solved with a customSelectExpression like above and I'm only using the DataSource for this purpose and always with aggregation.

          Best regards