2020-08-16 18:17:16 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionStringToString.h>
|
2020-12-02 12:08:03 +00:00
|
|
|
#include <Parsers/queryNormalization.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/find_symbols.h>
|
2020-08-16 18:17:16 +00:00
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int ILLEGAL_COLUMN;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-01-26 14:51:30 +00:00
|
|
|
template <bool keep_names>
|
2020-08-16 18:17:16 +00:00
|
|
|
struct Impl
|
|
|
|
{
|
2021-01-26 14:51:30 +00:00
|
|
|
static constexpr auto name = keep_names ? "normalizeQueryKeepNames" : "normalizeQuery";
|
2020-08-16 18:17:16 +00:00
|
|
|
static void vector(const ColumnString::Chars & data,
|
|
|
|
const ColumnString::Offsets & offsets,
|
|
|
|
ColumnString::Chars & res_data,
|
|
|
|
ColumnString::Offsets & res_offsets)
|
|
|
|
{
|
|
|
|
size_t size = offsets.size();
|
|
|
|
res_offsets.resize(size);
|
|
|
|
res_data.reserve(data.size());
|
|
|
|
|
|
|
|
ColumnString::Offset prev_src_offset = 0;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
ColumnString::Offset curr_src_offset = offsets[i];
|
2021-01-26 14:51:30 +00:00
|
|
|
normalizeQueryToPODArray<keep_names>(
|
2020-12-02 12:08:03 +00:00
|
|
|
reinterpret_cast<const char *>(&data[prev_src_offset]),
|
|
|
|
reinterpret_cast<const char *>(&data[curr_src_offset - 1]),
|
|
|
|
res_data);
|
2020-08-16 18:17:16 +00:00
|
|
|
prev_src_offset = offsets[i];
|
|
|
|
res_offsets[i] = res_data.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]] static void vectorFixed(const ColumnString::Chars &, size_t, ColumnString::Chars &)
|
|
|
|
{
|
|
|
|
throw Exception("Cannot apply function normalizeQuery to fixed string.", ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionNormalizeQuery(FunctionFactory & factory)
|
|
|
|
{
|
2021-01-26 14:51:30 +00:00
|
|
|
factory.registerFunction<FunctionStringToString<Impl<true>, Impl<true>>>();
|
|
|
|
factory.registerFunction<FunctionStringToString<Impl<false>, Impl<false>>>();
|
2020-08-16 18:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|