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

Allow user-defined aggregate functions (UDAs) to be defined in a model

    XMLWordPrintableJSON

Details

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

    Description

      Allow user-defined aggregate functions (UDAs) to be defined in a model, using a simple class to implement the UDA.

      A class can implement a UDA if it has init and add methods, and optionally initAdd, merge and result. For example,

      ```java
      class MySumAggFun {
      public MySumAggFun() {}
      public long[] init();
      public long[] initAdd(int v);
      public void add(long[] accumulator, int v);
      public long[] merge(long[] accumulator0, long[] accumulator1);
      public long result(long[] accumulator);
      }
      ```

      Every UDA has argument types (in general it can be a list with 0 or more elements, but usually 1), accumulator type, and result type. These are inferred from the method signatures.

      In this example, the accumulator type is `long[]`, the argument type is `[int]`, and the result type is `long`.

      If there is no `result` method, the accumulator and result types are the same, and the result is just the accumulator.

      If there is no `initAdd` method, Optiq calls `init` followed by `add`.

      The methods can all be static, in which case the class does not need a public zero-argument constructor.

      Example model:

      ```json
      schemas: {
      {
      name: ‘HR’,
      functions: [

      { name: ‘MY_SUM’, className: ‘com.example.MySumAggFun’ }

      ]
      }
      ```

      ---------------- Imported from GitHub ----------------
      Url: https://github.com/julianhyde/optiq/issues/237
      Created by: julianhyde
      Labels:
      Created at: Sun Apr 06 23:31:50 CEST 2014
      State: closed

      Attachments

        Activity

          People

            Unassigned Unassigned
            github-import GitHub Import
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: