2017-04-21 17:47:27 +00:00
|
|
|
#pragma once
|
2011-10-16 07:11:36 +00:00
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
#include <Columns/ColumnArray.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnConst.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
2018-09-03 04:57:01 +00:00
|
|
|
#include <Columns/ColumnVector.h>
|
2019-01-14 15:54:47 +00:00
|
|
|
#include <Core/Field.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
2018-09-03 04:57:01 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2017-07-21 06:35:58 +00:00
|
|
|
#include <Functions/FunctionHelpers.h>
|
2019-01-14 15:54:47 +00:00
|
|
|
#include <Functions/IFunction.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <common/StringRef.h>
|
|
|
|
#include <ext/range.h>
|
2016-10-24 13:47:15 +00:00
|
|
|
|
2011-10-16 07:11:36 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2017-05-27 15:45:25 +00:00
|
|
|
/** Search and replace functions in strings:
|
2011-10-16 07:11:36 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* position(haystack, needle) - the normal search for a substring in a string, returns the position (in bytes) of the found substring starting with 1, or 0 if no substring is found.
|
|
|
|
* positionUTF8(haystack, needle) - the same, but the position is calculated at code points, provided that the string is encoded in UTF-8.
|
2016-01-27 03:11:28 +00:00
|
|
|
* positionCaseInsensitive(haystack, needle)
|
|
|
|
* positionCaseInsensitiveUTF8(haystack, needle)
|
2014-06-26 00:58:14 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* like(haystack, pattern) - search by the regular expression LIKE; Returns 0 or 1. Case-insensitive, but only for Latin.
|
2011-10-17 08:28:39 +00:00
|
|
|
* notLike(haystack, pattern)
|
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* match(haystack, pattern) - search by regular expression re2; Returns 0 or 1.
|
2012-07-21 03:45:48 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* Applies regexp re2 and pulls:
|
|
|
|
* - the first subpattern, if the regexp has a subpattern;
|
|
|
|
* - the zero subpattern (the match part, otherwise);
|
|
|
|
* - if not match - an empty string.
|
2013-03-18 10:49:31 +00:00
|
|
|
* extract(haystack, pattern)
|
2011-10-17 08:28:39 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* replaceOne(haystack, pattern, replacement) - replacing the pattern with the specified rules, only the first occurrence.
|
|
|
|
* replaceAll(haystack, pattern, replacement) - replacing the pattern with the specified rules, all occurrences.
|
2011-10-16 07:11:36 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* replaceRegexpOne(haystack, pattern, replacement) - replaces the pattern with the specified regexp, only the first occurrence.
|
|
|
|
* replaceRegexpAll(haystack, pattern, replacement) - replaces the pattern with the specified type, all occurrences.
|
2019-01-14 15:54:47 +00:00
|
|
|
*
|
|
|
|
* multiPosition(haystack, [pattern_1, pattern_2, ..., pattern_n]) -- find first occurences (positions) of all the const patterns inside haystack
|
|
|
|
* multiPositionUTF8(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
* multiPositionCaseInsensitive(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
* multiPositionCaseInsensitiveUTF8(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
*
|
|
|
|
* multiSearch(haystack, [pattern_1, pattern_2, ..., pattern_n]) -- find any of the const patterns inside haystack and return 0 or 1
|
|
|
|
* multiSearchUTF8(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
* multiSearchCaseInsensitive(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
* multiSearchCaseInsensitiveUTF8(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
|
|
|
|
* firstMatch(haystack, [pattern_1, pattern_2, ..., pattern_n]) -- returns the first index of the matched string or zero if nothing was found
|
|
|
|
* firstMatchUTF8(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
* firstMatchCaseInsensitive(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
|
|
|
* firstMatchCaseInsensitiveUTF8(haystack, [pattern_1, pattern_2, ..., pattern_n])
|
2011-10-16 07:11:36 +00:00
|
|
|
*/
|
|
|
|
|
2018-09-03 04:57:01 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
|
|
|
extern const int ILLEGAL_COLUMN;
|
2019-01-14 15:54:47 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
2018-09-03 04:57:01 +00:00
|
|
|
}
|
2011-10-16 07:11:36 +00:00
|
|
|
|
2014-01-27 13:49:06 +00:00
|
|
|
template <typename Impl, typename Name>
|
2017-03-10 17:52:36 +00:00
|
|
|
class FunctionsStringSearch : public IFunction
|
2014-01-27 13:49:06 +00:00
|
|
|
{
|
|
|
|
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<FunctionsStringSearch>(); }
|
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 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 (!isString(arguments[0]))
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[0]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!isString(arguments[1]))
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[1]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return std::make_shared<DataTypeNumber<typename Impl::ResultType>>();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
using ResultType = typename Impl::ResultType;
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnPtr & column_haystack = block.getByPosition(arguments[0]).column;
|
|
|
|
const ColumnPtr & column_needle = block.getByPosition(arguments[1]).column;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnConst * col_haystack_const = typeid_cast<const ColumnConst *>(&*column_haystack);
|
|
|
|
const ColumnConst * col_needle_const = typeid_cast<const ColumnConst *>(&*column_needle);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (col_haystack_const && col_needle_const)
|
|
|
|
{
|
|
|
|
ResultType res{};
|
2017-07-21 06:35:58 +00:00
|
|
|
Impl::constant_constant(col_haystack_const->getValue<String>(), col_needle_const->getValue<String>(), res);
|
2019-01-14 15:54:47 +00:00
|
|
|
block.getByPosition(result).column
|
|
|
|
= block.getByPosition(result).type->createColumnConst(col_haystack_const->size(), toField(res));
|
2017-04-01 07:20:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
auto col_res = ColumnVector<ResultType>::create();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-15 21:32:25 +00:00
|
|
|
typename ColumnVector<ResultType>::Container & vec_res = col_res->getData();
|
2017-04-01 07:20:54 +00:00
|
|
|
vec_res.resize(column_haystack->size());
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnString * col_haystack_vector = checkAndGetColumn<ColumnString>(&*column_haystack);
|
|
|
|
const ColumnString * col_needle_vector = checkAndGetColumn<ColumnString>(&*column_needle);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (col_haystack_vector && col_needle_vector)
|
2019-01-14 15:54:47 +00:00
|
|
|
Impl::vector_vector(
|
|
|
|
col_haystack_vector->getChars(),
|
2017-04-01 07:20:54 +00:00
|
|
|
col_haystack_vector->getOffsets(),
|
|
|
|
col_needle_vector->getChars(),
|
|
|
|
col_needle_vector->getOffsets(),
|
|
|
|
vec_res);
|
|
|
|
else if (col_haystack_vector && col_needle_const)
|
2019-01-14 15:54:47 +00:00
|
|
|
Impl::vector_constant(
|
|
|
|
col_haystack_vector->getChars(), col_haystack_vector->getOffsets(), col_needle_const->getValue<String>(), vec_res);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (col_haystack_const && col_needle_vector)
|
2019-01-14 15:54:47 +00:00
|
|
|
Impl::constant_vector(
|
|
|
|
col_haystack_const->getValue<String>(), col_needle_vector->getChars(), col_needle_vector->getOffsets(), vec_res);
|
2017-04-01 07:20:54 +00:00
|
|
|
else
|
2019-01-14 15:54:47 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal columns " + block.getByPosition(arguments[0]).column->getName() + " and "
|
|
|
|
+ block.getByPosition(arguments[1]).column->getName() + " of arguments of function " + getName(),
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
2017-12-16 05:21:04 +00:00
|
|
|
|
|
|
|
block.getByPosition(result).column = std::move(col_res);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2011-10-16 07:11:36 +00:00
|
|
|
};
|
|
|
|
|
2011-10-17 08:28:39 +00:00
|
|
|
|
2013-02-28 13:01:07 +00:00
|
|
|
template <typename Impl, typename Name>
|
|
|
|
class FunctionsStringSearchToString : 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<FunctionsStringSearchToString>(); }
|
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 2; }
|
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}; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
|
|
|
{
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!isString(arguments[0]))
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[0]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!isString(arguments[1]))
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[1]->getName() + " of argument of function " + getName(), 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 = block.getByPosition(arguments[0]).column;
|
|
|
|
const ColumnPtr column_needle = block.getByPosition(arguments[1]).column;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnConst * col_needle = typeid_cast<const ColumnConst *>(&*column_needle);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!col_needle)
|
|
|
|
throw Exception("Second argument of function " + getName() + " must be constant string.", ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
if (const ColumnString * col = checkAndGetColumn<ColumnString>(column.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
|
|
|
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & vec_res = col_res->getChars();
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offsets & offsets_res = col_res->getOffsets();
|
2017-07-21 06:35:58 +00:00
|
|
|
Impl::vector(col->getChars(), col->getOffsets(), col_needle->getValue<String>(), vec_res, offsets_res);
|
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 argument of function " + getName(),
|
2017-04-01 07:20:54 +00:00
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
}
|
2013-02-28 13:01:07 +00:00
|
|
|
};
|
2017-03-12 11:09:25 +00:00
|
|
|
|
2019-01-14 15:54:47 +00:00
|
|
|
template <typename Impl, typename Name>
|
|
|
|
class FunctionsMultiStringPosition : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = Name::name;
|
|
|
|
static FunctionPtr create(const Context &) { return std::make_shared<FunctionsMultiStringPosition>(); }
|
|
|
|
|
|
|
|
String getName() const override { return name; }
|
|
|
|
|
|
|
|
size_t getNumberOfArguments() const override { return 2; }
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.size() + 1 >= std::numeric_limits<UInt8>::max())
|
|
|
|
throw Exception(
|
|
|
|
"Number of arguments for function " + getName() + " doesn't match: passed " + std::to_string(arguments.size())
|
|
|
|
+ ", should be at most 255.",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
if (!isString(arguments[0]))
|
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[0]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
const DataTypeArray * array_type = checkAndGetDataType<DataTypeArray>(arguments[1].get());
|
|
|
|
if (!array_type || !checkAndGetDataType<DataTypeString>(array_type->getNestedType().get()))
|
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[1]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
|
|
|
|
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) override
|
|
|
|
{
|
|
|
|
using ResultType = typename Impl::ResultType;
|
|
|
|
|
|
|
|
const ColumnPtr & column_haystack = block.getByPosition(arguments[0]).column;
|
|
|
|
|
|
|
|
const ColumnString * col_haystack_vector = checkAndGetColumn<ColumnString>(&*column_haystack);
|
|
|
|
|
|
|
|
const ColumnPtr & arr_ptr = block.getByPosition(arguments[1]).column;
|
|
|
|
const ColumnConst * col_const_arr = checkAndGetColumnConst<ColumnArray>(arr_ptr.get());
|
|
|
|
|
|
|
|
if (!col_const_arr)
|
|
|
|
throw Exception(
|
|
|
|
"Illegal column " + block.getByPosition(arguments[1]).column->getName() + ". The array is not const",
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
|
|
|
Array src_arr = col_const_arr->getValue<Array>();
|
|
|
|
|
|
|
|
std::vector<String> refs;
|
|
|
|
for (const auto & el : src_arr)
|
|
|
|
{
|
|
|
|
refs.push_back(el.get<String>());
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t column_haystack_size = column_haystack->size();
|
|
|
|
|
|
|
|
auto col_res = ColumnVector<ResultType>::create();
|
|
|
|
auto col_offsets = ColumnArray::ColumnOffsets::create(column_haystack_size);
|
|
|
|
|
|
|
|
auto & vec_res = col_res->getData();
|
|
|
|
auto & offsets_res = col_offsets->getData();
|
|
|
|
|
|
|
|
vec_res.resize(column_haystack_size * refs.size());
|
|
|
|
|
|
|
|
if (col_haystack_vector)
|
|
|
|
Impl::multi_constant_vector(col_haystack_vector->getChars(), col_haystack_vector->getOffsets(), refs, vec_res);
|
|
|
|
else
|
|
|
|
throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName(), ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
|
|
|
size_t refs_size = refs.size();
|
|
|
|
size_t accum = refs_size;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < column_haystack_size; ++i, accum += refs_size)
|
|
|
|
{
|
|
|
|
offsets_res[i] = accum;
|
|
|
|
}
|
|
|
|
|
|
|
|
block.getByPosition(result).column = ColumnArray::create(std::move(col_res), std::move(col_offsets));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Impl, typename Name>
|
|
|
|
class FunctionsMultiStringSearch : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = Name::name;
|
|
|
|
static FunctionPtr create(const Context &) { return std::make_shared<FunctionsMultiStringSearch>(); }
|
|
|
|
|
|
|
|
String getName() const override { return name; }
|
|
|
|
|
|
|
|
size_t getNumberOfArguments() const override { return 2; }
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.size() + 1 >= std::numeric_limits<UInt8>::max())
|
|
|
|
throw Exception(
|
|
|
|
"Number of arguments for function " + getName() + " doesn't match: passed " + std::to_string(arguments.size())
|
|
|
|
+ ", should be at most 255.",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
if (!isString(arguments[0]))
|
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[0]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
const DataTypeArray * array_type = checkAndGetDataType<DataTypeArray>(arguments[1].get());
|
|
|
|
if (!array_type || !checkAndGetDataType<DataTypeString>(array_type->getNestedType().get()))
|
|
|
|
throw Exception(
|
|
|
|
"Illegal type " + arguments[1]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
|
|
|
|
return std::make_shared<DataTypeNumber<typename Impl::ResultType>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) override
|
|
|
|
{
|
|
|
|
using ResultType = typename Impl::ResultType;
|
|
|
|
|
|
|
|
const ColumnPtr & column_haystack = block.getByPosition(arguments[0]).column;
|
|
|
|
|
|
|
|
const ColumnString * col_haystack_vector = checkAndGetColumn<ColumnString>(&*column_haystack);
|
|
|
|
|
|
|
|
const ColumnPtr & arr_ptr = block.getByPosition(arguments[1]).column;
|
|
|
|
const ColumnConst * col_const_arr = checkAndGetColumnConst<ColumnArray>(arr_ptr.get());
|
|
|
|
|
|
|
|
if (!col_const_arr)
|
|
|
|
throw Exception(
|
|
|
|
"Illegal column " + block.getByPosition(arguments[1]).column->getName() + ". The array is not const",
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
|
|
|
Array src_arr = col_const_arr->getValue<Array>();
|
|
|
|
|
|
|
|
std::vector<String> refs;
|
|
|
|
refs.reserve(src_arr.size());
|
|
|
|
|
|
|
|
for (const auto & el : src_arr)
|
|
|
|
refs.emplace_back(el.get<String>());
|
|
|
|
|
|
|
|
const size_t column_haystack_size = column_haystack->size();
|
|
|
|
|
|
|
|
auto col_res = ColumnVector<ResultType>::create();
|
|
|
|
|
|
|
|
auto & vec_res = col_res->getData();
|
|
|
|
|
|
|
|
vec_res.resize(column_haystack_size);
|
|
|
|
|
|
|
|
if (col_haystack_vector)
|
|
|
|
Impl::multi_constant_vector(col_haystack_vector->getChars(), col_haystack_vector->getOffsets(), refs, vec_res);
|
|
|
|
else
|
|
|
|
throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName(), ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
|
|
|
block.getByPosition(result).column = std::move(col_res);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-10-16 07:11:36 +00:00
|
|
|
}
|