2017-04-01 09:19:00 +00:00
|
|
|
#include <Functions/FunctionsStringSearch.h>
|
2017-03-10 17:52:36 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnFixedString.h>
|
2019-01-14 15:54:47 +00:00
|
|
|
#include <Common/config.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeFixedString.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/Regexps.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2017-03-14 13:47:39 +00:00
|
|
|
#include <re2/re2.h>
|
|
|
|
#include <re2/stringpiece.h>
|
2019-01-14 15:54:47 +00:00
|
|
|
#include <Poco/UTF8String.h>
|
|
|
|
#include <Common/Volnitsky.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
2017-03-12 10:13:45 +00:00
|
|
|
|
2017-03-10 17:52:36 +00:00
|
|
|
#if USE_RE2_ST
|
2019-01-14 15:54:47 +00:00
|
|
|
# include <re2_st/re2.h> // Y_IGNORE
|
2017-03-11 00:27:59 +00:00
|
|
|
#else
|
2019-01-14 15:54:47 +00:00
|
|
|
# define re2_st re2
|
2017-03-10 17:52:36 +00:00
|
|
|
#endif
|
|
|
|
|
2016-06-07 08:23:15 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2017-04-08 01:32:05 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
2018-11-22 21:19:58 +00:00
|
|
|
extern const int ILLEGAL_COLUMN;
|
2017-04-08 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-10 17:52:36 +00:00
|
|
|
/** Implementation details for functions of 'position' family depending on ASCII/UTF8 and case sensitiveness.
|
|
|
|
*/
|
|
|
|
struct PositionCaseSensitiveASCII
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// For searching single substring inside big-enough contiguous chunk of data. Coluld have slightly expensive initialization.
|
2019-01-14 15:54:47 +00:00
|
|
|
using SearcherInBigHaystack = Volnitsky;
|
|
|
|
|
|
|
|
/// For search many substrings in one string
|
|
|
|
using MultiSearcherInBigHaystack = MultiVolnitsky;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// For searching single substring, that is different each time. This object is created for each row of data. It must have cheap initialization.
|
|
|
|
using SearcherInSmallHaystack = LibCASCIICaseSensitiveStringSearcher;
|
|
|
|
|
|
|
|
static SearcherInBigHaystack createSearcherInBigHaystack(const char * needle_data, size_t needle_size, size_t haystack_size_hint)
|
|
|
|
{
|
|
|
|
return SearcherInBigHaystack(needle_data, needle_size, haystack_size_hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SearcherInSmallHaystack createSearcherInSmallHaystack(const char * needle_data, size_t needle_size)
|
|
|
|
{
|
|
|
|
return SearcherInSmallHaystack(needle_data, needle_size);
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:41:08 +00:00
|
|
|
static MultiSearcherInBigHaystack createMultiSearcherInBigHaystack(const std::vector<StringRef> & needles)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
return MultiSearcherInBigHaystack(needles);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
/// Number of code points between 'begin' and 'end' (this has different behaviour for ASCII and UTF-8).
|
|
|
|
static size_t countChars(const char * begin, const char * end) { return end - begin; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Convert string to lowercase. Only for case-insensitive search.
|
|
|
|
/// Implementation is permitted to be inefficient because it is called for single string.
|
2019-01-14 15:54:47 +00:00
|
|
|
static void toLowerIfNeed(std::string &) {}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PositionCaseInsensitiveASCII
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// `Volnitsky` is not used here, because one person has measured that this is better. It will be good if you question it.
|
|
|
|
using SearcherInBigHaystack = ASCIICaseInsensitiveStringSearcher;
|
2019-01-14 15:54:47 +00:00
|
|
|
using MultiSearcherInBigHaystack = MultiVolnitskyCaseInsensitive;
|
2017-04-01 07:20:54 +00:00
|
|
|
using SearcherInSmallHaystack = LibCASCIICaseInsensitiveStringSearcher;
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
static SearcherInBigHaystack createSearcherInBigHaystack(const char * needle_data, size_t needle_size, size_t /*haystack_size_hint*/)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
return SearcherInBigHaystack(needle_data, needle_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SearcherInSmallHaystack createSearcherInSmallHaystack(const char * needle_data, size_t needle_size)
|
|
|
|
{
|
|
|
|
return SearcherInSmallHaystack(needle_data, needle_size);
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:41:08 +00:00
|
|
|
static MultiSearcherInBigHaystack createMultiSearcherInBigHaystack(const std::vector<StringRef> & needles)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
return MultiSearcherInBigHaystack(needles);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static size_t countChars(const char * begin, const char * end) { return end - begin; }
|
|
|
|
|
|
|
|
static void toLowerIfNeed(std::string & s) { std::transform(std::begin(s), std::end(s), std::begin(s), tolower); }
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PositionCaseSensitiveUTF8
|
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
using SearcherInBigHaystack = VolnitskyUTF8;
|
|
|
|
using MultiSearcherInBigHaystack = MultiVolnitskyUTF8;
|
2017-04-01 07:20:54 +00:00
|
|
|
using SearcherInSmallHaystack = LibCASCIICaseSensitiveStringSearcher;
|
|
|
|
|
|
|
|
static SearcherInBigHaystack createSearcherInBigHaystack(const char * needle_data, size_t needle_size, size_t haystack_size_hint)
|
|
|
|
{
|
|
|
|
return SearcherInBigHaystack(needle_data, needle_size, haystack_size_hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SearcherInSmallHaystack createSearcherInSmallHaystack(const char * needle_data, size_t needle_size)
|
|
|
|
{
|
|
|
|
return SearcherInSmallHaystack(needle_data, needle_size);
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:41:08 +00:00
|
|
|
static MultiSearcherInBigHaystack createMultiSearcherInBigHaystack(const std::vector<StringRef> & needles)
|
2019-01-14 15:54:47 +00:00
|
|
|
{
|
|
|
|
return MultiSearcherInBigHaystack(needles);
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static size_t countChars(const char * begin, const char * end)
|
|
|
|
{
|
|
|
|
size_t res = 0;
|
|
|
|
for (auto it = begin; it != end; ++it)
|
|
|
|
if (!UTF8::isContinuationOctet(static_cast<UInt8>(*it)))
|
|
|
|
++res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static void toLowerIfNeed(std::string &) {}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PositionCaseInsensitiveUTF8
|
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
using SearcherInBigHaystack = VolnitskyCaseInsensitiveUTF8;
|
|
|
|
using MultiSearcherInBigHaystack = MultiVolnitskyCaseInsensitiveUTF8;
|
2017-04-01 07:20:54 +00:00
|
|
|
using SearcherInSmallHaystack = UTF8CaseInsensitiveStringSearcher; /// TODO Very suboptimal.
|
|
|
|
|
|
|
|
static SearcherInBigHaystack createSearcherInBigHaystack(const char * needle_data, size_t needle_size, size_t haystack_size_hint)
|
|
|
|
{
|
|
|
|
return SearcherInBigHaystack(needle_data, needle_size, haystack_size_hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SearcherInSmallHaystack createSearcherInSmallHaystack(const char * needle_data, size_t needle_size)
|
|
|
|
{
|
|
|
|
return SearcherInSmallHaystack(needle_data, needle_size);
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:41:08 +00:00
|
|
|
static MultiSearcherInBigHaystack createMultiSearcherInBigHaystack(const std::vector<StringRef> & needles)
|
2019-01-14 15:54:47 +00:00
|
|
|
{
|
|
|
|
return MultiSearcherInBigHaystack(needles);
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static size_t countChars(const char * begin, const char * end)
|
|
|
|
{
|
|
|
|
size_t res = 0;
|
|
|
|
for (auto it = begin; it != end; ++it)
|
|
|
|
if (!UTF8::isContinuationOctet(static_cast<UInt8>(*it)))
|
|
|
|
++res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static void toLowerIfNeed(std::string & s) { Poco::UTF8::toLowerInPlace(s); }
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Impl>
|
|
|
|
struct PositionImpl
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using ResultType = UInt64;
|
|
|
|
|
|
|
|
/// Find one substring in many strings.
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector_constant(
|
|
|
|
const ColumnString::Chars & data, const ColumnString::Offsets & offsets, const std::string & needle, PaddedPODArray<UInt64> & res)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-09-02 03:00:04 +00:00
|
|
|
const UInt8 * begin = data.data();
|
2017-04-01 07:20:54 +00:00
|
|
|
const UInt8 * pos = begin;
|
|
|
|
const UInt8 * end = pos + data.size();
|
|
|
|
|
|
|
|
/// Current index in the array of strings.
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
typename Impl::SearcherInBigHaystack searcher = Impl::createSearcherInBigHaystack(needle.data(), needle.size(), end - pos);
|
|
|
|
|
|
|
|
/// We will search for the next occurrence in all strings at once.
|
|
|
|
while (pos < end && end != (pos = searcher.search(pos, end - pos)))
|
|
|
|
{
|
|
|
|
/// Determine which index it refers to.
|
|
|
|
while (begin + offsets[i] <= pos)
|
|
|
|
{
|
|
|
|
res[i] = 0;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// We check that the entry does not pass through the boundaries of strings.
|
|
|
|
if (pos + needle.size() < begin + offsets[i])
|
|
|
|
{
|
|
|
|
size_t prev_offset = i != 0 ? offsets[i - 1] : 0;
|
|
|
|
res[i] = 1 + Impl::countChars(reinterpret_cast<const char *>(begin + prev_offset), reinterpret_cast<const char *>(pos));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res[i] = 0;
|
|
|
|
|
|
|
|
pos = begin + offsets[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2018-09-02 03:52:04 +00:00
|
|
|
if (i < res.size())
|
|
|
|
memset(&res[i], 0, (res.size() - i) * sizeof(res[0]));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Search for substring in string.
|
|
|
|
static void constant_constant(std::string data, std::string needle, UInt64 & res)
|
|
|
|
{
|
|
|
|
Impl::toLowerIfNeed(data);
|
|
|
|
Impl::toLowerIfNeed(needle);
|
|
|
|
|
|
|
|
res = data.find(needle);
|
|
|
|
if (res == std::string::npos)
|
|
|
|
res = 0;
|
|
|
|
else
|
|
|
|
res = 1 + Impl::countChars(data.data(), data.data() + res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Search each time for a different single substring inside each time different string.
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector_vector(
|
|
|
|
const ColumnString::Chars & haystack_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
const ColumnString::Offsets & haystack_offsets,
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & needle_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
const ColumnString::Offsets & needle_offsets,
|
2017-04-01 07:20:54 +00:00
|
|
|
PaddedPODArray<UInt64> & res)
|
|
|
|
{
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset prev_haystack_offset = 0;
|
|
|
|
ColumnString::Offset prev_needle_offset = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
size_t size = haystack_offsets.size();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
size_t needle_size = needle_offsets[i] - prev_needle_offset - 1;
|
|
|
|
size_t haystack_size = haystack_offsets[i] - prev_haystack_offset - 1;
|
|
|
|
|
|
|
|
if (0 == needle_size)
|
|
|
|
{
|
|
|
|
/// An empty string is always at the very beginning of `haystack`.
|
|
|
|
res[i] = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/// It is assumed that the StringSearcher is not very difficult to initialize.
|
2019-01-14 15:54:47 +00:00
|
|
|
typename Impl::SearcherInSmallHaystack searcher = Impl::createSearcherInSmallHaystack(
|
|
|
|
reinterpret_cast<const char *>(&needle_data[prev_needle_offset]),
|
|
|
|
needle_offsets[i] - prev_needle_offset - 1); /// zero byte at the end
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// searcher returns a pointer to the found substring or to the end of `haystack`.
|
|
|
|
size_t pos = searcher.search(&haystack_data[prev_haystack_offset], &haystack_data[haystack_offsets[i] - 1])
|
|
|
|
- &haystack_data[prev_haystack_offset];
|
|
|
|
|
|
|
|
if (pos != haystack_size)
|
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
res[i] = 1
|
|
|
|
+ Impl::countChars(
|
|
|
|
reinterpret_cast<const char *>(&haystack_data[prev_haystack_offset]),
|
|
|
|
reinterpret_cast<const char *>(&haystack_data[prev_haystack_offset + pos]));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
res[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_haystack_offset = haystack_offsets[i];
|
|
|
|
prev_needle_offset = needle_offsets[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:57:11 +00:00
|
|
|
/// Find many substrings in single string.
|
2019-01-14 15:54:47 +00:00
|
|
|
static void constant_vector(
|
|
|
|
const String & haystack,
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & needle_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
const ColumnString::Offsets & needle_offsets,
|
2017-04-01 07:20:54 +00:00
|
|
|
PaddedPODArray<UInt64> & res)
|
|
|
|
{
|
|
|
|
// NOTE You could use haystack indexing. But this is a rare case.
|
|
|
|
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset prev_needle_offset = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
size_t size = needle_offsets.size();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
size_t needle_size = needle_offsets[i] - prev_needle_offset - 1;
|
|
|
|
|
|
|
|
if (0 == needle_size)
|
|
|
|
{
|
|
|
|
res[i] = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
typename Impl::SearcherInSmallHaystack searcher = Impl::createSearcherInSmallHaystack(
|
|
|
|
reinterpret_cast<const char *>(&needle_data[prev_needle_offset]), needle_offsets[i] - prev_needle_offset - 1);
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
size_t pos = searcher.search(
|
|
|
|
reinterpret_cast<const UInt8 *>(haystack.data()),
|
2017-04-01 07:20:54 +00:00
|
|
|
reinterpret_cast<const UInt8 *>(haystack.data()) + haystack.size())
|
|
|
|
- reinterpret_cast<const UInt8 *>(haystack.data());
|
|
|
|
|
|
|
|
if (pos != haystack.size())
|
|
|
|
{
|
|
|
|
res[i] = 1 + Impl::countChars(haystack.data(), haystack.data() + pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_needle_offset = needle_offsets[i];
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
template <typename Impl>
|
|
|
|
struct MultiPositionImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt64;
|
|
|
|
|
2019-01-16 13:57:11 +00:00
|
|
|
static void vector_constant(
|
2019-01-14 15:54:47 +00:00
|
|
|
const ColumnString::Chars & haystack_data,
|
|
|
|
const ColumnString::Offsets & haystack_offsets,
|
2019-01-16 17:41:08 +00:00
|
|
|
const std::vector<StringRef> & needles,
|
2019-01-14 15:54:47 +00:00
|
|
|
PaddedPODArray<UInt64> & res)
|
|
|
|
{
|
2019-01-16 17:41:08 +00:00
|
|
|
auto resCallback = [](const UInt8 * start, const UInt8 * end) -> UInt64
|
2019-01-14 15:54:47 +00:00
|
|
|
{
|
2019-01-16 17:41:08 +00:00
|
|
|
return 1 + Impl::countChars(reinterpret_cast<const char *>(start), reinterpret_cast<const char *>(end));
|
|
|
|
};
|
|
|
|
|
|
|
|
Impl::createMultiSearcherInBigHaystack(needles).searchAll(haystack_data, haystack_offsets, resCallback, res);
|
2019-01-14 15:54:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Impl>
|
|
|
|
struct MultiSearchImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt64;
|
|
|
|
|
2019-01-16 13:57:11 +00:00
|
|
|
static void vector_constant(
|
2019-01-14 15:54:47 +00:00
|
|
|
const ColumnString::Chars & haystack_data,
|
|
|
|
const ColumnString::Offsets & haystack_offsets,
|
2019-01-16 17:41:08 +00:00
|
|
|
const std::vector<StringRef> & needles,
|
2019-01-14 15:54:47 +00:00
|
|
|
PaddedPODArray<UInt64> & res)
|
|
|
|
{
|
2019-01-16 17:41:08 +00:00
|
|
|
Impl::createMultiSearcherInBigHaystack(needles).search(haystack_data, haystack_offsets, res);
|
2019-01-14 15:54:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Impl>
|
|
|
|
struct FirstMatchImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt64;
|
|
|
|
|
2019-01-16 13:57:11 +00:00
|
|
|
static void vector_constant(
|
2019-01-14 15:54:47 +00:00
|
|
|
const ColumnString::Chars & haystack_data,
|
|
|
|
const ColumnString::Offsets & haystack_offsets,
|
2019-01-16 17:41:08 +00:00
|
|
|
const std::vector<StringRef> & needles,
|
2019-01-14 15:54:47 +00:00
|
|
|
PaddedPODArray<UInt64> & res)
|
|
|
|
{
|
2019-01-16 17:41:08 +00:00
|
|
|
Impl::createMultiSearcherInBigHaystack(needles).searchIndex(haystack_data, haystack_offsets, res);
|
2019-01-14 15:54:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-10 17:52:36 +00:00
|
|
|
|
2017-03-25 20:12:56 +00:00
|
|
|
/// Is the LIKE expression reduced to finding a substring in a string?
|
2017-03-10 17:52:36 +00:00
|
|
|
inline bool likePatternIsStrstr(const String & pattern, String & res)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
res = "";
|
|
|
|
|
|
|
|
if (pattern.size() < 2 || pattern.front() != '%' || pattern.back() != '%')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
res.reserve(pattern.size() * 2);
|
|
|
|
|
|
|
|
const char * pos = pattern.data();
|
|
|
|
const char * end = pos + pattern.size();
|
|
|
|
|
|
|
|
++pos;
|
|
|
|
--end;
|
|
|
|
|
|
|
|
while (pos < end)
|
|
|
|
{
|
|
|
|
switch (*pos)
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
case '_':
|
|
|
|
return false;
|
|
|
|
case '\\':
|
|
|
|
++pos;
|
|
|
|
if (pos == end)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
res += *pos;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res += *pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-03-10 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 'like' - if true, treat pattern as SQL LIKE; if false - treat pattern as re2 regexp.
|
|
|
|
* NOTE: We want to run regexp search for whole block by one call (as implemented in function 'position')
|
|
|
|
* but for that, regexp engine must support \0 bytes and their interpretation as string boundaries.
|
|
|
|
*/
|
|
|
|
template <bool like, bool revert = false>
|
|
|
|
struct MatchImpl
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using ResultType = UInt8;
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector_constant(
|
|
|
|
const ColumnString::Chars & data, const ColumnString::Offsets & offsets, const std::string & pattern, PaddedPODArray<UInt8> & res)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-09-02 03:43:31 +00:00
|
|
|
if (offsets.empty())
|
|
|
|
return;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String strstr_pattern;
|
|
|
|
/// A simple case where the LIKE expression reduces to finding a substring in a string
|
|
|
|
if (like && likePatternIsStrstr(pattern, strstr_pattern))
|
|
|
|
{
|
2018-09-02 03:00:04 +00:00
|
|
|
const UInt8 * begin = data.data();
|
2017-04-01 07:20:54 +00:00
|
|
|
const UInt8 * pos = begin;
|
|
|
|
const UInt8 * end = pos + data.size();
|
|
|
|
|
|
|
|
/// The current index in the array of strings.
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
/// TODO You need to make that `searcher` is common to all the calls of the function.
|
|
|
|
Volnitsky searcher(strstr_pattern.data(), strstr_pattern.size(), end - pos);
|
|
|
|
|
|
|
|
/// We will search for the next occurrence in all rows at once.
|
|
|
|
while (pos < end && end != (pos = searcher.search(pos, end - pos)))
|
|
|
|
{
|
|
|
|
/// Let's determine which index it refers to.
|
|
|
|
while (begin + offsets[i] <= pos)
|
|
|
|
{
|
|
|
|
res[i] = revert;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// We check that the entry does not pass through the boundaries of strings.
|
|
|
|
if (pos + strstr_pattern.size() < begin + offsets[i])
|
|
|
|
res[i] = !revert;
|
|
|
|
else
|
|
|
|
res[i] = revert;
|
|
|
|
|
|
|
|
pos = begin + offsets[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Tail, in which there can be no substring.
|
2018-09-02 03:52:04 +00:00
|
|
|
if (i < res.size())
|
|
|
|
memset(&res[i], revert, (res.size() - i) * sizeof(res[0]));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t size = offsets.size();
|
|
|
|
|
|
|
|
const auto & regexp = Regexps::get<like, true>(pattern);
|
|
|
|
|
|
|
|
std::string required_substring;
|
|
|
|
bool is_trivial;
|
|
|
|
bool required_substring_is_prefix; /// for `anchored` execution of the regexp.
|
|
|
|
|
|
|
|
regexp->getAnalyzeResult(required_substring, is_trivial, required_substring_is_prefix);
|
|
|
|
|
|
|
|
if (required_substring.empty())
|
|
|
|
{
|
|
|
|
if (!regexp->getRE2()) /// An empty regexp. Always matches.
|
|
|
|
{
|
2018-09-02 03:52:04 +00:00
|
|
|
if (size)
|
|
|
|
memset(res.data(), 1, size * sizeof(res[0]));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t prev_offset = 0;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
res[i] = revert
|
|
|
|
^ regexp->getRE2()->Match(
|
|
|
|
re2_st::StringPiece(reinterpret_cast<const char *>(&data[prev_offset]), offsets[i] - prev_offset - 1),
|
|
|
|
0,
|
|
|
|
offsets[i] - prev_offset - 1,
|
|
|
|
re2_st::RE2::UNANCHORED,
|
|
|
|
nullptr,
|
|
|
|
0);
|
|
|
|
|
|
|
|
prev_offset = offsets[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/// NOTE This almost matches with the case of LikePatternIsStrstr.
|
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
const UInt8 * begin = data.data();
|
2017-04-01 07:20:54 +00:00
|
|
|
const UInt8 * pos = begin;
|
|
|
|
const UInt8 * end = pos + data.size();
|
|
|
|
|
|
|
|
/// The current index in the array of strings.
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
Volnitsky searcher(required_substring.data(), required_substring.size(), end - pos);
|
|
|
|
|
|
|
|
/// We will search for the next occurrence in all rows at once.
|
|
|
|
while (pos < end && end != (pos = searcher.search(pos, end - pos)))
|
|
|
|
{
|
|
|
|
/// Determine which index it refers to.
|
|
|
|
while (begin + offsets[i] <= pos)
|
|
|
|
{
|
|
|
|
res[i] = revert;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// We check that the entry does not pass through the boundaries of strings.
|
|
|
|
if (pos + strstr_pattern.size() < begin + offsets[i])
|
|
|
|
{
|
|
|
|
/// And if it does not, if necessary, we check the regexp.
|
|
|
|
|
|
|
|
if (is_trivial)
|
|
|
|
res[i] = !revert;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char * str_data = reinterpret_cast<const char *>(&data[i != 0 ? offsets[i - 1] : 0]);
|
|
|
|
size_t str_size = (i != 0 ? offsets[i] - offsets[i - 1] : offsets[0]) - 1;
|
|
|
|
|
|
|
|
/** Even in the case of `required_substring_is_prefix` use UNANCHORED check for regexp,
|
2019-01-16 13:57:11 +00:00
|
|
|
* so that it can match when `required_substring` occurs into the string several times,
|
2017-04-01 07:20:54 +00:00
|
|
|
* and at the first occurrence, the regexp is not a match.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (required_substring_is_prefix)
|
|
|
|
res[i] = revert
|
2019-01-14 15:54:47 +00:00
|
|
|
^ regexp->getRE2()->Match(
|
|
|
|
re2_st::StringPiece(str_data, str_size),
|
2017-04-01 07:20:54 +00:00
|
|
|
reinterpret_cast<const char *>(pos) - str_data,
|
|
|
|
str_size,
|
|
|
|
re2_st::RE2::UNANCHORED,
|
|
|
|
nullptr,
|
|
|
|
0);
|
|
|
|
else
|
|
|
|
res[i] = revert
|
|
|
|
^ regexp->getRE2()->Match(
|
|
|
|
re2_st::StringPiece(str_data, str_size), 0, str_size, re2_st::RE2::UNANCHORED, nullptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res[i] = revert;
|
|
|
|
|
|
|
|
pos = begin + offsets[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2018-09-02 03:52:04 +00:00
|
|
|
if (i < res.size())
|
|
|
|
memset(&res[i], revert, (res.size() - i) * sizeof(res[0]));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void constant_constant(const std::string & data, const std::string & pattern, UInt8 & res)
|
|
|
|
{
|
|
|
|
const auto & regexp = Regexps::get<like, true>(pattern);
|
|
|
|
res = revert ^ regexp->match(data);
|
|
|
|
}
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
template <typename... Args>
|
|
|
|
static void vector_vector(Args &&...)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-24 17:36:16 +00:00
|
|
|
throw Exception("Functions 'like' and 'match' don't support non-constant needle argument", ErrorCodes::ILLEGAL_COLUMN);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Search different needles in single haystack.
|
2019-01-14 15:54:47 +00:00
|
|
|
template <typename... Args>
|
|
|
|
static void constant_vector(Args &&...)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-24 17:36:16 +00:00
|
|
|
throw Exception("Functions 'like' and 'match' don't support non-constant needle argument", ErrorCodes::ILLEGAL_COLUMN);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct ExtractImpl
|
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector(
|
|
|
|
const ColumnString::Chars & data,
|
2017-12-15 21:32:25 +00:00
|
|
|
const ColumnString::Offsets & offsets,
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & pattern,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & res_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offsets & res_offsets)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
res_data.reserve(data.size() / 5);
|
|
|
|
res_offsets.resize(offsets.size());
|
|
|
|
|
|
|
|
const auto & regexp = Regexps::get<false, false>(pattern);
|
|
|
|
|
|
|
|
unsigned capture = regexp->getNumberOfSubpatterns() > 0 ? 1 : 0;
|
|
|
|
OptimizedRegularExpression::MatchVec matches;
|
|
|
|
matches.reserve(capture + 1);
|
|
|
|
size_t prev_offset = 0;
|
|
|
|
size_t res_offset = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < offsets.size(); ++i)
|
|
|
|
{
|
|
|
|
size_t cur_offset = offsets[i];
|
|
|
|
|
|
|
|
unsigned count
|
|
|
|
= regexp->match(reinterpret_cast<const char *>(&data[prev_offset]), cur_offset - prev_offset - 1, matches, capture + 1);
|
|
|
|
if (count > capture && matches[capture].offset != std::string::npos)
|
|
|
|
{
|
|
|
|
const auto & match = matches[capture];
|
|
|
|
res_data.resize(res_offset + match.length + 1);
|
|
|
|
memcpySmallAllowReadWriteOverflow15(&res_data[res_offset], &data[prev_offset + match.offset], match.length);
|
|
|
|
res_offset += match.length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res_data.resize(res_offset + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
res_data[res_offset] = 0;
|
|
|
|
++res_offset;
|
|
|
|
res_offsets[i] = res_offset;
|
|
|
|
|
|
|
|
prev_offset = cur_offset;
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Replace all matches of regexp 'needle' to string 'replacement'. 'needle' and 'replacement' are constants.
|
|
|
|
* 'replacement' could contain substitutions, for example: '\2-\3-\1'
|
|
|
|
*/
|
|
|
|
template <bool replace_one = false>
|
|
|
|
struct ReplaceRegexpImpl
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Sequence of instructions, describing how to get resulting string.
|
|
|
|
/// Each element is either:
|
|
|
|
/// - substitution (in that case first element of pair is their number and second element is empty)
|
|
|
|
/// - string that need to be inserted (in that case, first element of pair is that string and second element is -1)
|
|
|
|
using Instructions = std::vector<std::pair<int, std::string>>;
|
|
|
|
|
|
|
|
static const size_t max_captures = 10;
|
|
|
|
|
|
|
|
|
|
|
|
static Instructions createInstructions(const std::string & s, int num_captures)
|
|
|
|
{
|
|
|
|
Instructions instructions;
|
|
|
|
|
|
|
|
String now = "";
|
|
|
|
for (size_t i = 0; i < s.size(); ++i)
|
|
|
|
{
|
|
|
|
if (s[i] == '\\' && i + 1 < s.size())
|
|
|
|
{
|
2017-07-11 18:22:02 +00:00
|
|
|
if (isNumericASCII(s[i + 1])) /// Substitution
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (!now.empty())
|
|
|
|
{
|
|
|
|
instructions.emplace_back(-1, now);
|
|
|
|
now = "";
|
|
|
|
}
|
|
|
|
instructions.emplace_back(s[i + 1] - '0', String());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
now += s[i + 1]; /// Escaping
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
now += s[i]; /// Plain character
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!now.empty())
|
|
|
|
{
|
|
|
|
instructions.emplace_back(-1, now);
|
|
|
|
now = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto & it : instructions)
|
|
|
|
if (it.first >= num_captures)
|
2019-01-14 15:54:47 +00:00
|
|
|
throw Exception(
|
|
|
|
"Invalid replace instruction in replacement string. Id: " + toString(it.first) + ", but regexp has only "
|
|
|
|
+ toString(num_captures - 1) + " subpatterns",
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::BAD_ARGUMENTS);
|
|
|
|
|
|
|
|
return instructions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static void processString(
|
|
|
|
const re2_st::StringPiece & input,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & res_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset & res_offset,
|
2017-04-01 07:20:54 +00:00
|
|
|
re2_st::RE2 & searcher,
|
|
|
|
int num_captures,
|
|
|
|
const Instructions & instructions)
|
|
|
|
{
|
|
|
|
re2_st::StringPiece matches[max_captures];
|
|
|
|
|
2018-01-19 01:18:47 +00:00
|
|
|
size_t start_pos = 0;
|
2018-01-19 22:37:50 +00:00
|
|
|
while (start_pos < static_cast<size_t>(input.length()))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
/// If no more replacements possible for current string
|
|
|
|
bool can_finish_current_string = false;
|
|
|
|
|
|
|
|
if (searcher.Match(input, start_pos, input.length(), re2_st::RE2::Anchor::UNANCHORED, matches, num_captures))
|
|
|
|
{
|
|
|
|
const auto & match = matches[0];
|
|
|
|
size_t bytes_to_copy = (match.data() - input.data()) - start_pos;
|
|
|
|
|
|
|
|
/// Copy prefix before matched regexp without modification
|
|
|
|
res_data.resize(res_data.size() + bytes_to_copy);
|
|
|
|
memcpySmallAllowReadWriteOverflow15(&res_data[res_offset], input.data() + start_pos, bytes_to_copy);
|
|
|
|
res_offset += bytes_to_copy;
|
|
|
|
start_pos += bytes_to_copy + match.length();
|
|
|
|
|
|
|
|
/// Do substitution instructions
|
|
|
|
for (const auto & it : instructions)
|
|
|
|
{
|
|
|
|
if (it.first >= 0)
|
|
|
|
{
|
|
|
|
res_data.resize(res_data.size() + matches[it.first].length());
|
|
|
|
memcpy(&res_data[res_offset], matches[it.first].data(), matches[it.first].length());
|
|
|
|
res_offset += matches[it.first].length();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res_data.resize(res_data.size() + it.second.size());
|
|
|
|
memcpy(&res_data[res_offset], it.second.data(), it.second.size());
|
|
|
|
res_offset += it.second.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (replace_one || match.length() == 0) /// Stop after match of zero length, to avoid infinite loop.
|
|
|
|
can_finish_current_string = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
can_finish_current_string = true;
|
|
|
|
|
|
|
|
/// If ready, append suffix after match to end of string.
|
|
|
|
if (can_finish_current_string)
|
|
|
|
{
|
|
|
|
res_data.resize(res_data.size() + input.length() - start_pos);
|
|
|
|
memcpySmallAllowReadWriteOverflow15(&res_data[res_offset], input.data() + start_pos, input.length() - start_pos);
|
|
|
|
res_offset += input.length() - start_pos;
|
|
|
|
start_pos = input.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res_data.resize(res_data.size() + 1);
|
|
|
|
res_data[res_offset] = 0;
|
|
|
|
++res_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector(
|
|
|
|
const ColumnString::Chars & data,
|
2017-12-15 21:32:25 +00:00
|
|
|
const ColumnString::Offsets & offsets,
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & needle,
|
|
|
|
const std::string & replacement,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & res_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offsets & res_offsets)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset res_offset = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
res_data.reserve(data.size());
|
|
|
|
size_t size = offsets.size();
|
|
|
|
res_offsets.resize(size);
|
|
|
|
|
|
|
|
re2_st::RE2 searcher(needle);
|
|
|
|
int num_captures = std::min(searcher.NumberOfCapturingGroups() + 1, static_cast<int>(max_captures));
|
|
|
|
|
|
|
|
Instructions instructions = createInstructions(replacement, num_captures);
|
|
|
|
|
|
|
|
/// Cannot perform search for whole block. Will process each string separately.
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
int from = i > 0 ? offsets[i - 1] : 0;
|
2018-09-02 03:00:04 +00:00
|
|
|
re2_st::StringPiece input(reinterpret_cast<const char *>(data.data() + from), offsets[i] - from - 1);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
processString(input, res_data, res_offset, searcher, num_captures, instructions);
|
|
|
|
res_offsets[i] = res_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector_fixed(
|
|
|
|
const ColumnString::Chars & data,
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t n,
|
|
|
|
const std::string & needle,
|
|
|
|
const std::string & replacement,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & res_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offsets & res_offsets)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset res_offset = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t size = data.size() / n;
|
|
|
|
res_data.reserve(data.size());
|
|
|
|
res_offsets.resize(size);
|
|
|
|
|
|
|
|
re2_st::RE2 searcher(needle);
|
|
|
|
int num_captures = std::min(searcher.NumberOfCapturingGroups() + 1, static_cast<int>(max_captures));
|
|
|
|
|
|
|
|
Instructions instructions = createInstructions(replacement, num_captures);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
int from = i * n;
|
2018-09-02 03:00:04 +00:00
|
|
|
re2_st::StringPiece input(reinterpret_cast<const char *>(data.data() + from), n);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
processString(input, res_data, res_offset, searcher, num_captures, instructions);
|
|
|
|
res_offsets[i] = res_offset;
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Replace one or all occurencies of substring 'needle' to 'replacement'. 'needle' and 'replacement' are constants.
|
|
|
|
*/
|
|
|
|
template <bool replace_one = false>
|
|
|
|
struct ReplaceStringImpl
|
|
|
|
{
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector(
|
|
|
|
const ColumnString::Chars & data,
|
2017-12-15 21:32:25 +00:00
|
|
|
const ColumnString::Offsets & offsets,
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & needle,
|
|
|
|
const std::string & replacement,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & res_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offsets & res_offsets)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-09-02 03:00:04 +00:00
|
|
|
const UInt8 * begin = data.data();
|
2017-04-01 07:20:54 +00:00
|
|
|
const UInt8 * pos = begin;
|
|
|
|
const UInt8 * end = pos + data.size();
|
|
|
|
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset res_offset = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
res_data.reserve(data.size());
|
|
|
|
size_t size = offsets.size();
|
|
|
|
res_offsets.resize(size);
|
|
|
|
|
|
|
|
/// The current index in the array of strings.
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
Volnitsky searcher(needle.data(), needle.size(), end - pos);
|
|
|
|
|
|
|
|
/// We will search for the next occurrence in all rows at once.
|
|
|
|
while (pos < end)
|
|
|
|
{
|
|
|
|
const UInt8 * match = searcher.search(pos, end - pos);
|
|
|
|
|
|
|
|
/// Copy the data without changing
|
|
|
|
res_data.resize(res_data.size() + (match - pos));
|
|
|
|
memcpy(&res_data[res_offset], pos, match - pos);
|
|
|
|
|
|
|
|
/// Determine which index it belongs to.
|
|
|
|
while (i < offsets.size() && begin + offsets[i] <= match)
|
|
|
|
{
|
|
|
|
res_offsets[i] = res_offset + ((begin + offsets[i]) - pos);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
res_offset += (match - pos);
|
|
|
|
|
|
|
|
/// If you have reached the end, it's time to stop
|
|
|
|
if (i == offsets.size())
|
|
|
|
break;
|
|
|
|
|
2019-01-16 13:57:11 +00:00
|
|
|
/// Is it true that this string no longer needs to perform transformations.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool can_finish_current_string = false;
|
|
|
|
|
|
|
|
/// We check that the entry does not go through the boundaries of strings.
|
|
|
|
if (match + needle.size() < begin + offsets[i])
|
|
|
|
{
|
|
|
|
res_data.resize(res_data.size() + replacement.size());
|
|
|
|
memcpy(&res_data[res_offset], replacement.data(), replacement.size());
|
|
|
|
res_offset += replacement.size();
|
|
|
|
pos = match + needle.size();
|
|
|
|
if (replace_one)
|
|
|
|
can_finish_current_string = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = match;
|
|
|
|
can_finish_current_string = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (can_finish_current_string)
|
|
|
|
{
|
|
|
|
res_data.resize(res_data.size() + (begin + offsets[i] - pos));
|
|
|
|
memcpy(&res_data[res_offset], pos, (begin + offsets[i] - pos));
|
|
|
|
res_offset += (begin + offsets[i] - pos);
|
|
|
|
res_offsets[i] = res_offset;
|
|
|
|
pos = begin + offsets[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 13:25:50 +00:00
|
|
|
/// Note: this function converts fixed-length strings to variable-length strings
|
|
|
|
/// and each variable-length string should ends with zero byte.
|
2019-01-14 15:54:47 +00:00
|
|
|
static void vector_fixed(
|
|
|
|
const ColumnString::Chars & data,
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t n,
|
|
|
|
const std::string & needle,
|
|
|
|
const std::string & replacement,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & res_data,
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offsets & res_offsets)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-09-02 03:00:04 +00:00
|
|
|
const UInt8 * begin = data.data();
|
2017-04-01 07:20:54 +00:00
|
|
|
const UInt8 * pos = begin;
|
|
|
|
const UInt8 * end = pos + data.size();
|
|
|
|
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset res_offset = 0;
|
2017-04-18 13:25:50 +00:00
|
|
|
size_t count = data.size() / n;
|
2017-04-01 07:20:54 +00:00
|
|
|
res_data.reserve(data.size());
|
2017-04-18 13:25:50 +00:00
|
|
|
res_offsets.resize(count);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// The current index in the string array.
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
Volnitsky searcher(needle.data(), needle.size(), end - pos);
|
|
|
|
|
|
|
|
/// We will search for the next occurrence in all rows at once.
|
|
|
|
while (pos < end)
|
|
|
|
{
|
|
|
|
const UInt8 * match = searcher.search(pos, end - pos);
|
|
|
|
|
2017-04-18 13:25:50 +00:00
|
|
|
#define COPY_REST_OF_CURRENT_STRING() \
|
2019-01-14 15:54:47 +00:00
|
|
|
do \
|
|
|
|
{ \
|
2017-04-18 13:25:50 +00:00
|
|
|
const size_t len = begin + n * (i + 1) - pos; \
|
|
|
|
res_data.resize(res_data.size() + len + 1); \
|
|
|
|
memcpy(&res_data[res_offset], pos, len); \
|
|
|
|
res_offset += len; \
|
|
|
|
res_data[res_offset++] = 0; \
|
|
|
|
res_offsets[i] = res_offset; \
|
|
|
|
pos = begin + n * (i + 1); \
|
|
|
|
++i; \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
/// Copy skipped strings without any changes but
|
|
|
|
/// add zero byte to the end of each string.
|
|
|
|
while (i < count && begin + n * (i + 1) <= match)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-04-18 13:25:50 +00:00
|
|
|
COPY_REST_OF_CURRENT_STRING();
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If you have reached the end, it's time to stop
|
2017-04-18 13:25:50 +00:00
|
|
|
if (i == count)
|
2017-04-01 07:20:54 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-18 13:25:50 +00:00
|
|
|
/// Copy unchanged part of current string.
|
|
|
|
res_data.resize(res_data.size() + (match - pos));
|
|
|
|
memcpy(&res_data[res_offset], pos, match - pos);
|
|
|
|
res_offset += (match - pos);
|
|
|
|
|
2019-01-16 13:57:11 +00:00
|
|
|
/// Is it true that this string no longer needs to perform conversions.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool can_finish_current_string = false;
|
|
|
|
|
|
|
|
/// We check that the entry does not pass through the boundaries of strings.
|
2017-04-18 13:25:50 +00:00
|
|
|
if (match + needle.size() <= begin + n * (i + 1))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
res_data.resize(res_data.size() + replacement.size());
|
|
|
|
memcpy(&res_data[res_offset], replacement.data(), replacement.size());
|
|
|
|
res_offset += replacement.size();
|
|
|
|
pos = match + needle.size();
|
2017-04-18 13:25:50 +00:00
|
|
|
if (replace_one || pos == begin + n * (i + 1))
|
2017-04-01 07:20:54 +00:00
|
|
|
can_finish_current_string = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = match;
|
|
|
|
can_finish_current_string = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (can_finish_current_string)
|
|
|
|
{
|
2017-04-18 13:25:50 +00:00
|
|
|
COPY_REST_OF_CURRENT_STRING();
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-04-18 13:25:50 +00:00
|
|
|
#undef COPY_REST_OF_CURRENT_STRING
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void constant(const std::string & data, const std::string & needle, const std::string & replacement, std::string & res_data)
|
|
|
|
{
|
|
|
|
res_data = "";
|
|
|
|
int replace_cnt = 0;
|
|
|
|
for (size_t i = 0; i < data.size(); ++i)
|
|
|
|
{
|
|
|
|
bool match = true;
|
|
|
|
if (i + needle.size() > data.size() || (replace_one && replace_cnt > 0))
|
|
|
|
match = false;
|
|
|
|
for (size_t j = 0; match && j < needle.size(); ++j)
|
|
|
|
if (data[i + j] != needle[j])
|
|
|
|
match = false;
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
++replace_cnt;
|
|
|
|
res_data += replacement;
|
|
|
|
i = i + needle.size() - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res_data += data[i];
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Impl, typename Name>
|
|
|
|
class FunctionStringReplace : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = Name::name;
|
2019-01-14 15:54:47 +00:00
|
|
|
static FunctionPtr create(const Context &) { return std::make_shared<FunctionStringReplace>(); }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
String getName() const override { return name; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 3; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-23 08:40:43 +00:00
|
|
|
bool useDefaultImplementationForConstants() const override { return true; }
|
|
|
|
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1, 2}; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
|
|
|
{
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!isStringOrFixedString(arguments[0]))
|
2019-01-14 15:54:47 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[0]->getName() + " of first argument of function " + getName(),
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!isStringOrFixedString(arguments[1]))
|
2019-01-14 15:54:47 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[1]->getName() + " of second argument of function " + getName(),
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!isStringOrFixedString(arguments[2]))
|
2019-01-14 15:54:47 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[2]->getName() + " of third argument of function " + getName(),
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return std::make_shared<DataTypeString>();
|
|
|
|
}
|
|
|
|
|
2018-04-24 07:16:39 +00:00
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnPtr column_src = block.getByPosition(arguments[0]).column;
|
|
|
|
const ColumnPtr column_needle = block.getByPosition(arguments[1]).column;
|
|
|
|
const ColumnPtr column_replacement = block.getByPosition(arguments[2]).column;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-09 10:14:45 +00:00
|
|
|
if (!column_needle->isColumnConst() || !column_replacement->isColumnConst())
|
2018-11-22 21:19:58 +00:00
|
|
|
throw Exception("2nd and 3rd arguments of function " + getName() + " must be constants.", ErrorCodes::ILLEGAL_COLUMN);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const IColumn * c1 = block.getByPosition(arguments[1]).column.get();
|
|
|
|
const IColumn * c2 = block.getByPosition(arguments[2]).column.get();
|
|
|
|
const ColumnConst * c1_const = typeid_cast<const ColumnConst *>(c1);
|
|
|
|
const ColumnConst * c2_const = typeid_cast<const ColumnConst *>(c2);
|
|
|
|
String needle = c1_const->getValue<String>();
|
|
|
|
String replacement = c2_const->getValue<String>();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (needle.size() == 0)
|
|
|
|
throw Exception("Length of the second argument of function replace must be greater than 0.", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
if (const ColumnString * col = checkAndGetColumn<ColumnString>(column_src.get()))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-14 03:56:56 +00:00
|
|
|
auto col_res = ColumnString::create();
|
2017-04-01 07:20:54 +00:00
|
|
|
Impl::vector(col->getChars(), col->getOffsets(), needle, replacement, col_res->getChars(), col_res->getOffsets());
|
2017-12-14 03:56:56 +00:00
|
|
|
block.getByPosition(result).column = std::move(col_res);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2019-01-04 12:10:00 +00:00
|
|
|
else if (const ColumnFixedString * col_fixed = checkAndGetColumn<ColumnFixedString>(column_src.get()))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-14 03:56:56 +00:00
|
|
|
auto col_res = ColumnString::create();
|
2019-01-04 12:10:00 +00:00
|
|
|
Impl::vector_fixed(col_fixed->getChars(), col_fixed->getN(), needle, replacement, col_res->getChars(), col_res->getOffsets());
|
2017-12-14 03:56:56 +00:00
|
|
|
block.getByPosition(result).column = std::move(col_res);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
throw Exception(
|
2017-07-21 06:35:58 +00:00
|
|
|
"Illegal column " + block.getByPosition(arguments[0]).column->getName() + " of first argument of function " + getName(),
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct NamePosition
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "position";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NamePositionUTF8
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "positionUTF8";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NamePositionCaseInsensitive
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "positionCaseInsensitive";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NamePositionCaseInsensitiveUTF8
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "positionCaseInsensitiveUTF8";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
2019-01-14 15:54:47 +00:00
|
|
|
struct NameMultiPosition
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiPosition";
|
|
|
|
};
|
|
|
|
struct NameMultiPositionUTF8
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiPositionUTF8";
|
|
|
|
};
|
|
|
|
struct NameMultiPositionCaseInsensitive
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiPositionCaseInsensitive";
|
|
|
|
};
|
|
|
|
struct NameMultiPositionCaseInsensitiveUTF8
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiPositionCaseInsensitiveUTF8";
|
|
|
|
};
|
|
|
|
struct NameMultiSearch
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiSearch";
|
|
|
|
};
|
|
|
|
struct NameMultiSearchUTF8
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiSearchUTF8";
|
|
|
|
};
|
|
|
|
struct NameMultiSearchCaseInsensitive
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiSearchCaseInsensitive";
|
|
|
|
};
|
|
|
|
struct NameMultiSearchCaseInsensitiveUTF8
|
|
|
|
{
|
|
|
|
static constexpr auto name = "multiSearchCaseInsensitiveUTF8";
|
|
|
|
};
|
|
|
|
struct NameFirstMatch
|
|
|
|
{
|
|
|
|
static constexpr auto name = "firstMatch";
|
|
|
|
};
|
|
|
|
struct NameFirstMatchUTF8
|
|
|
|
{
|
|
|
|
static constexpr auto name = "firstMatchUTF8";
|
|
|
|
};
|
|
|
|
struct NameFirstMatchCaseInsensitive
|
|
|
|
{
|
|
|
|
static constexpr auto name = "firstMatchCaseInsensitive";
|
|
|
|
};
|
|
|
|
struct NameFirstMatchCaseInsensitiveUTF8
|
|
|
|
{
|
|
|
|
static constexpr auto name = "firstMatchCaseInsensitiveUTF8";
|
|
|
|
};
|
2017-03-10 17:52:36 +00:00
|
|
|
struct NameMatch
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "match";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameLike
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "like";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameNotLike
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "notLike";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameExtract
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "extract";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameReplaceOne
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "replaceOne";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameReplaceAll
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "replaceAll";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameReplaceRegexpOne
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "replaceRegexpOne";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
struct NameReplaceRegexpAll
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto name = "replaceRegexpAll";
|
2017-03-10 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using FunctionPosition = FunctionsStringSearch<PositionImpl<PositionCaseSensitiveASCII>, NamePosition>;
|
|
|
|
using FunctionPositionUTF8 = FunctionsStringSearch<PositionImpl<PositionCaseSensitiveUTF8>, NamePositionUTF8>;
|
|
|
|
using FunctionPositionCaseInsensitive = FunctionsStringSearch<PositionImpl<PositionCaseInsensitiveASCII>, NamePositionCaseInsensitive>;
|
|
|
|
using FunctionPositionCaseInsensitiveUTF8
|
2017-04-01 07:20:54 +00:00
|
|
|
= FunctionsStringSearch<PositionImpl<PositionCaseInsensitiveUTF8>, NamePositionCaseInsensitiveUTF8>;
|
2017-03-10 17:52:36 +00:00
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
using FunctionMultiPosition = FunctionsMultiStringPosition<MultiPositionImpl<PositionCaseSensitiveASCII>, NameMultiPosition>;
|
|
|
|
using FunctionMultiPositionUTF8 = FunctionsMultiStringPosition<MultiPositionImpl<PositionCaseSensitiveUTF8>, NameMultiPositionUTF8>;
|
|
|
|
using FunctionMultiPositionCaseInsensitive
|
|
|
|
= FunctionsMultiStringPosition<MultiPositionImpl<PositionCaseInsensitiveASCII>, NameMultiPositionCaseInsensitive>;
|
|
|
|
using FunctionMultiPositionCaseInsensitiveUTF8
|
|
|
|
= FunctionsMultiStringPosition<MultiPositionImpl<PositionCaseInsensitiveUTF8>, NameMultiPositionCaseInsensitiveUTF8>;
|
|
|
|
|
|
|
|
using FunctionMultiSearch = FunctionsMultiStringSearch<MultiSearchImpl<PositionCaseSensitiveASCII>, NameMultiSearch>;
|
|
|
|
using FunctionMultiSearchUTF8 = FunctionsMultiStringSearch<MultiSearchImpl<PositionCaseSensitiveUTF8>, NameMultiSearchUTF8>;
|
|
|
|
using FunctionMultiSearchCaseInsensitive
|
|
|
|
= FunctionsMultiStringSearch<MultiSearchImpl<PositionCaseInsensitiveASCII>, NameMultiSearchCaseInsensitive>;
|
|
|
|
using FunctionMultiSearchCaseInsensitiveUTF8
|
|
|
|
= FunctionsMultiStringSearch<MultiSearchImpl<PositionCaseInsensitiveUTF8>, NameMultiSearchCaseInsensitiveUTF8>;
|
|
|
|
|
|
|
|
using FunctionFirstMatch = FunctionsMultiStringSearch<FirstMatchImpl<PositionCaseSensitiveASCII>, NameFirstMatch>;
|
|
|
|
using FunctionFirstMatchUTF8 = FunctionsMultiStringSearch<FirstMatchImpl<PositionCaseSensitiveUTF8>, NameFirstMatchUTF8>;
|
|
|
|
using FunctionFirstMatchCaseInsensitive
|
|
|
|
= FunctionsMultiStringSearch<FirstMatchImpl<PositionCaseInsensitiveASCII>, NameFirstMatchCaseInsensitive>;
|
|
|
|
using FunctionFirstMatchCaseInsensitiveUTF8
|
|
|
|
= FunctionsMultiStringSearch<FirstMatchImpl<PositionCaseInsensitiveUTF8>, NameFirstMatchCaseInsensitiveUTF8>;
|
|
|
|
|
2017-03-10 17:52:36 +00:00
|
|
|
using FunctionMatch = FunctionsStringSearch<MatchImpl<false>, NameMatch>;
|
|
|
|
using FunctionLike = FunctionsStringSearch<MatchImpl<true>, NameLike>;
|
|
|
|
using FunctionNotLike = FunctionsStringSearch<MatchImpl<true, true>, NameNotLike>;
|
|
|
|
using FunctionExtract = FunctionsStringSearchToString<ExtractImpl, NameExtract>;
|
|
|
|
using FunctionReplaceOne = FunctionStringReplace<ReplaceStringImpl<true>, NameReplaceOne>;
|
|
|
|
using FunctionReplaceAll = FunctionStringReplace<ReplaceStringImpl<false>, NameReplaceAll>;
|
|
|
|
using FunctionReplaceRegexpOne = FunctionStringReplace<ReplaceRegexpImpl<true>, NameReplaceRegexpOne>;
|
|
|
|
using FunctionReplaceRegexpAll = FunctionStringReplace<ReplaceRegexpImpl<false>, NameReplaceRegexpAll>;
|
|
|
|
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
void registerFunctionsStringSearch(FunctionFactory & factory)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionReplaceOne>();
|
|
|
|
factory.registerFunction<FunctionReplaceAll>();
|
|
|
|
factory.registerFunction<FunctionReplaceRegexpOne>();
|
|
|
|
factory.registerFunction<FunctionReplaceRegexpAll>();
|
2019-01-14 15:54:47 +00:00
|
|
|
|
2018-12-19 14:46:18 +00:00
|
|
|
factory.registerFunction<FunctionPosition>(FunctionFactory::CaseInsensitive);
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionPositionUTF8>();
|
|
|
|
factory.registerFunction<FunctionPositionCaseInsensitive>();
|
|
|
|
factory.registerFunction<FunctionPositionCaseInsensitiveUTF8>();
|
2019-01-14 15:54:47 +00:00
|
|
|
|
|
|
|
factory.registerFunction<FunctionMultiPosition>();
|
|
|
|
factory.registerFunction<FunctionMultiPositionUTF8>();
|
|
|
|
factory.registerFunction<FunctionMultiPositionCaseInsensitive>();
|
|
|
|
factory.registerFunction<FunctionMultiPositionCaseInsensitiveUTF8>();
|
|
|
|
|
|
|
|
factory.registerFunction<FunctionMultiSearch>();
|
|
|
|
factory.registerFunction<FunctionMultiSearchUTF8>();
|
|
|
|
factory.registerFunction<FunctionMultiSearchCaseInsensitive>();
|
|
|
|
factory.registerFunction<FunctionMultiSearchCaseInsensitiveUTF8>();
|
|
|
|
|
|
|
|
factory.registerFunction<FunctionFirstMatch>();
|
|
|
|
factory.registerFunction<FunctionFirstMatchUTF8>();
|
|
|
|
factory.registerFunction<FunctionFirstMatchCaseInsensitive>();
|
|
|
|
factory.registerFunction<FunctionFirstMatchCaseInsensitiveUTF8>();
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionMatch>();
|
|
|
|
factory.registerFunction<FunctionLike>();
|
|
|
|
factory.registerFunction<FunctionNotLike>();
|
|
|
|
factory.registerFunction<FunctionExtract>();
|
2019-01-14 15:54:47 +00:00
|
|
|
|
2018-12-06 13:36:23 +00:00
|
|
|
factory.registerAlias("locate", NamePosition::name, FunctionFactory::CaseInsensitive);
|
2018-12-06 13:23:45 +00:00
|
|
|
factory.registerAlias("replace", NameReplaceAll::name, FunctionFactory::CaseInsensitive);
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
}
|