Skip to content

User defined aggregate functions #10

@haikyuu

Description

@haikyuu

Taken from Spectrum.

This is how i first imagined the syntax:

FOR accumulator, variable IN "{" iterator-set [, ...]  "}"
REDUCE output-expr ;

Note that this doesn't allow defining arbitrary aggregate functions, but rather executing them, just like FOR.

Example 1

FOR sentence = "", word IN { "hello", "world" }
REDUCE (
  SELECT result ++ " " ++ word
)

This would give a result of hello world.

We can also access the current index by using _index and the original set using_source

FOR sentence = "", word IN { "hello", "world" }
REDUCE (
  SELECT (
    (<str>(SELECT count(_source)) ++ " ") IF _index = 1 ELSE "")
    ++ result ++ " " ++ word ++ " "
)

Result: 2 hello world

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions