diff options
| author | vitalyisaev <[email protected]> | 2023-11-14 09:58:56 +0300 |
|---|---|---|
| committer | vitalyisaev <[email protected]> | 2023-11-14 10:20:20 +0300 |
| commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
| tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/array/arrayExists.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/array/arrayExists.cpp')
| -rw-r--r-- | contrib/clickhouse/src/Functions/array/arrayExists.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/array/arrayExists.cpp b/contrib/clickhouse/src/Functions/array/arrayExists.cpp new file mode 100644 index 00000000000..d59425338a5 --- /dev/null +++ b/contrib/clickhouse/src/Functions/array/arrayExists.cpp @@ -0,0 +1,71 @@ +#include <Functions/array/arrayExists.h> +#include <Functions/FunctionFactory.h> + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int ILLEGAL_COLUMN; +} + +ColumnPtr ArrayExistsImpl::execute(const ColumnArray & array, ColumnPtr mapped) +{ + const ColumnUInt8 * column_filter = typeid_cast<const ColumnUInt8 *>(&*mapped); + + if (!column_filter) + { + const auto * column_filter_const = checkAndGetColumnConst<ColumnUInt8>(&*mapped); + + if (!column_filter_const) + throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Unexpected type of filter column"); + + if (column_filter_const->getValue<UInt8>()) + { + const IColumn::Offsets & offsets = array.getOffsets(); + auto out_column = ColumnUInt8::create(offsets.size()); + ColumnUInt8::Container & out_exists = out_column->getData(); + + size_t pos = 0; + for (size_t i = 0; i < offsets.size(); ++i) + { + out_exists[i] = offsets[i] - pos > 0; + pos = offsets[i]; + } + + return out_column; + } + else + return DataTypeUInt8().createColumnConst(array.size(), 0u); + } + + const IColumn::Filter & filter = column_filter->getData(); + const IColumn::Offsets & offsets = array.getOffsets(); + auto out_column = ColumnUInt8::create(offsets.size()); + ColumnUInt8::Container & out_exists = out_column->getData(); + + size_t pos = 0; + for (size_t i = 0; i < offsets.size(); ++i) + { + UInt8 exists = 0; + for (; pos < offsets[i]; ++pos) + { + if (filter[pos]) + { + exists = 1; + pos = offsets[i]; + break; + } + } + out_exists[i] = exists; + } + + return out_column; +} + +REGISTER_FUNCTION(ArrayExists) +{ + factory.registerFunction<FunctionArrayExists>(); +} + +} |
