Files
scylladb/db/functions/aggregate_function.hh
Avi Kivity 2739ac66ed treewide: drop cql_serialization_format
Now that we don't accept cql protocol version 1 or 2, we can
drop cql_serialization format everywhere, except when in the IDL
(since it's part of the inter-node protocol).

A few functions had duplicate versions, one with and one without
a cql_serialization_format parameter. They are deduplicated.

Care is taken that `partition_slice`, which communicates
the cql_serialization_format across nodes, still presents
a valid cql_serialization_format to other nodes when
transmitting itself and rejects protocol 1 and 2 serialization\
format when receiving. The IDL is unchanged.

One test checking the 16-bit serialization format is removed.
2023-01-03 19:54:13 +02:00

92 lines
2.2 KiB
C++

/*
* Modified by ScyllaDB
*
* Copyright (C) 2022-present ScyllaDB
*/
/*
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
*/
#pragma once
#include "function.hh"
#include <optional>
namespace db {
namespace functions {
/**
* Performs a calculation on a set of values and return a single value.
*/
class aggregate_function : public virtual function {
public:
class aggregate;
/**
* Creates a new <code>Aggregate</code> instance.
*
* @return a new <code>Aggregate</code> instance.
*/
virtual std::unique_ptr<aggregate> new_aggregate() = 0;
/**
* Checks wheather the function can be distributed and is able to reduce states.
*
* @return <code>true</code> if the function is reducible, <code>false</code> otherwise.
*/
virtual bool is_reducible() const = 0;
/**
* Creates a <code>Aggregate Function</code> that can be reduced.
* Such <code>Aggregate Function</code> returns <code>Aggregate</code>,
* which returns not finalized output, but its accumulator that can be
* later reduced with other one.
*
* Reducible aggregate function can be obtained only if <code>is_reducible()</code>
* return true. Otherwise, it should return <code>nullptr</code>.
*
* @return a reducible <code>Aggregate Function</code>.
*/
virtual ::shared_ptr<aggregate_function> reducible_aggregate_function() = 0;
/**
* An aggregation operation.
*/
class aggregate {
public:
using opt_bytes = aggregate_function::opt_bytes;
virtual ~aggregate() {}
/**
* Adds the specified input to this aggregate.
*
* @param values the values to add to the aggregate.
*/
virtual void add_input(const std::vector<opt_bytes>& values) = 0;
/**
* Computes and returns the aggregate current value.
*
* @return the aggregate current value.
*/
virtual opt_bytes compute() = 0;
virtual void set_accumulator(const opt_bytes& acc) = 0;
virtual opt_bytes get_accumulator() const = 0;
virtual void reduce(const opt_bytes& acc) = 0;
/**
* Reset this aggregate.
*/
virtual void reset() = 0;
};
};
}
}