mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
dbms: Cleanup [#METR-19266]
This commit is contained in:
parent
a6ed503f49
commit
655d0cb5b4
@ -905,56 +905,4 @@ using FunctionGreater = FunctionComparison<GreaterOp, NameGreater> ;
|
||||
using FunctionLessOrEquals = FunctionComparison<LessOrEqualsOp, NameLessOrEquals> ;
|
||||
using FunctionGreaterOrEquals = FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>;
|
||||
|
||||
|
||||
template <>
|
||||
void FunctionComparison<EqualsOp, NameEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleEqualityImpl<FunctionComparison<EqualsOp, NameEquals>, FunctionAnd>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<NotEqualsOp, NameNotEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleEqualityImpl<FunctionComparison<NotEqualsOp, NameNotEquals>, FunctionOr>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<LessOp, NameLess>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<LessOp, NameLess>,
|
||||
FunctionComparison<LessOp, NameLess>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<GreaterOp, NameGreater>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<GreaterOp, NameGreater>,
|
||||
FunctionComparison<GreaterOp, NameGreater>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<LessOrEqualsOp, NameLessOrEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<LessOp, NameLess>,
|
||||
FunctionComparison<LessOrEqualsOp, NameLessOrEquals>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<GreaterOp, NameGreater>,
|
||||
FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -46,4 +46,28 @@ public:
|
||||
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
||||
};
|
||||
|
||||
class FunctionIfNull : public IFunction
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = "ifNull";
|
||||
static FunctionPtr create(const Context & context);
|
||||
|
||||
std::string getName() const override;
|
||||
bool hasSpecialSupportForNulls() const override;
|
||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
||||
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
||||
};
|
||||
|
||||
class FunctionNullIf : public IFunction
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = "nullIf";
|
||||
static FunctionPtr create(const Context & context);
|
||||
|
||||
std::string getName() const override;
|
||||
bool hasSpecialSupportForNulls() const override;
|
||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override;
|
||||
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -14,4 +14,54 @@ void registerFunctionsComparison(FunctionFactory & factory)
|
||||
factory.registerFunction<FunctionGreaterOrEquals>();
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<EqualsOp, NameEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleEqualityImpl<FunctionComparison<EqualsOp, NameEquals>, FunctionAnd>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<NotEqualsOp, NameNotEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleEqualityImpl<FunctionComparison<NotEqualsOp, NameNotEquals>, FunctionOr>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<LessOp, NameLess>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<LessOp, NameLess>,
|
||||
FunctionComparison<LessOp, NameLess>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<GreaterOp, NameGreater>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<GreaterOp, NameGreater>,
|
||||
FunctionComparison<GreaterOp, NameGreater>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<LessOrEqualsOp, NameLessOrEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<LessOp, NameLess>,
|
||||
FunctionComparison<LessOrEqualsOp, NameLessOrEquals>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
template <>
|
||||
void FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>::executeTupleImpl(
|
||||
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
||||
{
|
||||
return executeTupleLessGreaterImpl<
|
||||
FunctionComparison<GreaterOp, NameGreater>,
|
||||
FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>>(block, result, x, y, tuple_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <DB/Functions/FunctionsNull.h>
|
||||
#include <DB/Functions/FunctionsLogical.h>
|
||||
#include <DB/Functions/FunctionsComparison.h>
|
||||
#include <DB/Functions/FunctionsConditional.h>
|
||||
#include <DB/Functions/FunctionFactory.h>
|
||||
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
||||
@ -16,6 +17,8 @@ void registerFunctionsNull(FunctionFactory & factory)
|
||||
factory.registerFunction<FunctionIsNull>();
|
||||
factory.registerFunction<FunctionIsNotNull>();
|
||||
factory.registerFunction<FunctionCoalesce>();
|
||||
factory.registerFunction<FunctionIfNull>();
|
||||
factory.registerFunction<FunctionNullIf>();
|
||||
}
|
||||
|
||||
/// Implementation of isNull.
|
||||
@ -135,7 +138,7 @@ DataTypePtr FunctionCoalesce::getReturnTypeImpl(const DataTypes & arguments) con
|
||||
}
|
||||
new_args.push_back(std::make_shared<DataTypeNull>());
|
||||
|
||||
return FunctionMultiIf{}.getReturnType(new_args);
|
||||
return FunctionMultiIf{}.getReturnTypeImpl(new_args);
|
||||
}
|
||||
|
||||
void FunctionCoalesce::executeImpl(Block & block, const ColumnNumbers & arguments, size_t result)
|
||||
@ -172,7 +175,103 @@ void FunctionCoalesce::executeImpl(Block & block, const ColumnNumbers & argument
|
||||
|
||||
block.insert(elem);
|
||||
|
||||
FunctionMultiIf{}.execute(block, multi_if_args, result);
|
||||
FunctionMultiIf{}.executeImpl(block, multi_if_args, result);
|
||||
}
|
||||
|
||||
/// Implementation of ifNull.
|
||||
|
||||
FunctionPtr FunctionIfNull::create(const Context & context)
|
||||
{
|
||||
return std::make_shared<FunctionIfNull>();
|
||||
}
|
||||
|
||||
std::string FunctionIfNull::getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
bool FunctionIfNull::hasSpecialSupportForNulls() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
DataTypePtr FunctionIfNull::getReturnTypeImpl(const DataTypes & arguments) const
|
||||
{
|
||||
if (arguments.size() != 2)
|
||||
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
|
||||
+ toString(arguments.size()) + ", should be 2.",
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
return FunctionMultiIf{}.getReturnTypeImpl({std::make_shared<DataTypeUInt8>(), arguments[0], arguments[1]});
|
||||
}
|
||||
|
||||
void FunctionIfNull::executeImpl(Block & block, const ColumnNumbers & arguments, size_t result)
|
||||
{
|
||||
/// ifNull(col1, col2) == multiIf(isNotNull(col1), col1, col2)
|
||||
|
||||
ColumnWithTypeAndName elem;
|
||||
elem.type = std::make_shared<DataTypeUInt8>();
|
||||
elem.name = "isNotNull(" + block.getByPosition(arguments[0]).name + ")";
|
||||
|
||||
size_t res_pos = block.columns();
|
||||
block.insert(elem);
|
||||
|
||||
FunctionIsNotNull{}.executeImpl(block, {arguments[0]}, res_pos);
|
||||
FunctionMultiIf{}.executeImpl(block, {res_pos, arguments[0], arguments[1]}, result);
|
||||
}
|
||||
|
||||
/// Implementation of nullIf.
|
||||
|
||||
FunctionPtr FunctionNullIf::create(const Context & context)
|
||||
{
|
||||
return std::make_shared<FunctionNullIf>();
|
||||
}
|
||||
|
||||
std::string FunctionNullIf::getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
bool FunctionNullIf::hasSpecialSupportForNulls() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
DataTypePtr FunctionNullIf::getReturnTypeImpl(const DataTypes & arguments) const
|
||||
{
|
||||
if (arguments.size() != 2)
|
||||
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
|
||||
+ toString(arguments.size()) + ", should be 2.",
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
return FunctionMultiIf{}.getReturnTypeImpl({std::make_shared<DataTypeUInt8>(), std::make_shared<DataTypeNull>(), arguments[0]});
|
||||
}
|
||||
|
||||
void FunctionNullIf::executeImpl(Block & block, const ColumnNumbers & arguments, size_t result)
|
||||
{
|
||||
/// nullIf(col1, col2) == multiIf(col1 == col2, NULL, col1)
|
||||
|
||||
ColumnWithTypeAndName elem;
|
||||
elem.type = std::make_shared<DataTypeUInt8>();
|
||||
elem.name = "equals(" + block.getByPosition(arguments[0]).name + "," + block.getByPosition(arguments[1]).name + ")";
|
||||
|
||||
size_t res_pos = block.columns();
|
||||
block.insert(elem);
|
||||
|
||||
FunctionEquals{}.execute(block, {arguments[0], arguments[1]}, res_pos);
|
||||
|
||||
/// Argument corresponding to the NULL value.
|
||||
size_t null_pos = block.columns();
|
||||
|
||||
/// Append a NULL column.
|
||||
ColumnWithTypeAndName null_elem;
|
||||
null_elem.column = std::make_shared<ColumnNull>(block.rowsInFirstColumn(), Null());
|
||||
null_elem.type = std::make_shared<DataTypeNull>();
|
||||
null_elem.name = "NULL";
|
||||
|
||||
block.insert(null_elem);
|
||||
|
||||
FunctionMultiIf{}.executeImpl(block, {res_pos, null_pos, arguments[0]}, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user