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/GatherUtils/createArraySource.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/GatherUtils/createArraySource.cpp')
| -rw-r--r-- | contrib/clickhouse/src/Functions/GatherUtils/createArraySource.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/GatherUtils/createArraySource.cpp b/contrib/clickhouse/src/Functions/GatherUtils/createArraySource.cpp new file mode 100644 index 00000000000..500af6a2cc7 --- /dev/null +++ b/contrib/clickhouse/src/Functions/GatherUtils/createArraySource.cpp @@ -0,0 +1,69 @@ +#include "GatherUtils.h" +#include "Sinks.h" +#include "Sources.h" +#include <base/TypeLists.h> + +namespace DB::GatherUtils +{ +/// Creates IArraySource from ColumnArray + +namespace +{ + +template <typename... Types> +struct ArraySourceCreator; + +template <typename Type, typename... Types> +struct ArraySourceCreator<Type, Types...> +{ + static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows) + { + using ColVecType = ColumnVectorOrDecimal<Type>; + + if (typeid_cast<const ColVecType *>(&col.getData())) + { + if (null_map) + { + if (is_const) + return std::make_unique<ConstSource<NullableArraySource<NumericArraySource<Type>>>>(col, *null_map, total_rows); + return std::make_unique<NullableArraySource<NumericArraySource<Type>>>(col, *null_map); + } + if (is_const) + return std::make_unique<ConstSource<NumericArraySource<Type>>>(col, total_rows); + return std::make_unique<NumericArraySource<Type>>(col); + } + + return ArraySourceCreator<Types...>::create(col, null_map, is_const, total_rows); + } +}; + +template <> +struct ArraySourceCreator<> +{ + static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows) + { + if (null_map) + { + if (is_const) + return std::make_unique<ConstSource<NullableArraySource<GenericArraySource>>>(col, *null_map, total_rows); + return std::make_unique<NullableArraySource<GenericArraySource>>(col, *null_map); + } + if (is_const) + return std::make_unique<ConstSource<GenericArraySource>>(col, total_rows); + return std::make_unique<GenericArraySource>(col); + } +}; + +} + +std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is_const, size_t total_rows) +{ + using Creator = TypeListChangeRoot<ArraySourceCreator, TypeListNumberWithUUID>; + if (const auto * column_nullable = typeid_cast<const ColumnNullable *>(&col.getData())) + { + auto column = ColumnArray::create(column_nullable->getNestedColumnPtr(), col.getOffsetsPtr()); + return Creator::create(*column, &column_nullable->getNullMapData(), is_const, total_rows); + } + return Creator::create(col, nullptr, is_const, total_rows); +} +} |
