2019-12-15 06:34:43 +00:00
|
|
|
#include "GatherUtils.h"
|
2019-06-21 15:31:37 +00:00
|
|
|
#include "Sinks.h"
|
|
|
|
#include "Sources.h"
|
2018-01-10 15:45:05 +00:00
|
|
|
#include <Core/TypeListNumber.h>
|
2017-10-12 19:58:39 +00:00
|
|
|
|
2018-01-10 15:45:05 +00:00
|
|
|
namespace DB::GatherUtils
|
2017-10-12 19:58:39 +00:00
|
|
|
{
|
|
|
|
/// Creates IArraySink from ColumnArray
|
|
|
|
|
|
|
|
template <typename... Types>
|
|
|
|
struct ArraySinkCreator;
|
|
|
|
|
|
|
|
template <typename Type, typename... Types>
|
|
|
|
struct ArraySinkCreator<Type, Types...>
|
|
|
|
{
|
2018-01-19 15:19:02 +00:00
|
|
|
static std::unique_ptr<IArraySink> create(ColumnArray & col, NullMap * null_map, size_t column_size)
|
2017-10-12 19:58:39 +00:00
|
|
|
{
|
2019-11-11 16:18:37 +00:00
|
|
|
using ColVecType = std::conditional_t<IsDecimalNumber<Type>, ColumnDecimal<Type>, ColumnVector<Type>>;
|
|
|
|
|
|
|
|
if (typeid_cast<ColVecType *>(&col.getData()))
|
2017-10-12 19:58:39 +00:00
|
|
|
{
|
|
|
|
if (null_map)
|
|
|
|
return std::make_unique<NullableArraySink<NumericArraySink<Type>>>(col, *null_map, column_size);
|
|
|
|
return std::make_unique<NumericArraySink<Type>>(col, column_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ArraySinkCreator<Types...>::create(col, null_map, column_size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ArraySinkCreator<>
|
|
|
|
{
|
2018-01-19 15:19:02 +00:00
|
|
|
static std::unique_ptr<IArraySink> create(ColumnArray & col, NullMap * null_map, size_t column_size)
|
2017-10-12 19:58:39 +00:00
|
|
|
{
|
|
|
|
if (null_map)
|
|
|
|
return std::make_unique<NullableArraySink<GenericArraySink>>(col, *null_map, column_size);
|
|
|
|
return std::make_unique<GenericArraySink>(col, column_size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size)
|
|
|
|
{
|
|
|
|
using Creator = ApplyTypeListForClass<ArraySinkCreator, TypeListNumbers>::Type;
|
|
|
|
if (auto column_nullable = typeid_cast<ColumnNullable *>(&col.getData()))
|
|
|
|
{
|
2019-03-25 01:43:54 +00:00
|
|
|
auto column = ColumnArray::create(column_nullable->getNestedColumnPtr()->assumeMutable(), col.getOffsetsPtr()->assumeMutable());
|
2018-01-19 15:19:02 +00:00
|
|
|
return Creator::create(*column, &column_nullable->getNullMapData(), column_size);
|
2017-10-12 19:58:39 +00:00
|
|
|
}
|
|
|
|
return Creator::create(col, nullptr, column_size);
|
|
|
|
}
|
|
|
|
}
|