Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6217

PER clause for aggregate functions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Add a PER clause for windowed aggregate functions, allowing multi-level aggregation. For example,

      SELECT MIN(AVG(revenue) PER MONTH(orderDate))
      FROM Orders
      

      CALCITE-4483 added WITHIN DISTINCT, to allow you to eliminate duplicates values on a key before calling an aggregate function, but it required that all values were the same; this change allows you to specify an aggregate expression to combine those values. Thus WITHIN DISTINCT is a specialization of PER that always uses SINGLE_VALUE; for example, AVG(shipping) WITHIN DISTINCT (orderId) is equivalent to AVG(SINGLE_VALUE(shipping) PER orderId).

      Applications of PER:

      • semi-additive aggregates, e.g. SUM(LAST_VALUE(inventory) PER DAY(inventoryDate));
      • symmetric aggregates, e.g. AVG(SINGLE_VALUE(shipping) PER orderId);
      • distinct aggregates, e.g. SUM(shipping PER shipping) is equivalent to SUM(DISTINCT shipping).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: