feat(Function): isNullable

This commit is contained in:
lokax 2022-07-05 15:23:07 +08:00
parent 1f2266e45f
commit 849c46e6fa
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,60 @@
#include <Functions/IFunction.h>
#include <Functions/FunctionFactory.h>
#include <DataTypes/DataTypesNumber.h>
#include <Columns/ColumnsNumber.h>
namespace DB
{
namespace
{
class FunctionIsNullable : public IFunction
{
public:
static constexpr auto name = "isNullable";
static FunctionPtr create(ContextPtr)
{
return std::make_shared<FunctionIsNullable>();
}
String getName() const override
{
return name;
}
bool useDefaultImplementationForNulls() const override { return false; }
bool useDefaultImplementationForNothing() const override { return false; }
bool useDefaultImplementationForConstants() const override { return true; }
ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t /*number_of_arguments*/) const override { return {0}; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
size_t getNumberOfArguments() const override
{
return 1;
}
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
{
return std::make_shared<DataTypeUInt8>();
}
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
{
const auto & elem = arguments[0];
return ColumnUInt8::create(input_rows_count, isColumnNullable(*elem.column));
}
};
}
void registerFunctionIsNullable(FunctionFactory & factory)
{
factory.registerFunction<FunctionIsNullable>();
}
}

View File

@ -11,6 +11,7 @@ void registerFunctionNullIf(FunctionFactory & factory);
void registerFunctionAssumeNotNull(FunctionFactory & factory);
void registerFunctionToNullable(FunctionFactory & factory);
void registerFunctionIsZeroOrNull(FunctionFactory & factory);
void registerFunctionIsNullable(FunctionFactory & factory);
void registerFunctionsNull(FunctionFactory & factory)
@ -23,6 +24,7 @@ void registerFunctionsNull(FunctionFactory & factory)
registerFunctionAssumeNotNull(factory);
registerFunctionToNullable(factory);
registerFunctionIsZeroOrNull(factory);
registerFunctionIsNullable(factory);
}
}