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 IArraySource from ColumnArray
|
|
|
|
|
|
|
|
template <typename... Types>
|
|
|
|
struct ArraySourceCreator;
|
|
|
|
|
|
|
|
template <typename Type, typename... Types>
|
|
|
|
struct ArraySourceCreator<Type, Types...>
|
|
|
|
{
|
2018-01-19 15:19:02 +00:00
|
|
|
static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows)
|
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<const ColVecType *>(&col.getData()))
|
2017-10-12 19:58:39 +00:00
|
|
|
{
|
|
|
|
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<>
|
|
|
|
{
|
2018-01-19 15:19:02 +00:00
|
|
|
static std::unique_ptr<IArraySource> create(const ColumnArray & col, const NullMap * null_map, bool is_const, size_t total_rows)
|
2017-10-12 19:58:39 +00:00
|
|
|
{
|
|
|
|
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 = typename ApplyTypeListForClass<ArraySourceCreator, TypeListNumbers>::Type;
|
|
|
|
if (auto column_nullable = typeid_cast<const ColumnNullable *>(&col.getData()))
|
|
|
|
{
|
2017-12-16 06:02:54 +00:00
|
|
|
auto column = ColumnArray::create(column_nullable->getNestedColumnPtr(), col.getOffsetsPtr());
|
2018-01-19 15:19:02 +00:00
|
|
|
return Creator::create(*column, &column_nullable->getNullMapData(), is_const, total_rows);
|
2017-10-12 19:58:39 +00:00
|
|
|
}
|
|
|
|
return Creator::create(col, nullptr, is_const, total_rows);
|
|
|
|
}
|
|
|
|
}
|