Fix style in PositionImpl and FunctionsStringSearch

This commit is contained in:
vdimir 2020-08-02 14:24:39 +00:00
parent 32f26bcde7
commit 368314b930
5 changed files with 43 additions and 35 deletions

View File

@ -50,14 +50,12 @@ public:
String getName() const override { return name; }
bool isVariadic() const override {
return Impl::supports_start_pos;
}
bool isVariadic() const override { return Impl::supports_start_pos; }
size_t getNumberOfArguments() const override {
if (Impl::supports_start_pos) {
size_t getNumberOfArguments() const override
{
if (Impl::supports_start_pos)
return 0;
}
return 2;
}
@ -82,11 +80,11 @@ public:
throw Exception(
"Illegal type " + arguments[1]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
if (arguments.size() >= 3) {
if (!isUnsignedInteger(arguments[2])) {
if (arguments.size() >= 3)
{
if (!isUnsignedInteger(arguments[2]))
throw Exception(
"Illegal type " + arguments[2]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
}
return std::make_shared<DataTypeNumber<typename Impl::ResultType>>();
@ -100,9 +98,8 @@ public:
const ColumnPtr & column_needle = block.getByPosition(arguments[1]).column;
ColumnPtr column_start_pos = nullptr;
if (arguments.size() >= 3) {
if (arguments.size() >= 3)
column_start_pos = block.getByPosition(arguments[2]).column;
}
const ColumnConst * col_haystack_const = typeid_cast<const ColumnConst *>(&*column_haystack);
const ColumnConst * col_needle_const = typeid_cast<const ColumnConst *>(&*column_needle);
@ -122,12 +119,11 @@ public:
column_start_pos,
vec_res);
if (is_col_start_pos_const) {
if (is_col_start_pos_const)
block.getByPosition(result).column
= block.getByPosition(result).type->createColumnConst(col_haystack_const->size(), toField(vec_res[0]));
} else {
else
block.getByPosition(result).column = std::move(col_res);
}
return;
}

View File

@ -89,9 +89,9 @@ struct ExtractParamImpl
const ColumnPtr & start_pos,
PaddedPODArray<ResultType> & res)
{
if (start_pos != nullptr) {
if (start_pos != nullptr)
throw Exception("Functions 'visitParamHas' and 'visitParamExtract*' doesn't support start_pos argument", ErrorCodes::ILLEGAL_COLUMN);
}
/// We are looking for a parameter simply as a substring of the form "name"
needle = "\"" + needle + "\":";

View File

@ -8,6 +8,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int ILLEGAL_COLUMN;
}
@ -28,9 +29,8 @@ struct HasTokenImpl
const ColumnPtr & start_pos,
PaddedPODArray<UInt8> & res)
{
if (start_pos != nullptr) {
if (start_pos != nullptr)
throw Exception("Function 'hasToken' does not support start_pos argument", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
if (offsets.empty())
return;

View File

@ -24,6 +24,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int ILLEGAL_COLUMN;
}
@ -91,9 +92,8 @@ struct MatchImpl
const ColumnPtr & start_pos,
PaddedPODArray<UInt8> & res)
{
if (start_pos != nullptr) {
if (start_pos != nullptr)
throw Exception("Functions 'like' and 'match' don't support start_pos argument", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
if (offsets.empty())
return;

View File

@ -42,7 +42,8 @@ struct PositionCaseSensitiveASCII
return MultiSearcherInBigHaystack(needles);
}
static const char * advancePos(const char * pos, const char * end, size_t n) {
static const char * advancePos(const char * pos, const char * end, size_t n)
{
return std::min(pos + n, end);
}
@ -77,7 +78,8 @@ struct PositionCaseInsensitiveASCII
return MultiSearcherInBigHaystack(needles);
}
static const char * advancePos(const char * pos, const char * end, size_t n) {
static const char * advancePos(const char * pos, const char * end, size_t n)
{
return std::min(pos + n, end);
}
@ -110,11 +112,12 @@ struct PositionCaseSensitiveUTF8
static const char * advancePos(const char * pos, const char * end, size_t n)
{
for (auto it = pos; it != end; ++it) {
if (!UTF8::isContinuationOctet(static_cast<UInt8>(*it))) {
if (n == 0) {
for (auto it = pos; it != end; ++it)
{
if (!UTF8::isContinuationOctet(static_cast<UInt8>(*it)))
{
if (n == 0)
return it;
}
n--;
}
}
@ -208,9 +211,11 @@ struct PositionImpl
auto start = start_pos != nullptr ? start_pos->getUInt(i) : 0;
/// We check that the entry does not pass through the boundaries of strings.
if (pos + needle.size() < begin + offsets[i]) {
if (pos + needle.size() < begin + offsets[i])
{
auto res_pos = 1 + Impl::countChars(reinterpret_cast<const char *>(begin + offsets[i - 1]), reinterpret_cast<const char *>(pos));
if (res_pos < start) {
if (res_pos < start)
{
pos = reinterpret_cast<const UInt8 *>(Impl::advancePos(
reinterpret_cast<const char *>(pos),
reinterpret_cast<const char *>(begin + offsets[i]),
@ -219,7 +224,8 @@ struct PositionImpl
}
res[i] = res_pos;
}
else {
else
{
res[i] = 0;
}
pos = begin + offsets[i];
@ -239,7 +245,8 @@ struct PositionImpl
{
auto start = std::max(start_pos, 1ul);
if (needle.size() == 0) {
if (needle.size() == 0)
{
size_t haystack_size = Impl::countChars(data.data(), data.data() + data.size());
res = start <= haystack_size + 1 ? start : 0;
return;
@ -263,7 +270,8 @@ struct PositionImpl
Impl::toLowerIfNeed(data);
Impl::toLowerIfNeed(needle);
if (start_pos == nullptr) {
if (start_pos == nullptr)
{
constantConstantScalar(data, needle, 0, res[0]);
return;
}
@ -271,10 +279,12 @@ struct PositionImpl
size_t haystack_size = Impl::countChars(data.data(), data.data() + data.size());
size_t size = start_pos != nullptr ? start_pos->size() : 0;
for (size_t i = 0; i < size; ++i) {
for (size_t i = 0; i < size; ++i)
{
auto start = start_pos->getUInt(i);
if (start > haystack_size + 1) {
if (start > haystack_size + 1)
{
res[i] = 0;
continue;
}
@ -303,7 +313,8 @@ struct PositionImpl
auto start = start_pos != nullptr ? std::max(start_pos->getUInt(i), 1ul) : 1ul;
if (start > haystack_size + 1) {
if (start > haystack_size + 1)
{
res[i] = 0;
}
else if (0 == needle_size)
@ -362,7 +373,8 @@ struct PositionImpl
auto start = start_pos != nullptr ? std::max(start_pos->getUInt(i), 1ul) : 1ul;
if (start > haystack.size() + 1) {
if (start > haystack.size() + 1)
{
res[i] = 0;
}
else if (0 == needle_size)