Aggregate Functions

April 24, 2024 ยท View on GitHub

This page describes how Exasol aggregate functions map to the Virtual Schemas push-down request API.

Exasol Aggregate Functions List

Functions With a Common API

Functions Supporting an Optional distinct Field

The aggregate functions from the table below support an optional distinct field. For this field they require an additional capability *_DISTINCT.

Function NameRequired Set-Function Capabilities
AVGAVG and AVG_DISTINCT
COUNTCOUNT and COUNT_DISTINCT
GROUP_CONCATGROUP_CONCAT and GROUP_CONCAT_DISTINCT
LISTAGGLISTAGG and LISTAGG_DISTINCT
MULMUL and MUL_DISTINCT
STDDEVSTDDEV and STDDEV_DISTINCT
STDDEV_POPSTDDEV_POP and STDDEV_POP_DISTINCT
STDDEV_SAMPSTDDEV_SAMP and STDDEV_SAMP_DISTINCT
SUMSUM and SUM_DISTINCT
VARIANCEVARIANCE and VARIANCE_DISTINCT
VAR_POPVAR_POP and VAR_POP_DISTINCT
VAR_SAMPVAR_SAMP and VAR_SAMP_DISTINCT

Special Cases of Aggregate Functions

This section contains functions that have a special API mapping.

Function NameAPI Mapping Link
COUNTCOUNT function
GROUP_CONCATGROUP_CONCAT function
LISTAGGLISTAGG function

Aggregate Functions Not Included in the API

Function NameComment
ANYThe API uses the SOME function.
CORRNot included in the API.
COVAR_POPNot included in the API.
COVAR_SAMPNot included in the API.
GROUPINGNot included in the API.
PERCENTILE_CONTNot included in the API.
PERCENTILE_DISCNot included in the API.
REGR_*Not included in the API.

Aggregate Functions API

Functions With a Single Argument

An aggregate function with a single argument (consistent with multiple argument version):

{
    "type": "function_aggregate",
    "name": "<function name>",
    "arguments": [
        {
            ...
        }
    ]
}

Functions With Multiple Arguments

An aggregate function with multiple arguments:

{
    "type": "function_aggregate",
    "name": "<function name>",
    "arguments": [
        {
            ...
        },
        {
            ...
        }
    ]
}

Functions With distinct Field

distinct is an optional field.

{
    "type": "function_aggregate",
    "name": "<function name>",
    "distinct": true,
    "arguments": [
        ...
    ],

    ...
}

COUNT

COUNT(*) (Requires set-function capability COUNT_STAR. Please notice, that the set-function capability COUNT is not required in this case.)

{
    "type": "function_aggregate",
    "name": "COUNT"
}

COUNT([DISTINCT] exp) (requires set-function capability COUNT)

COUNT([DISTINCT] (exp1, exp2, ...)) (requires set-function capabilities COUNT and COUNT_TUPLE)

{
    "type": "function_aggregate",
    "name": "COUNT",
    "distinct": true,
    "arguments": [
        {
            ...
        },
        {
            ...
        }
    ]
}

Notes:

  • distinct: Optional. Requires set-function capability COUNT_DISTINCT.

GROUP_CONCAT

GROUP_CONCAT([DISTINCT] arg [orderBy] [SEPARATOR 'separator']) (requires set-function capability GROUP_CONCAT)

{
    "type": "function_aggregate_group_concat",
    "name": "GROUP_CONCAT",
    "distinct": true,
    "arguments": [
        {
            ...
        }
    ],
    "orderBy" : [
        ...
    ],
    "separator":
    {
        "type": "literal_string",
        "value": "..."
    }
}

Notes:

  • distinct: Optional. Requires set-function capability GROUP_CONCAT_DISTINCT.
  • orderBy: Optional. The requested order-by clause, a list of order_by_element elements. Requires the set-function capability GROUP_CONCAT_ORDER_BY.
  • separator: Optional. Requires set-function capability GROUP_CONCAT_SEPARATOR.

LISTAGG

LISTAGG([DISTINCT] arg[, 'separator'] ON OVERFLOW {ERROR | TRUNCATE ['truncationFiller'] {WITH | WITHOUT} COUNT}) [WITHIN GROUP (orderBy)] (requires set-function capability LISTAGG)

{
    "type": "function_aggregate_listagg",
    "name": "LISTAGG",
    "distinct": true,
    "arguments": [
        {
            ...
        }
    ],
    "separator":
    {
        "type": "literal_string",
        "value": "..."
    },
    "overflowBehavior":
    {
        "type": "TRUNCATE",
        "truncationType": "WITH COUNT",
        "truncationFiller":
        {
            "type": "literal_string",
            "value": "..."
        }    
    },
    "orderBy": [
        ...
    ]
}

Notes:

  • arguments: While this is an array, it always has exactly one single element. That is also the reason why Exasol can tell the second optional parameter in the parentesis must be the separator.
  • distinct: Optional. Requires set-function capability LISTAGG_DISTINCT.
  • separator: Optional. Requires set-function capability LISTAGG_SEPARATOR.
  • overflowBehavior: type is "ERROR" (requires set-function capability LISTAGG_ON_OVERFLOW_ERROR) or "TRUNCATE" (requires set-function capability LISTAGG_ON_OVERFLOW_TRUNCATE). Only for "TRUNCATE" the members truncationType and optionally truncationFiller exist. truncationType is "WITH COUNT" or "WITHOUT COUNT".
  • orderBy: Optional. The requested order-by clause, a list of order_by_element elements. Requires the set-function capability LISTAGG_ORDER_BY.