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

Add ARG_MIN, ARG_MAX (aka MIN_BY, MAX_BY) aggregate functions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.33.0
    • None

    Description

      Add ARG_MIN, ARG_MAX (aka MIN_BY, MAX_BY) aggregate functions.

      For example, the following query prints the name of the lowest paid employee in each department:

      SELECT deptno, ARG_MIN(sal, ename)
      FROM emp
      GROUP BY deptno;
      
      +------------+------------+
      | deptno     | _c1        |
      +------------+------------+
      | 10         | MILLER     |
      | 20         | SMITH      |
      | 30         | JAMES      |
      +------------+------------+
      

      If multiple employees have the same salary, arbitrarily chooses one to return.

      See Yandex description of ARG_MIN. Also implemented in Alibaba MaxCompute, Clickhouse, DuckDB. (And in Alibaba MaxCompute, Spark SQL, Firebolt, PrestoDB, Trino as MIN_BY/MAX_BY.)

      Attachments

        Issue Links

          Activity

            People

              FrankZou Dan Zou
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m