Files
scylladb/cql3/functions/first_function.hh
Avi Kivity b7556e9482 cql3: functions: add "first" aggregate function
first(x) returns the first x it sees in the group. This is useful
for SELECT clauses that return a mix of aggregates and non-aggregates,
for example

    SELECT max(x), x

with inputs of x = { 1, 2, 3 } is expected to return (3, 1).

Currently, this behavior is handled by individual selectors,
which means they need to contain extra state for this, which
cannot be easily translated to expressions. The new first function
allows translating the SELECT clause above to

    SELECT max(x), first(x)

so all selectors are aggregations and can be handled in the same
way.

The first() function is not exposed to users.
2023-07-02 18:15:00 +03:00

19 lines
525 B
C++

// Copyright (C) 2023-present ScyllaDB
// SPDX-License-Identifier: AGPL-3.0-or-later
#pragma once
#include "aggregate_function.hh"
#include "function_name.hh"
/// Factory methods for aggregate functions.
namespace cql3::functions::aggregate_fcts {
/// A aggregate function that accepts a single input; the aggregation result
/// is the first value seen (if the first value is NULL then that's the result too)
shared_ptr<aggregate_function> make_first_function(data_type io_type);
function_name first_function_name();
}