2014-12-30 12:58:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-12-09 11:14:40 +00:00
|
|
|
#include <AggregateFunctions/IAggregateFunction.h>
|
|
|
|
#include <DataTypes/IDataType.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/ColumnNumbers.h>
|
|
|
|
#include <Core/Names.h>
|
2020-12-09 11:14:40 +00:00
|
|
|
#include <Core/SortDescription.h>
|
|
|
|
#include <Parsers/IAST_fwd.h>
|
2014-12-30 12:58:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-12-09 11:14:40 +00:00
|
|
|
class ASTFunction;
|
|
|
|
|
2014-12-30 12:58:02 +00:00
|
|
|
struct AggregateDescription
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
AggregateFunctionPtr function;
|
2017-06-02 21:37:28 +00:00
|
|
|
Array parameters; /// Parameters of the (parametric) aggregate function.
|
2017-04-01 07:20:54 +00:00
|
|
|
ColumnNumbers arguments;
|
2017-06-02 21:37:28 +00:00
|
|
|
Names argument_names; /// used if no `arguments` are specified.
|
|
|
|
String column_name; /// What name to use for a column with aggregate function values
|
2020-06-23 16:06:56 +00:00
|
|
|
|
2020-07-07 19:51:32 +00:00
|
|
|
void explain(WriteBuffer & out, size_t indent) const; /// Get description for EXPLAIN query.
|
2014-12-30 12:58:02 +00:00
|
|
|
};
|
|
|
|
|
2016-05-28 10:35:44 +00:00
|
|
|
using AggregateDescriptions = std::vector<AggregateDescription>;
|
2014-12-30 12:58:02 +00:00
|
|
|
|
2020-12-09 11:14:40 +00:00
|
|
|
|
|
|
|
struct WindowFunctionDescription
|
|
|
|
{
|
2020-12-18 17:13:28 +00:00
|
|
|
// According to the standard, a window function can refer to a window declared
|
|
|
|
// elsewhere, using its name. We haven't implemented this yet: all windows
|
|
|
|
// are declared in OVER clause, but they still get an auto-generated name,
|
|
|
|
// and this name is used to find the window that corresponds to a function.
|
2020-12-09 11:14:40 +00:00
|
|
|
std::string window_name;
|
2020-12-18 17:13:28 +00:00
|
|
|
|
2020-12-09 11:14:40 +00:00
|
|
|
std::string column_name;
|
|
|
|
const ASTFunction * function_node;
|
|
|
|
AggregateFunctionPtr aggregate_function;
|
|
|
|
Array function_parameters;
|
|
|
|
DataTypes argument_types;
|
|
|
|
Names argument_names;
|
|
|
|
|
|
|
|
std::string dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WindowDescription
|
|
|
|
{
|
|
|
|
std::string window_name;
|
2020-12-18 17:13:28 +00:00
|
|
|
|
|
|
|
// We don't care about the particular order of keys for PARTITION BY, only
|
|
|
|
// that they are sorted. For now we always require ASC, but we could be more
|
|
|
|
// flexible and match any direction, or even different order of columns.
|
2020-12-10 19:06:52 +00:00
|
|
|
SortDescription partition_by;
|
2020-12-18 17:13:28 +00:00
|
|
|
|
2020-12-10 19:06:52 +00:00
|
|
|
SortDescription order_by;
|
2020-12-18 17:13:28 +00:00
|
|
|
|
|
|
|
// To calculate the window function, we sort input data first by PARTITION BY,
|
|
|
|
// then by ORDER BY. This field holds this combined sort order.
|
2020-12-10 19:06:52 +00:00
|
|
|
SortDescription full_sort_description;
|
2020-12-18 17:13:28 +00:00
|
|
|
|
2020-12-09 11:14:40 +00:00
|
|
|
// No frame info as of yet.
|
2020-12-10 19:06:52 +00:00
|
|
|
|
|
|
|
std::string dump() const;
|
2020-12-09 11:14:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using WindowFunctionDescriptions = std::vector<WindowFunctionDescription>;
|
|
|
|
|
|
|
|
using WindowDescriptions = std::unordered_map<std::string, WindowDescription>;
|
|
|
|
|
2014-12-30 12:58:02 +00:00
|
|
|
}
|