From 7084fbfee356636aaac115975d817a9854f3e68b Mon Sep 17 00:00:00 2001 From: Roman Vasin Date: Fri, 25 Nov 2022 06:51:08 +0000 Subject: [PATCH] Make iteration through array of values --- src/Functions/URL/cutURLParameter.cpp | 31 +++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Functions/URL/cutURLParameter.cpp b/src/Functions/URL/cutURLParameter.cpp index 92cd6df3429..8776801c7a1 100644 --- a/src/Functions/URL/cutURLParameter.cpp +++ b/src/Functions/URL/cutURLParameter.cpp @@ -44,7 +44,7 @@ public: throw Exception( "Illegal type " + arguments[0]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - if (!isString(arguments[1])) + if (!isString(arguments[1]) && !isArray(arguments[1])) throw Exception( "Illegal type " + arguments[1]->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); @@ -55,10 +55,13 @@ public: { const ColumnPtr column = arguments[0].column; const ColumnPtr column_needle = arguments[1].column; + // assert(isArray(arguments[1].type)); const ColumnConst * col_needle = typeid_cast(&*column_needle); - if (!col_needle) - throw Exception("Second argument of function " + getName() + " must be constant string", ErrorCodes::ILLEGAL_COLUMN); + const ColumnArray * col_const_array = checkAndGetColumnConstData(column_needle.get()); + + if (!col_needle && !col_const_array) + throw Exception("Second argument of function " + getName() + " must be constant string or constant array", ErrorCodes::ILLEGAL_COLUMN); if (const ColumnString * col = checkAndGetColumn(column.get())) { @@ -66,8 +69,28 @@ public: ColumnString::Chars & vec_res = col_res->getChars(); ColumnString::Offsets & offsets_res = col_res->getOffsets(); - vector(col->getChars(), col->getOffsets(), col_needle->getValue(), vec_res, offsets_res); + if (!col_const_array) + { + vector(col->getChars(), col->getOffsets(), col_needle->getValue(), vec_res, offsets_res); + } + else + { + size_t arr_size = col_const_array->size(); + assert(arr_size>0); + size_t data_size = col_const_array->getData().size(); + assert(data_size>0); + + for (size_t i = 0; i < data_size; ++i) + { + auto field = col_const_array->getData()[i]; + // auto typename_ = field.getTypeName(); + // assert(typename_ != ""); + auto field_value = field.get(); + assert(field_value != ""); + vector(col->getChars(), col->getOffsets(), field_value, vec_res, offsets_res); + } + } return col_res; } else