2011-11-07 01:15:37 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
#include <DB/Columns/ColumnAggregateFunction.h>
|
2011-11-07 01:15:37 +00:00
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
#include <DB/Columns/ColumnString.h>
|
2012-08-23 18:43:57 +00:00
|
|
|
|
#include <DB/Columns/ColumnTuple.h>
|
2011-11-07 01:15:37 +00:00
|
|
|
|
#include <DB/Functions/IFunction.h>
|
2016-09-16 22:00:30 +00:00
|
|
|
|
#include <DB/Functions/NumberTraits.h>
|
2015-05-04 17:52:19 +00:00
|
|
|
|
#include <DB/Interpreters/ExpressionActions.h>
|
2017-01-14 09:00:19 +00:00
|
|
|
|
|
2011-11-07 01:15:37 +00:00
|
|
|
|
namespace DB
|
|
|
|
|
{
|
2016-01-11 21:46:36 +00:00
|
|
|
|
namespace ErrorCodes
|
|
|
|
|
{
|
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
|
extern const int ILLEGAL_INDEX;
|
|
|
|
|
extern const int FUNCTION_IS_SPECIAL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 01:15:37 +00:00
|
|
|
|
/** Вспомогательные функции:
|
|
|
|
|
*
|
2013-03-04 10:38:44 +00:00
|
|
|
|
* visibleWidth(x) - вычисляет приблизительную ширину при выводе значения в текстовом (tab-separated) виде на консоль.
|
2014-06-26 00:58:14 +00:00
|
|
|
|
*
|
2013-03-04 10:38:44 +00:00
|
|
|
|
* toTypeName(x) - получить имя типа
|
|
|
|
|
* blockSize() - получить размер блока
|
|
|
|
|
* materialize(x) - материализовать константу
|
2012-08-26 02:08:18 +00:00
|
|
|
|
* ignore(...) - функция, принимающая любые аргументы, и всегда возвращающая 0.
|
2013-03-04 10:38:44 +00:00
|
|
|
|
* sleep(seconds) - спит указанное количество секунд каждый блок.
|
2014-06-26 00:58:14 +00:00
|
|
|
|
*
|
2013-03-04 10:38:44 +00:00
|
|
|
|
* in(x, set) - функция для вычисления оператора IN
|
|
|
|
|
* notIn(x, set) - и NOT IN.
|
2012-08-23 18:05:31 +00:00
|
|
|
|
*
|
|
|
|
|
* tuple(x, y, ...) - функция, позволяющая сгруппировать несколько столбцов
|
2012-08-26 02:08:18 +00:00
|
|
|
|
* tupleElement(tuple, n) - функция, позволяющая достать столбец из tuple.
|
2012-08-27 05:13:14 +00:00
|
|
|
|
*
|
2013-03-04 10:38:44 +00:00
|
|
|
|
* arrayJoin(arr) - особая функция - выполнить её напрямую нельзя;
|
2012-08-27 05:13:14 +00:00
|
|
|
|
* используется только чтобы получить тип результата соответствующего выражения.
|
2013-09-18 20:06:49 +00:00
|
|
|
|
*
|
2015-06-19 02:34:47 +00:00
|
|
|
|
* replicate(x, arr) - создаёт массив такого же размера как arr, все элементы которого равны x;
|
|
|
|
|
* например: replicate(1, ['a', 'b', 'c']) = [1, 1, 1].
|
2013-09-18 20:06:49 +00:00
|
|
|
|
*
|
2013-03-18 10:49:31 +00:00
|
|
|
|
* sleep(n) - спит n секунд каждый блок.
|
2014-08-09 01:51:03 +00:00
|
|
|
|
*
|
|
|
|
|
* bar(x, min, max, width) - рисует полосу из количества символов, пропорционального (x - min) и равного width при x == max.
|
2015-06-03 13:20:19 +00:00
|
|
|
|
*
|
|
|
|
|
* version() - возвращает текущую версию сервера в строке.
|
2015-06-06 00:28:37 +00:00
|
|
|
|
*
|
|
|
|
|
* finalizeAggregation(agg_state) - по состоянию агрегации получить результат.
|
|
|
|
|
*
|
|
|
|
|
* runningAccumulate(agg_state) - принимает состояния агрегатной функции и возвращает столбец со значениями,
|
|
|
|
|
* являющимися результатом накопления этих состояний для множества строк блока, от первой до текущей строки.
|
2011-11-07 01:15:37 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2014-09-23 15:28:21 +00:00
|
|
|
|
class FunctionCurrentDatabase : public IFunction
|
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
const String db_name;
|
2014-09-23 15:28:21 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "currentDatabase";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-09-23 15:28:21 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
explicit FunctionCurrentDatabase(const String & db_name) : db_name{db_name}
|
2014-09-23 15:28:21 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2014-09-23 15:28:21 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
size_t getNumberOfArguments() const override
|
2014-09-23 15:28:21 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2014-09-23 15:28:21 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, const size_t result) override;
|
2014-09-23 15:28:21 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-05-29 00:33:56 +00:00
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/// Get the host name. Is is constant on single server, but is not constant in distributed queries.
|
2013-12-17 13:49:21 +00:00
|
|
|
|
class FunctionHostName : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "hostName";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2013-12-17 13:49:21 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2013-12-17 13:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2013-12-17 13:49:21 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2013-12-17 13:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/** convertToFullColumn needed because in distributed query processing,
|
|
|
|
|
* each server returns its own value.
|
|
|
|
|
*/
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2013-12-17 13:49:21 +00:00
|
|
|
|
};
|
2011-11-07 01:15:37 +00:00
|
|
|
|
|
2015-05-29 00:33:56 +00:00
|
|
|
|
|
2011-11-07 01:15:37 +00:00
|
|
|
|
class FunctionVisibleWidth : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "visibleWidth";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2016-08-17 13:38:33 +00:00
|
|
|
|
bool hasSpecialSupportForNulls() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2011-11-07 01:15:37 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2011-11-07 01:15:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2011-11-07 01:15:37 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2011-11-07 01:15:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
2016-07-06 09:47:55 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2011-11-07 01:15:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-07-15 23:13:08 +00:00
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/// Returns name of IDataType instance (name of data type).
|
2012-07-15 23:13:08 +00:00
|
|
|
|
class FunctionToTypeName : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "toTypeName";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-07-15 23:13:08 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-07-15 23:13:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 05:13:14 +00:00
|
|
|
|
bool hasSpecialSupportForNulls() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2012-07-15 23:13:08 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2012-07-15 23:13:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-07-10 02:14:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns name of IColumn instance.
|
|
|
|
|
class FunctionToColumnTypeName : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "toColumnTypeName";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-07-10 02:14:23 +00:00
|
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 05:13:14 +00:00
|
|
|
|
bool hasSpecialSupportForNulls() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2016-07-10 02:14:23 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2016-07-10 02:14:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-07-15 23:13:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-03 19:40:08 +00:00
|
|
|
|
|
|
|
|
|
class FunctionBlockSize : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "blockSize";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-08-03 19:40:08 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
2012-08-03 19:40:08 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return false;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2012-08-03 19:40:08 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-02-23 03:20:48 +00:00
|
|
|
|
class FunctionRowNumberInBlock : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "rowNumberInBlock";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-02-23 03:20:48 +00:00
|
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2016-02-23 03:20:48 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2016-02-23 03:20:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
2016-02-23 03:20:48 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return false;
|
2016-02-23 03:20:48 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-02-23 03:20:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-05-17 18:25:47 +00:00
|
|
|
|
/** Инкрементальный номер блока среди вызовов этой функции. */
|
|
|
|
|
class FunctionBlockNumber : public IFunction
|
|
|
|
|
{
|
|
|
|
|
private:
|
2017-03-07 18:57:15 +00:00
|
|
|
|
std::atomic<size_t> block_number{0};
|
2016-05-17 18:25:47 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "blockNumber";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-05-17 18:25:47 +00:00
|
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2016-05-17 18:25:47 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2016-05-17 18:25:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
2016-05-17 18:25:47 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return false;
|
2016-05-17 18:25:47 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-05-17 18:25:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-07-08 21:46:18 +00:00
|
|
|
|
/** Incremental number of row within all blocks passed to this function. */
|
|
|
|
|
class FunctionRowNumberInAllBlocks : public IFunction
|
|
|
|
|
{
|
|
|
|
|
private:
|
2017-03-07 18:57:15 +00:00
|
|
|
|
std::atomic<size_t> rows{0};
|
2016-07-08 21:46:18 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "rowNumberInAllBlocks";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-07-08 21:46:18 +00:00
|
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2016-07-08 21:46:18 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2016-07-08 21:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
2016-07-08 21:46:18 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-07-08 21:46:18 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2016-07-08 21:46:18 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-07-08 21:46:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2013-03-04 10:38:44 +00:00
|
|
|
|
class FunctionSleep : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "sleep";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2013-03-04 10:38:44 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2013-03-04 10:38:44 +00:00
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-01-04 03:37:59 +00:00
|
|
|
|
/// Do not sleep during query analysis.
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isSuitableForConstantFolding() const override
|
2013-03-04 10:38:44 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return false;
|
2013-03-04 10:38:44 +00:00
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2013-03-04 10:38:44 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2013-03-04 10:38:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-08-03 19:40:08 +00:00
|
|
|
|
class FunctionMaterialize : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "materialize";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-08-03 19:40:08 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-08-03 19:40:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
template <bool negative, bool global>
|
|
|
|
|
struct FunctionInName;
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct FunctionInName<false, false>
|
|
|
|
|
{
|
|
|
|
|
static constexpr auto name = "in";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct FunctionInName<false, true>
|
|
|
|
|
{
|
|
|
|
|
static constexpr auto name = "globalIn";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct FunctionInName<true, false>
|
|
|
|
|
{
|
|
|
|
|
static constexpr auto name = "notIn";
|
|
|
|
|
};
|
|
|
|
|
template <>
|
|
|
|
|
struct FunctionInName<true, true>
|
|
|
|
|
{
|
|
|
|
|
static constexpr auto name = "globalNotIn";
|
|
|
|
|
};
|
2012-08-23 18:05:31 +00:00
|
|
|
|
|
2014-11-12 17:23:26 +00:00
|
|
|
|
template <bool negative, bool global>
|
2012-08-23 18:05:31 +00:00
|
|
|
|
class FunctionIn : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = FunctionInName<negative, global>::name;
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-08-23 18:05:31 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-08-23 18:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2012-08-23 18:05:31 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 2;
|
2012-08-23 18:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2016-07-10 05:50:09 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-08-23 18:43:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionTuple : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "tuple";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-08-23 18:43:57 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-08-23 18:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isVariadic() const override
|
2012-08-23 18:43:57 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return true;
|
2012-08-23 18:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2012-08-23 18:43:57 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isInjective(const Block &) override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool hasSpecialSupportForNulls() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
2012-08-23 18:43:57 +00:00
|
|
|
|
}
|
2016-07-10 02:14:23 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2016-07-10 02:14:23 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-08-23 18:05:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-26 02:08:18 +00:00
|
|
|
|
|
2016-07-10 02:51:13 +00:00
|
|
|
|
/** Extract element of tuple by constant index. The operation is essentially free.
|
|
|
|
|
*/
|
2012-08-26 02:08:18 +00:00
|
|
|
|
class FunctionTupleElement : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "tupleElement";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-08-26 02:08:18 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-08-26 02:08:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2013-06-04 13:34:46 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 2;
|
2013-06-04 13:34:46 +00:00
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void getReturnTypeAndPrerequisitesImpl(
|
|
|
|
|
const ColumnsWithTypeAndName & arguments, DataTypePtr & out_return_type, ExpressionActions::Actions & out_prerequisites) override;
|
2012-08-26 02:08:18 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-08-26 02:08:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionIgnore : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "ignore";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isVariadic() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
size_t getNumberOfArguments() const override
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-12-30 05:13:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool hasSpecialSupportForNulls() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-08-26 02:08:18 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2012-08-26 02:08:18 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2012-08-26 02:08:18 +00:00
|
|
|
|
}
|
2017-03-09 04:39:45 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-04-15 23:10:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Функция indexHint принимает любое количество любых аргументов и всегда возвращает единицу.
|
|
|
|
|
*
|
|
|
|
|
* Эта функция имеет особый смысл (см. ExpressionAnalyzer, PKCondition):
|
|
|
|
|
* - расположенные внутри неё выражения не вычисляются;
|
|
|
|
|
* - но при анализе индекса (выбора диапазонов для чтения), эта функция воспринимается так же,
|
|
|
|
|
* как если бы вместо её применения было бы само выражение.
|
|
|
|
|
*
|
|
|
|
|
* Пример: WHERE something AND indexHint(CounterID = 34)
|
|
|
|
|
* - не читать и не вычислять CounterID = 34, но выбрать диапазоны, в которых выражение CounterID = 34 может быть истинным.
|
|
|
|
|
*
|
|
|
|
|
* Функция может использоваться в отладочных целях, а также для (скрытых от пользователя) преобразований запроса.
|
|
|
|
|
*/
|
|
|
|
|
class FunctionIndexHint : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "indexHint";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isVariadic() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
size_t getNumberOfArguments() const override
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-12-30 05:13:14 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool hasSpecialSupportForNulls() const override
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-08-26 02:08:18 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2012-08-26 02:08:18 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2012-08-26 02:08:18 +00:00
|
|
|
|
}
|
2017-03-09 04:39:45 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2012-08-26 02:08:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-27 05:13:14 +00:00
|
|
|
|
|
2015-07-13 21:27:08 +00:00
|
|
|
|
class FunctionIdentity : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "identity";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2015-07-13 21:27:08 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2015-07-13 21:27:08 +00:00
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2015-07-13 21:27:08 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2015-07-13 21:27:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2015-07-13 21:27:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-08-27 05:13:14 +00:00
|
|
|
|
class FunctionArrayJoin : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "arrayJoin";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2012-08-27 05:13:14 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2012-08-27 05:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2012-08-27 05:13:14 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2012-08-27 05:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 16:34:05 +00:00
|
|
|
|
/** It could return many different values for single argument. */
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
2012-08-27 05:13:14 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return false;
|
2012-08-27 05:13:14 +00:00
|
|
|
|
}
|
2017-01-05 07:25:23 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2017-01-05 07:25:23 +00:00
|
|
|
|
|
|
|
|
|
/// Because of function cannot be executed directly.
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isSuitableForConstantFolding() const override
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-08-27 05:13:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-09-18 20:06:49 +00:00
|
|
|
|
|
2015-06-19 02:34:47 +00:00
|
|
|
|
/** Создаёт массив, размножая столбец (первый аргумент) по количеству элементов в массиве (втором аргументе).
|
2013-09-18 20:06:49 +00:00
|
|
|
|
* Используется только в качестве prerequisites для функций высшего порядка.
|
|
|
|
|
*/
|
2013-06-04 14:59:05 +00:00
|
|
|
|
class FunctionReplicate : public IFunction
|
|
|
|
|
{
|
2015-06-19 02:34:47 +00:00
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "replicate";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2013-06-04 14:59:05 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2013-06-04 14:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2013-06-04 14:59:05 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 2;
|
2013-06-04 14:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
/// Получить типы результата по типам аргументов. Если функция неприменима для данных аргументов - кинуть исключение.
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2013-09-18 20:06:49 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2013-06-04 14:59:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/** Returns a string with nice Unicode-art bar with resolution of 1/8 part of symbol.
|
|
|
|
|
*/
|
2014-08-09 01:51:03 +00:00
|
|
|
|
class FunctionBar : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 17:23:26 +00:00
|
|
|
|
static constexpr auto name = "bar";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2014-11-12 17:23:26 +00:00
|
|
|
|
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2014-08-09 01:51:03 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2014-08-09 01:51:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isVariadic() const override
|
2014-08-09 01:51:03 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return true;
|
2014-08-09 01:51:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2014-08-09 01:51:03 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2014-08-09 01:51:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
template <typename T>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
T extractConstant(Block & block, const ColumnNumbers & arguments, size_t argument_pos, const char * which_argument) const;
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
|
|
|
|
template <typename T>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static void fill(const PaddedPODArray<T> & src,
|
|
|
|
|
ColumnString::Chars_t & dst_chars,
|
|
|
|
|
ColumnString::Offsets_t & dst_offsets,
|
|
|
|
|
Int64 min,
|
|
|
|
|
Int64 max,
|
|
|
|
|
Float64 max_width);
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
|
|
|
|
template <typename T>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static void fill(T src, String & dst_chars, Int64 min, Int64 max, Float64 max_width);
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
|
|
|
|
template <typename T>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static bool executeNumber(const IColumn & src, ColumnString & dst, Int64 min, Int64 max, Float64 max_width);
|
2014-08-09 01:51:03 +00:00
|
|
|
|
|
|
|
|
|
template <typename T>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static bool executeConstNumber(const IColumn & src, ColumnConstString & dst, Int64 min, Int64 max, Float64 max_width);
|
2014-08-09 01:51:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-04-03 13:30:00 +00:00
|
|
|
|
|
|
|
|
|
template <typename Impl>
|
|
|
|
|
class FunctionNumericPredicate : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = Impl::name;
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context &);
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2015-04-03 13:30:00 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2015-04-03 13:30:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2015-04-03 13:30:00 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2015-04-03 13:30:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2015-04-03 13:30:00 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, const size_t result) override;
|
2015-04-03 13:30:00 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
template <typename T>
|
|
|
|
|
bool execute(Block & block, const IColumn * in_untyped, const size_t result);
|
2015-04-03 13:30:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct IsFiniteImpl
|
|
|
|
|
{
|
|
|
|
|
static constexpr auto name = "isFinite";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
template <typename T>
|
|
|
|
|
static bool execute(const T t);
|
2015-04-03 13:30:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct IsInfiniteImpl
|
|
|
|
|
{
|
|
|
|
|
static constexpr auto name = "isInfinite";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
template <typename T>
|
|
|
|
|
static bool execute(const T t);
|
2015-04-03 13:30:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-04-03 14:52:33 +00:00
|
|
|
|
struct IsNaNImpl
|
2015-04-03 13:30:00 +00:00
|
|
|
|
{
|
2015-04-03 14:52:33 +00:00
|
|
|
|
static constexpr auto name = "isNaN";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
template <typename T>
|
|
|
|
|
static bool execute(const T t);
|
2015-04-03 13:30:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using FunctionIsFinite = FunctionNumericPredicate<IsFiniteImpl>;
|
|
|
|
|
using FunctionIsInfinite = FunctionNumericPredicate<IsInfiniteImpl>;
|
2015-04-03 14:52:33 +00:00
|
|
|
|
using FunctionIsNaN = FunctionNumericPredicate<IsNaNImpl>;
|
2015-04-03 13:30:00 +00:00
|
|
|
|
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/** Returns server version (constant).
|
|
|
|
|
*/
|
2015-06-03 13:11:59 +00:00
|
|
|
|
class FunctionVersion : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "version";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2015-06-03 13:11:59 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2015-06-03 13:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2015-06-03 13:11:59 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2015-06-03 13:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
|
|
|
|
|
2015-06-03 13:11:59 +00:00
|
|
|
|
private:
|
2016-12-12 05:14:46 +00:00
|
|
|
|
std::string getVersion() const;
|
2015-06-03 13:11:59 +00:00
|
|
|
|
};
|
2015-04-28 03:38:41 +00:00
|
|
|
|
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/** Returns server uptime in seconds.
|
|
|
|
|
*/
|
2016-04-09 07:47:08 +00:00
|
|
|
|
class FunctionUptime : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "uptime";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-04-09 07:47:08 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
FunctionUptime(time_t uptime_) : uptime(uptime_)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2016-04-09 07:47:08 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2016-04-09 07:47:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2016-04-09 07:47:08 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2016-04-09 07:47:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
|
|
|
|
|
2016-04-09 07:47:08 +00:00
|
|
|
|
private:
|
|
|
|
|
time_t uptime;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2017-01-22 11:07:45 +00:00
|
|
|
|
/** Returns the server time zone.
|
|
|
|
|
*/
|
|
|
|
|
class FunctionTimeZone : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "timezone";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2017-01-22 11:07:45 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2017-01-22 11:07:45 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2017-01-22 11:07:45 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2017-01-22 11:07:45 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 0;
|
2017-01-22 11:07:45 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2017-01-22 11:07:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/** Quite unusual function.
|
|
|
|
|
* Takes state of aggregate function (example runningAccumulate(uniqState(UserID))),
|
|
|
|
|
* and for each row of block, return result of aggregate function on merge of states of all previous rows and current row.
|
2015-06-06 00:28:37 +00:00
|
|
|
|
*
|
2016-07-10 02:14:23 +00:00
|
|
|
|
* So, result of function depends on partition of data to blocks and on order of data in block.
|
2015-06-06 00:28:37 +00:00
|
|
|
|
*/
|
|
|
|
|
class FunctionRunningAccumulate : public IFunction
|
|
|
|
|
{
|
2015-08-26 11:27:45 +00:00
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "runningAccumulate";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2015-08-26 11:27:45 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2015-06-06 00:28:37 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2015-06-06 00:28:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2015-06-06 00:28:37 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-02-01 14:00:12 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2015-08-25 16:34:28 +00:00
|
|
|
|
};
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2015-08-26 11:27:45 +00:00
|
|
|
|
|
2016-09-16 22:00:30 +00:00
|
|
|
|
/** Calculate difference of consecutive values in block.
|
|
|
|
|
* So, result of function depends on partition of data to blocks and on order of data in block.
|
|
|
|
|
*/
|
|
|
|
|
class FunctionRunningDifference : public IFunction
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/// It is possible to track value from previous block, to calculate continuously across all blocks. Not implemented.
|
|
|
|
|
|
|
|
|
|
template <typename Src, typename Dst>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static void process(const PaddedPODArray<Src> & src, PaddedPODArray<Dst> & dst);
|
2016-09-16 22:00:30 +00:00
|
|
|
|
|
|
|
|
|
/// Result type is same as result of subtraction of argument types.
|
|
|
|
|
template <typename SrcFieldType>
|
|
|
|
|
using DstFieldType = typename NumberTraits::ResultOfSubtraction<SrcFieldType, SrcFieldType>::Type;
|
|
|
|
|
|
|
|
|
|
/// Call polymorphic lambda with tag argument of concrete field type of src_type.
|
|
|
|
|
template <typename F>
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void dispatchForSourceType(const IDataType & src_type, F && f) const;
|
2016-09-16 22:00:30 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "runningDifference";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-09-16 22:00:30 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2016-09-16 22:00:30 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2016-09-16 22:00:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2016-09-16 22:00:30 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2016-09-16 22:00:30 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
bool isDeterministicInScopeOfQuery() override
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-16 22:00:30 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
2016-09-16 22:00:30 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2015-08-25 16:34:28 +00:00
|
|
|
|
};
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2015-08-26 11:27:45 +00:00
|
|
|
|
|
2016-07-10 02:14:23 +00:00
|
|
|
|
/** Takes state of aggregate function. Returns result of aggregation (finalized state).
|
2015-06-06 00:28:37 +00:00
|
|
|
|
*/
|
|
|
|
|
class FunctionFinalizeAggregation : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "finalizeAggregation";
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2015-06-06 00:28:37 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
2015-06-06 00:28:37 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return name;
|
2015-06-06 00:28:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
2015-06-06 00:28:37 +00:00
|
|
|
|
{
|
2017-03-07 18:57:15 +00:00
|
|
|
|
return 1;
|
2015-06-06 00:28:37 +00:00
|
|
|
|
}
|
2017-03-07 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2015-06-06 00:28:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-11-15 10:57:11 +00:00
|
|
|
|
|
|
|
|
|
/** Usage:
|
|
|
|
|
* hasColumnInTable('database', 'table', 'column')
|
|
|
|
|
*/
|
|
|
|
|
class FunctionHasColumnInTable : public IFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = "hasColumnInTable";
|
2016-12-29 19:38:10 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
size_t getNumberOfArguments() const override
|
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
2016-11-15 10:57:11 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
static FunctionPtr create(const Context & context);
|
2016-11-15 10:57:11 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
FunctionHasColumnInTable(const Context & global_context_) : global_context(global_context_)
|
2016-11-15 10:57:11 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
String getName() const override
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2016-11-15 10:57:11 +00:00
|
|
|
|
|
2017-03-07 18:57:15 +00:00
|
|
|
|
void getReturnTypeAndPrerequisitesImpl(
|
|
|
|
|
const ColumnsWithTypeAndName & arguments, DataTypePtr & out_return_type, ExpressionActions::Actions & out_prerequisites) override;
|
2016-12-10 06:12:21 +00:00
|
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-11-15 10:57:11 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const Context & global_context;
|
|
|
|
|
};
|
2011-11-07 01:15:37 +00:00
|
|
|
|
}
|