2020-03-29 17:04:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-09-21 16:43:46 +00:00
|
|
|
template <typename Name, typename Impl>
|
2020-03-29 17:04:16 +00:00
|
|
|
struct MultiSearchImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt8;
|
|
|
|
static constexpr bool is_using_hyperscan = false;
|
|
|
|
/// Variable for understanding, if we used offsets for the output, most
|
|
|
|
/// likely to determine whether the function returns ColumnVector of ColumnArray.
|
|
|
|
static constexpr bool is_column_array = false;
|
2021-09-21 16:43:46 +00:00
|
|
|
static constexpr auto name = Name::name;
|
|
|
|
|
2020-03-29 17:04:16 +00:00
|
|
|
static auto getReturnType() { return std::make_shared<DataTypeNumber<ResultType>>(); }
|
|
|
|
|
|
|
|
static void vectorConstant(
|
|
|
|
const ColumnString::Chars & haystack_data,
|
|
|
|
const ColumnString::Offsets & haystack_offsets,
|
|
|
|
const std::vector<StringRef> & needles,
|
|
|
|
PaddedPODArray<UInt8> & res,
|
|
|
|
[[maybe_unused]] PaddedPODArray<UInt64> & offsets)
|
|
|
|
{
|
|
|
|
auto searcher = Impl::createMultiSearcherInBigHaystack(needles);
|
|
|
|
const size_t haystack_string_size = haystack_offsets.size();
|
2021-08-05 08:36:35 +00:00
|
|
|
res.resize(haystack_string_size);
|
2020-03-29 17:04:16 +00:00
|
|
|
size_t iteration = 0;
|
|
|
|
while (searcher.hasMoreToSearch())
|
|
|
|
{
|
|
|
|
size_t prev_offset = 0;
|
|
|
|
for (size_t j = 0; j < haystack_string_size; ++j)
|
|
|
|
{
|
|
|
|
const auto * haystack = &haystack_data[prev_offset];
|
|
|
|
const auto * haystack_end = haystack + haystack_offsets[j] - prev_offset - 1;
|
|
|
|
if (iteration == 0 || !res[j])
|
|
|
|
res[j] = searcher.searchOne(haystack, haystack_end);
|
|
|
|
prev_offset = haystack_offsets[j];
|
|
|
|
}
|
|
|
|
++iteration;
|
|
|
|
}
|
2021-08-05 08:36:35 +00:00
|
|
|
if (iteration == 0)
|
|
|
|
std::fill(res.begin(), res.end(), 0);
|
2020-03-29 17:04:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|