2019-12-09 13:12:54 +00:00
|
|
|
#include <Functions/IFunctionImpl.h>
|
2018-09-08 01:24:09 +00:00
|
|
|
#include <Functions/FunctionHelpers.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <Core/ColumnNumbers.h>
|
|
|
|
#include <Columns/ColumnNullable.h>
|
2019-08-21 02:28:04 +00:00
|
|
|
#include <Common/assert_cast.h>
|
2018-09-08 01:24:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Implements the function isNotNull which returns true if a value
|
|
|
|
/// is not null, false otherwise.
|
|
|
|
class FunctionIsNotNull : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "isNotNull";
|
|
|
|
|
|
|
|
static FunctionPtr create(const Context &)
|
|
|
|
{
|
|
|
|
return std::make_shared<FunctionIsNotNull>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getNumberOfArguments() const override { return 1; }
|
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
|
|
|
bool useDefaultImplementationForConstants() const override { return true; }
|
2019-10-02 17:51:00 +00:00
|
|
|
ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t /*number_of_arguments*/) const override { return {0}; }
|
2018-09-08 01:24:09 +00:00
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes &) const override
|
|
|
|
{
|
|
|
|
return std::make_shared<DataTypeUInt8>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override
|
|
|
|
{
|
|
|
|
const ColumnWithTypeAndName & elem = block.getByPosition(arguments[0]);
|
2019-06-27 18:50:20 +00:00
|
|
|
if (auto * nullable = checkAndGetColumn<ColumnNullable>(*elem.column))
|
2018-09-08 01:24:09 +00:00
|
|
|
{
|
|
|
|
/// Return the negated null map.
|
|
|
|
auto res_column = ColumnUInt8::create(input_rows_count);
|
2019-06-26 17:20:33 +00:00
|
|
|
const auto & src_data = nullable->getNullMapData();
|
2019-08-21 02:28:04 +00:00
|
|
|
auto & res_data = assert_cast<ColumnUInt8 &>(*res_column).getData();
|
2018-09-08 01:24:09 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < input_rows_count; ++i)
|
|
|
|
res_data[i] = !src_data[i];
|
|
|
|
|
|
|
|
block.getByPosition(result).column = std::move(res_column);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/// Since no element is nullable, return a constant one.
|
2018-10-22 08:54:54 +00:00
|
|
|
block.getByPosition(result).column = DataTypeUInt8().createColumnConst(elem.column->size(), 1u);
|
2018-09-08 01:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void registerFunctionIsNotNull(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionIsNotNull>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|