2021-05-17 07:30:42 +00:00
|
|
|
#include <Functions/IFunction.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>
|
2022-07-13 17:56:34 +00:00
|
|
|
#include <Columns/ColumnLowCardinality.h>
|
2018-09-08 01:24:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
2018-09-08 01:24:09 +00:00
|
|
|
|
|
|
|
/// Implements the function isNull which returns true if a value
|
|
|
|
/// is null, false otherwise.
|
|
|
|
class FunctionIsNull : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "isNull";
|
|
|
|
|
2021-06-01 12:20:52 +00:00
|
|
|
static FunctionPtr create(ContextPtr)
|
2018-09-08 01:24:09 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<FunctionIsNull>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getNumberOfArguments() const override { return 1; }
|
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
2022-07-13 17:56:34 +00:00
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
|
2018-09-08 01:24:09 +00:00
|
|
|
bool useDefaultImplementationForConstants() const override { return true; }
|
2021-06-22 16:21:23 +00:00
|
|
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
|
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>();
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:24:45 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t) const override
|
2018-09-08 01:24:09 +00:00
|
|
|
{
|
2020-10-19 13:42:14 +00:00
|
|
|
const ColumnWithTypeAndName & elem = arguments[0];
|
2022-07-13 17:56:34 +00:00
|
|
|
if (elem.type->isLowCardinalityNullable())
|
|
|
|
{
|
|
|
|
const auto * low_cardinality_column = checkAndGetColumn<ColumnLowCardinality>(*elem.column);
|
|
|
|
size_t null_index = low_cardinality_column->getDictionary().getNullValueIndex();
|
|
|
|
auto res = DataTypeUInt8().createColumn();
|
|
|
|
auto & data = typeid_cast<ColumnUInt8 &>(*res).getData();
|
2022-07-15 16:23:56 +00:00
|
|
|
data.reserve(low_cardinality_column->size());
|
2022-07-13 17:56:34 +00:00
|
|
|
for (size_t i = 0; i != low_cardinality_column->size(); ++i)
|
|
|
|
data.push_back(low_cardinality_column->getIndexAt(i) == null_index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-04-22 08:31:10 +00:00
|
|
|
if (const auto * nullable = checkAndGetColumn<ColumnNullable>(*elem.column))
|
2018-09-08 01:24:09 +00:00
|
|
|
{
|
|
|
|
/// Merely return the embedded null map.
|
2020-10-19 13:42:14 +00:00
|
|
|
return nullable->getNullMapColumnPtr();
|
2018-09-08 01:24:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/// Since no element is nullable, return a zero-constant column representing
|
|
|
|
/// a zero-filled null map.
|
2020-10-19 13:42:14 +00:00
|
|
|
return DataTypeUInt8().createColumnConst(elem.column->size(), 0u);
|
2018-09-08 01:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
2018-09-08 01:24:09 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(IsNull)
|
2018-09-08 01:24:09 +00:00
|
|
|
{
|
2022-08-27 20:06:03 +00:00
|
|
|
factory.registerFunction<FunctionIsNull>({}, FunctionFactory::CaseInsensitive);
|
2018-09-08 01:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|