2016-07-06 09:47:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Functions/IFunction.h>
|
2016-08-04 23:32:18 +00:00
|
|
|
#include <DB/DataTypes/IDataType.h>
|
|
|
|
#include <DB/Core/ColumnNumbers.h>
|
2016-07-06 09:47:55 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-08-04 23:32:18 +00:00
|
|
|
class Block;
|
|
|
|
class Context;
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
/// Implements the function isNull which returns true if a value
|
|
|
|
/// is null, false otherwise.
|
2016-07-06 09:47:55 +00:00
|
|
|
class FunctionIsNull : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "isNull";
|
2016-08-04 23:32:18 +00:00
|
|
|
static FunctionPtr create(const Context & context);
|
2016-07-06 09:47:55 +00:00
|
|
|
|
2016-08-04 23:32:18 +00:00
|
|
|
std::string getName() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 1; }
|
2016-08-04 23:32:18 +00:00
|
|
|
bool hasSpecialSupportForNulls() const override;
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-07-06 09:47:55 +00:00
|
|
|
};
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
/// Implements the function isNotNull which returns true if a value
|
|
|
|
/// is not null, false otherwise.
|
2016-07-06 09:47:55 +00:00
|
|
|
class FunctionIsNotNull : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "isNotNull";
|
2016-08-04 23:32:18 +00:00
|
|
|
static FunctionPtr create(const Context & context);
|
2016-07-12 14:58:54 +00:00
|
|
|
|
2016-08-04 23:32:18 +00:00
|
|
|
std::string getName() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 1; }
|
2016-08-04 23:32:18 +00:00
|
|
|
bool hasSpecialSupportForNulls() const override;
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-07-25 18:26:45 +00:00
|
|
|
};
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
/// Implements the function coalesce which takes a set of arguments and
|
|
|
|
/// returns the value of the leftmost non-null argument. If no such value is
|
|
|
|
/// found, coalesce() returns NULL.
|
2016-07-25 18:26:45 +00:00
|
|
|
class FunctionCoalesce : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "coalesce";
|
2016-08-04 23:32:18 +00:00
|
|
|
static FunctionPtr create(const Context & context);
|
2016-07-25 18:26:45 +00:00
|
|
|
|
2016-08-04 23:32:18 +00:00
|
|
|
std::string getName() const override;
|
|
|
|
bool hasSpecialSupportForNulls() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
bool isVariadic() const override { return true; }
|
|
|
|
size_t getNumberOfArguments() const override { return 0; }
|
2016-08-04 23:32:18 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
2016-07-06 09:47:55 +00:00
|
|
|
};
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
/// Implements the function ifNull which takes 2 arguments and returns
|
|
|
|
/// the value of the 1st argument if it is not null. Otherwise it returns
|
|
|
|
/// the value of the 2nd argument.
|
2016-08-05 12:30:56 +00:00
|
|
|
class FunctionIfNull : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "ifNull";
|
|
|
|
static FunctionPtr create(const Context & context);
|
|
|
|
|
|
|
|
std::string getName() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 2; }
|
2016-08-05 12:30:56 +00:00
|
|
|
bool hasSpecialSupportForNulls() const override;
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
|
|
|
};
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
/// Implements the function nullIf which takes 2 arguments and returns
|
|
|
|
/// NULL if both arguments have the same value. Otherwise it returns the
|
|
|
|
/// value of the first argument.
|
2016-08-05 12:30:56 +00:00
|
|
|
class FunctionNullIf : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "nullIf";
|
|
|
|
static FunctionPtr create(const Context & context);
|
|
|
|
|
|
|
|
std::string getName() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 2; }
|
2016-08-05 12:30:56 +00:00
|
|
|
bool hasSpecialSupportForNulls() const override;
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
|
|
|
};
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
/// Implements the function assumeNotNull which takes 1 argument and works as follows:
|
|
|
|
/// - if the argument is a nullable column, return its embedded column;
|
|
|
|
/// - otherwise return the original argument.
|
2016-08-12 14:57:39 +00:00
|
|
|
/// NOTE: assumeNotNull may not be called with the NULL value.
|
2016-08-05 12:52:09 +00:00
|
|
|
class FunctionAssumeNotNull : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "assumeNotNull";
|
|
|
|
static FunctionPtr create(const Context & context);
|
|
|
|
|
|
|
|
std::string getName() const override;
|
2016-12-29 19:38:10 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 1; }
|
2016-08-05 12:52:09 +00:00
|
|
|
bool hasSpecialSupportForNulls() const override;
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
|
|
|
};
|
|
|
|
|
2016-07-06 09:47:55 +00:00
|
|
|
}
|