ClickHouse/dbms/include/DB/Functions/FunctionsMiscellaneous.h

941 lines
23 KiB
C++
Raw Normal View History

2011-11-07 01:15:37 +00:00
#pragma once
#include <DB/Columns/ColumnAggregateFunction.h>
2011-11-07 01:15:37 +00:00
#include <DB/Columns/ColumnConst.h>
#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>
#include <DB/Functions/NumberTraits.h>
2015-05-04 17:52:19 +00:00
#include <DB/Interpreters/ExpressionActions.h>
Squashed commit of the following: commit e712f469a55ff34ad34b482b15cc4153b7ad7233 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:59:13 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 2a002823084e3a79bffcc17d479620a68eb0644b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:58:30 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 9e06f407c8ee781ed8ddf98bdfcc31846bf2a0fe Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:55:14 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 9581620f1e839f456fa7894aa1f996d5162ac6cd Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:54:22 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 2a8564c68cb6cc3649fafaf401256d43c9a2e777 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:47:34 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit cf60632d78ec656be3304ef4565e859bb6ce80ba Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:40:09 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit ee3d1dc6e0c4ca60e3ac1e0c30d4b3ed1e66eca0 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:22:49 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 65592ef7116a90104fcd524b53ef8b7cf22640f2 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:18:17 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 37972c257320d3b7e7b294e0fdeffff218647bfd Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:17:06 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit dd909d149974ce5bed2456de1261aa5a368fd3ff Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:16:28 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 3cf43266ca7e30adf01212b1a739ba5fe43639fd Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:15:42 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 6731a3df96d1609286e2536b6432916af7743f0f Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:13:35 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 1b5727e0d56415b7add4cb76110105358663602c Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:11:18 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit bbcf726a55685b8e72f5b40ba0bf1904bd1c0407 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:09:04 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit c03b477d5e2e65014e8906ecfa2efb67ee295af1 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:06:30 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 2986e2fb0466bc18d73693dcdded28fccc0dc66b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:05:44 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 5d6cdef13d2e02bd5c4954983334e9162ab2635b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:04:53 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit f2b819b25ce8b2ccdcb201eefb03e1e6f5aab590 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:01:47 2017 +0300 Less dependencies [#CLICKHOUSE-2]
2017-01-14 09:00:19 +00:00
2011-11-07 01:15:37 +00:00
namespace DB
{
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
/** Вспомогательные функции:
*
* visibleWidth(x) - вычисляет приблизительную ширину при выводе значения в текстовом (tab-separated) виде на консоль.
*
* toTypeName(x) - получить имя типа
* blockSize() - получить размер блока
* materialize(x) - материализовать константу
2012-08-26 02:08:18 +00:00
* ignore(...) - функция, принимающая любые аргументы, и всегда возвращающая 0.
* sleep(seconds) - спит указанное количество секунд каждый блок.
*
* 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
*
* arrayJoin(arr) - особая функция - выполнить её напрямую нельзя;
2012-08-27 05:13:14 +00:00
* используется только чтобы получить тип результата соответствующего выражения.
*
* replicate(x, arr) - создаёт массив такого же размера как arr, все элементы которого равны x;
* например: replicate(1, ['a', 'b', 'c']) = [1, 1, 1].
*
* sleep(n) - спит n секунд каждый блок.
*
* bar(x, min, max, width) - рисует полосу из количества символов, пропорционального (x - min) и равного width при x == max.
*
* version() - возвращает текущую версию сервера в строке.
*
* finalizeAggregation(agg_state) - по состоянию агрегации получить результат.
*
* runningAccumulate(agg_state) - принимает состояния агрегатной функции и возвращает столбец со значениями,
* являющимися результатом накопления этих состояний для множества строк блока, от первой до текущей строки.
2011-11-07 01:15:37 +00:00
*/
class FunctionCurrentDatabase : public IFunction
{
const String db_name;
public:
static constexpr auto name = "currentDatabase";
static FunctionPtr create(const Context & context);
explicit FunctionCurrentDatabase(const String & db_name) : db_name{db_name}
{
}
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 0;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, const size_t result) override;
};
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.
class FunctionHostName : public IFunction
{
public:
static constexpr auto name = "hostName";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
2016-12-29 19:38:10 +00:00
size_t getNumberOfArguments() const override
{
return 0;
}
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.
*/
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
2011-11-07 01:15:37 +00:00
2011-11-07 01:15:37 +00:00
class FunctionVisibleWidth : public IFunction
{
public:
static constexpr auto name = "visibleWidth";
static FunctionPtr create(const Context & context);
2016-08-17 13:38:33 +00:00
bool hasSpecialSupportForNulls() const override
{
return true;
}
String getName() const override
2011-11-07 01:15:37 +00:00
{
return name;
2011-11-07 01:15:37 +00:00
}
size_t getNumberOfArguments() const override
2011-11-07 01:15:37 +00:00
{
return 1;
2011-11-07 01:15:37 +00:00
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
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:
static constexpr auto name = "toTypeName";
static FunctionPtr create(const Context & context);
String getName() const override
2012-07-15 23:13:08 +00:00
{
return name;
2012-07-15 23:13:08 +00:00
}
bool hasSpecialSupportForNulls() const override
{
return true;
}
size_t getNumberOfArguments() const override
2012-07-15 23:13:08 +00:00
{
return 1;
2012-07-15 23:13:08 +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";
static FunctionPtr create(const Context & context);
2016-07-10 02:14:23 +00:00
String getName() const override
{
return name;
}
bool hasSpecialSupportForNulls() const override
{
return true;
}
size_t getNumberOfArguments() const override
2016-07-10 02:14:23 +00:00
{
return 1;
2016-07-10 02:14:23 +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
};
class FunctionBlockSize : public IFunction
{
public:
static constexpr auto name = "blockSize";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
size_t getNumberOfArguments() const override
{
return 0;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
class FunctionRowNumberInBlock : public IFunction
{
public:
static constexpr auto name = "rowNumberInBlock";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 0;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
/** Инкрементальный номер блока среди вызовов этой функции. */
class FunctionBlockNumber : public IFunction
{
private:
std::atomic<size_t> block_number{0};
public:
static constexpr auto name = "blockNumber";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 0;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
/** Incremental number of row within all blocks passed to this function. */
class FunctionRowNumberInAllBlocks : public IFunction
{
private:
std::atomic<size_t> rows{0};
public:
static constexpr auto name = "rowNumberInAllBlocks";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 0;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
class FunctionSleep : public IFunction
{
public:
static constexpr auto name = "sleep";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
/// Do not sleep during query analysis.
bool isSuitableForConstantFolding() const override
{
return false;
}
size_t getNumberOfArguments() const override
{
return 1;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
class FunctionMaterialize : public IFunction
{
public:
static constexpr auto name = "materialize";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override;
2016-12-29 19:38:10 +00:00
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
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
template <bool negative, bool global>
2012-08-23 18:05:31 +00:00
class FunctionIn : public IFunction
{
public:
static constexpr auto name = FunctionInName<negative, global>::name;
static FunctionPtr create(const Context & context);
String getName() const override
2012-08-23 18:05:31 +00:00
{
return name;
2012-08-23 18:05:31 +00:00
}
size_t getNumberOfArguments() const override
2012-08-23 18:05:31 +00:00
{
return 2;
2012-08-23 18:05:31 +00:00
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
2016-07-10 05:50:09 +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:
static constexpr auto name = "tuple";
static FunctionPtr create(const Context & context);
String getName() const override
2012-08-23 18:43:57 +00:00
{
return name;
2012-08-23 18:43:57 +00:00
}
bool isVariadic() const override
2012-08-23 18:43:57 +00:00
{
return true;
2012-08-23 18:43:57 +00:00
}
size_t getNumberOfArguments() const override
2012-08-23 18:43:57 +00:00
{
return 0;
}
bool isInjective(const Block &) override
{
return true;
}
bool hasSpecialSupportForNulls() const override
{
return true;
2012-08-23 18:43:57 +00:00
}
2016-07-10 02:14:23 +00:00
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
2016-07-10 02:14:23 +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:
static constexpr auto name = "tupleElement";
static FunctionPtr create(const Context & context);
String getName() const override
2012-08-26 02:08:18 +00:00
{
return name;
2012-08-26 02:08:18 +00:00
}
size_t getNumberOfArguments() const override
{
return 2;
}
void getReturnTypeAndPrerequisitesImpl(
const ColumnsWithTypeAndName & arguments, DataTypePtr & out_return_type, ExpressionActions::Actions & out_prerequisites) override;
2012-08-26 02:08:18 +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:
static constexpr auto name = "ignore";
static FunctionPtr create(const Context & context);
2016-12-29 19:38:10 +00:00
bool isVariadic() const override
{
return true;
}
size_t getNumberOfArguments() const override
{
return 0;
}
bool hasSpecialSupportForNulls() const override
{
return true;
}
2012-08-26 02:08:18 +00:00
String getName() const override
2012-08-26 02:08:18 +00:00
{
return name;
2012-08-26 02:08:18 +00:00
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
/** Функция indexHint принимает любое количество любых аргументов и всегда возвращает единицу.
*
* Эта функция имеет особый смысл (см. ExpressionAnalyzer, PKCondition):
* - расположенные внутри неё выражения не вычисляются;
* - но при анализе индекса (выбора диапазонов для чтения), эта функция воспринимается так же,
* как если бы вместо её применения было бы само выражение.
*
* Пример: WHERE something AND indexHint(CounterID = 34)
* - не читать и не вычислять CounterID = 34, но выбрать диапазоны, в которых выражение CounterID = 34 может быть истинным.
*
* Функция может использоваться в отладочных целях, а также для (скрытых от пользователя) преобразований запроса.
*/
class FunctionIndexHint : public IFunction
{
public:
static constexpr auto name = "indexHint";
static FunctionPtr create(const Context & context);
2016-12-29 19:38:10 +00:00
bool isVariadic() const override
{
return true;
}
size_t getNumberOfArguments() const override
{
return 0;
}
bool hasSpecialSupportForNulls() const override
{
return true;
}
2012-08-26 02:08:18 +00:00
String getName() const override
2012-08-26 02:08:18 +00:00
{
return name;
2012-08-26 02:08:18 +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
class FunctionIdentity : public IFunction
{
public:
static constexpr auto name = "identity";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 1;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
2012-08-27 05:13:14 +00:00
class FunctionArrayJoin : public IFunction
{
public:
static constexpr auto name = "arrayJoin";
static FunctionPtr create(const Context & context);
String getName() const override
2012-08-27 05:13:14 +00:00
{
return name;
2012-08-27 05:13:14 +00:00
}
size_t getNumberOfArguments() const override
2012-08-27 05:13:14 +00:00
{
return 1;
2012-08-27 05:13:14 +00:00
}
/** It could return many different values for single argument. */
bool isDeterministicInScopeOfQuery() override
2012-08-27 05:13:14 +00:00
{
return false;
2012-08-27 05:13:14 +00:00
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
/// Because of function cannot be executed directly.
bool isSuitableForConstantFolding() const override
{
return false;
}
2012-08-27 05:13:14 +00:00
};
/** Создаёт массив, размножая столбец (первый аргумент) по количеству элементов в массиве (втором аргументе).
* Используется только в качестве prerequisites для функций высшего порядка.
*/
class FunctionReplicate : public IFunction
{
public:
static constexpr auto name = "replicate";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 2;
}
/// Получить типы результата по типам аргументов. Если функция неприменима для данных аргументов - кинуть исключение.
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 a string with nice Unicode-art bar with resolution of 1/8 part of symbol.
*/
class FunctionBar : public IFunction
{
public:
static constexpr auto name = "bar";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
bool isVariadic() const override
{
return true;
}
size_t getNumberOfArguments() const override
{
return 0;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
private:
template <typename T>
T extractConstant(Block & block, const ColumnNumbers & arguments, size_t argument_pos, const char * which_argument) const;
template <typename T>
static void fill(const PaddedPODArray<T> & src,
ColumnString::Chars_t & dst_chars,
ColumnString::Offsets_t & dst_offsets,
Int64 min,
Int64 max,
Float64 max_width);
template <typename T>
static void fill(T src, String & dst_chars, Int64 min, Int64 max, Float64 max_width);
template <typename T>
static bool executeNumber(const IColumn & src, ColumnString & dst, Int64 min, Int64 max, Float64 max_width);
template <typename T>
static bool executeConstNumber(const IColumn & src, ColumnConstString & dst, Int64 min, Int64 max, Float64 max_width);
};
template <typename Impl>
class FunctionNumericPredicate : public IFunction
{
public:
static constexpr auto name = Impl::name;
static FunctionPtr create(const Context &);
2016-12-29 19:38:10 +00:00
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 1;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, const size_t result) override;
template <typename T>
bool execute(Block & block, const IColumn * in_untyped, const size_t result);
};
struct IsFiniteImpl
{
static constexpr auto name = "isFinite";
template <typename T>
static bool execute(const T t);
};
struct IsInfiniteImpl
{
static constexpr auto name = "isInfinite";
template <typename T>
static bool execute(const T t);
};
struct IsNaNImpl
{
static constexpr auto name = "isNaN";
template <typename T>
static bool execute(const T t);
};
using FunctionIsFinite = FunctionNumericPredicate<IsFiniteImpl>;
using FunctionIsInfinite = FunctionNumericPredicate<IsInfiniteImpl>;
using FunctionIsNaN = FunctionNumericPredicate<IsNaNImpl>;
2016-07-10 02:14:23 +00:00
/** Returns server version (constant).
*/
class FunctionVersion : public IFunction
{
public:
static constexpr auto name = "version";
static FunctionPtr create(const Context & context);
2016-12-29 19:38:10 +00:00
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 0;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
private:
std::string getVersion() const;
};
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";
static FunctionPtr create(const Context & context);
2016-04-09 07:47:08 +00:00
FunctionUptime(time_t uptime_) : uptime(uptime_)
{
}
2016-12-29 19:38:10 +00:00
String getName() const override
2016-04-09 07:47:08 +00:00
{
return name;
2016-04-09 07:47:08 +00:00
}
size_t getNumberOfArguments() const override
2016-04-09 07:47:08 +00:00
{
return 0;
2016-04-09 07:47:08 +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;
};
/** Returns the server time zone.
*/
class FunctionTimeZone : public IFunction
{
public:
static constexpr auto name = "timezone";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 0;
}
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
/** 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.
*
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.
*/
class FunctionRunningAccumulate : public IFunction
{
public:
static constexpr auto name = "runningAccumulate";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 1;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
/** 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>
static void process(const PaddedPODArray<Src> & src, PaddedPODArray<Dst> & dst);
/// 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>
void dispatchForSourceType(const IDataType & src_type, F && f) const;
public:
static constexpr auto name = "runningDifference";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 1;
}
bool isDeterministicInScopeOfQuery() override
{
return false;
}
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
/** Takes state of aggregate function. Returns result of aggregation (finalized state).
*/
class FunctionFinalizeAggregation : public IFunction
{
public:
static constexpr auto name = "finalizeAggregation";
static FunctionPtr create(const Context & context);
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 1;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
};
/** Usage:
* hasColumnInTable('database', 'table', 'column')
*/
class FunctionHasColumnInTable : public IFunction
{
public:
static constexpr auto name = "hasColumnInTable";
2016-12-29 19:38:10 +00:00
size_t getNumberOfArguments() const override
{
return 3;
}
static FunctionPtr create(const Context & context);
FunctionHasColumnInTable(const Context & global_context_) : global_context(global_context_)
{
}
String getName() const override
{
return name;
}
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;
private:
const Context & global_context;
};
2011-11-07 01:15:37 +00:00
}