Skip to content

Unknown function exception for a UDA #479

@lizhou1111

Description

@lizhou1111

Describe what's wrong

  1. Run a query with native 'group_uniq_array' aggregate function, it works well
with cte as (select array_join(['a', 'b', 'a']) as a)
select group_uniq_array(a) from cte;
  1. However, if replace 'group_uniq_array' with a UDA 'group_distinct'
    UDA definition
CREATE OR REPLACE AGGREGATE FUNCTION group_distinct(value string)
RETURNS array(string)
LANGUAGE JAVASCRIPT AS $$
{
    initialize: function () {
        this.set = new Set();
    },

    process: function (values, deltas) {
        let is_changelog = deltas !== undefined;
        for (let i = 0; i < values.length; i++) {
            if (is_changelog) {
                if (deltas[i] === -1 && this.set.has(values[i])) {
                    this.set.delete(values[i]);
                } else if (deltas[i] === 1 && values[i] !== "") {
                    if (!this.set.has(values[i])) {
                        this.set.add(values[i]);
                    }
                }
            } else {
                if (!this.set.has(values[i]) && values[i] !== "") {
                    this.set.add(values[i]);
                }
            }
        }
    },

    finalize: function () {
        return [...this.set];
    },

    serialize: function () {
        return JSON.stringify([...this.set]);
    },

    deserialize: function (state_str) {
        this.set = new Set(JSON.parse(state_str));
    },

    merge: function (state) {
        let other_set = JSON.parse(state);
        other_set.forEach((v) => this.set.add(v));
    }
}
$$;
with cte as (select array_join(['a', 'b', 'a']) as a)
select group_distinct(a) from cte;

it throws the below exception

Code: 46. DB::Exception: Received from 127.0.0.1:8463. DB::Exception: Unknown function group_distinct. There is an aggregate function with the same name, but ordinary function is expected here. Maybe you meant: ['array_distinct','geo_distance']. (UNKNOWN_FUNCTION)

How to reproduce

Error message and/or stacktrace

Additional context

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions