2018-09-09 23:36:06 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionStringOrArrayToT.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/** Calculates the length of a string in bytes.
|
|
|
|
*/
|
|
|
|
struct LengthImpl
|
|
|
|
{
|
|
|
|
static constexpr auto is_fixed_to_constant = true;
|
|
|
|
|
2018-11-25 00:08:50 +00:00
|
|
|
static void vector(const ColumnString::Chars & /*data*/, const ColumnString::Offsets & offsets, PaddedPODArray<UInt64> & res)
|
2018-09-09 23:36:06 +00:00
|
|
|
{
|
|
|
|
size_t size = offsets.size();
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2018-12-27 19:58:30 +00:00
|
|
|
res[i] = offsets[i] - 1 - offsets[i - 1];
|
2018-09-09 23:36:06 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 02:12:31 +00:00
|
|
|
static void vectorFixedToConstant(const ColumnString::Chars & /*data*/, size_t n, UInt64 & res)
|
2018-09-09 23:36:06 +00:00
|
|
|
{
|
|
|
|
res = n;
|
|
|
|
}
|
|
|
|
|
2020-03-23 02:12:31 +00:00
|
|
|
static void vectorFixedToVector(const ColumnString::Chars & /*data*/, size_t /*n*/, PaddedPODArray<UInt64> & /*res*/)
|
2018-09-09 23:36:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void array(const ColumnString::Offsets & offsets, PaddedPODArray<UInt64> & res)
|
|
|
|
{
|
|
|
|
size_t size = offsets.size();
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2018-12-27 19:58:30 +00:00
|
|
|
res[i] = offsets[i] - offsets[i - 1];
|
2018-09-09 23:36:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct NameLength
|
|
|
|
{
|
|
|
|
static constexpr auto name = "length";
|
|
|
|
};
|
|
|
|
|
|
|
|
using FunctionLength = FunctionStringOrArrayToT<LengthImpl, NameLength, UInt64>;
|
|
|
|
|
|
|
|
void registerFunctionLength(FunctionFactory & factory)
|
|
|
|
{
|
2018-10-05 19:52:42 +00:00
|
|
|
factory.registerFunction<FunctionLength>(FunctionFactory::CaseInsensitive);
|
2018-09-09 23:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|