ClickHouse/src/Functions/EmptyImpl.h

66 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
2019-03-03 20:08:39 +00:00
#include <Common/memcmpSmall.h>
2018-09-09 23:47:56 +00:00
#include <Columns/ColumnString.h>
2018-09-09 23:36:06 +00:00
#include <Functions/FunctionFactory.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
template <bool negative = false>
struct EmptyImpl
{
/// If the function will return constant value for FixedString data type.
static constexpr auto is_fixed_to_constant = false;
static void vector(const ColumnString::Chars & /*data*/, const ColumnString::Offsets & offsets, PaddedPODArray<UInt8> & res)
2018-09-09 23:36:06 +00:00
{
size_t size = offsets.size();
ColumnString::Offset prev_offset = 1;
for (size_t i = 0; i < size; ++i)
{
res[i] = negative ^ (offsets[i] == prev_offset);
prev_offset = offsets[i] + 1;
}
}
/// Only make sense if is_fixed_to_constant.
static void vectorFixedToConstant(const ColumnString::Chars & /*data*/, size_t /*n*/, UInt8 & /*res*/)
2018-09-09 23:36:06 +00:00
{
throw Exception("Logical error: 'vectorFixedToConstant method' is called", ErrorCodes::LOGICAL_ERROR);
2018-09-09 23:36:06 +00:00
}
static void vectorFixedToVector(const ColumnString::Chars & data, size_t n, PaddedPODArray<UInt8> & res)
2018-09-09 23:36:06 +00:00
{
2019-03-04 15:50:23 +00:00
size_t size = data.size() / n;
for (size_t i = 0; i < size; ++i)
res[i] = negative ^ memoryIsZeroSmallAllowOverflow15(data.data() + i * n, n);
2018-09-09 23:36:06 +00:00
}
static void array(const ColumnString::Offsets & offsets, PaddedPODArray<UInt8> & res)
{
size_t size = offsets.size();
ColumnString::Offset prev_offset = 0;
for (size_t i = 0; i < size; ++i)
{
res[i] = negative ^ (offsets[i] == prev_offset);
prev_offset = offsets[i];
}
}
2021-07-04 14:26:09 +00:00
static void uuid(const ColumnUUID::Container & container, size_t n, PaddedPODArray<UInt8> & res)
{
for (size_t i = 0; i < n; ++i)
2021-11-26 14:39:03 +00:00
res[i] = negative ^ (container[i].toUnderType() == 0);
2021-07-04 14:26:09 +00:00
}
2018-09-09 23:36:06 +00:00
};
}