Merge pull request #14848 from ClickHouse/test-gather-utils-build-time

Improve GatherUtils build time
This commit is contained in:
Nikolai Kochetov 2020-09-17 08:58:00 +03:00 committed by GitHub
commit a67986791f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 291 additions and 143 deletions

View File

@ -21,7 +21,6 @@ namespace DB::GatherUtils
inline constexpr size_t MAX_ARRAY_SIZE = 1 << 30;
/// Methods to copy Slice to Sink, overloaded for various combinations of types.
template <typename T>

View File

@ -41,18 +41,37 @@ std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is
std::unique_ptr<IValueSource> createValueSource(const IColumn & col, bool is_const, size_t total_rows);
std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size);
void concat(const std::vector<std::unique_ptr<IArraySource>> & sources, IArraySink & sink);
ColumnArray::MutablePtr concat(const std::vector<std::unique_ptr<IArraySource>> & sources);
void sliceFromLeftConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset);
void sliceFromLeftConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length);
ColumnArray::MutablePtr sliceFromLeftConstantOffsetUnbounded(IArraySource & src, size_t offset);
ColumnArray::MutablePtr sliceFromLeftConstantOffsetBounded(IArraySource & src, size_t offset, ssize_t length);
void sliceFromRightConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset);
void sliceFromRightConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length);
ColumnArray::MutablePtr sliceFromRightConstantOffsetUnbounded(IArraySource & src, size_t offset);
ColumnArray::MutablePtr sliceFromRightConstantOffsetBounded(IArraySource & src, size_t offset, ssize_t length);
void sliceDynamicOffsetUnbounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column);
void sliceDynamicOffsetBounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column, const IColumn & length_column);
ColumnArray::MutablePtr sliceDynamicOffsetUnbounded(IArraySource & src, const IColumn & offset_column);
ColumnArray::MutablePtr sliceDynamicOffsetBounded(IArraySource & src, const IColumn & offset_column, const IColumn & length_column);
void sliceHas(IArraySource & first, IArraySource & second, ArraySearchType search_type, ColumnUInt8 & result);
void sliceHasAny(IArraySource & first, IArraySource & second, ColumnUInt8 & result);
void sliceHasAll(IArraySource & first, IArraySource & second, ColumnUInt8 & result);
void sliceHasSubstr(IArraySource & first, IArraySource & second, ColumnUInt8 & result);
inline void sliceHas(IArraySource & first, IArraySource & second, ArraySearchType search_type, ColumnUInt8 & result)
{
switch (search_type)
{
case ArraySearchType::All:
sliceHasAll(first, second, result);
break;
case ArraySearchType::Any:
sliceHasAny(first, second, result);
break;
case ArraySearchType::Substr:
sliceHasSubstr(first, second, result);
break;
}
}
void push(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, bool push_front);

View File

@ -11,6 +11,7 @@
#include <Columns/ColumnNullable.h>
#include <Common/typeid_cast.h>
#include <Common/assert_cast.h>
namespace DB::GatherUtils
{
@ -44,8 +45,8 @@ struct NumericArraySink : public ArraySinkImpl<NumericArraySink<T>>
size_t row_num = 0;
ColumnArray::Offset current_offset = 0;
NumericArraySink(ColumnArray & arr, size_t column_size)
: elements(typeid_cast<ColVecType &>(arr.getData()).getData()), offsets(arr.getOffsets())
NumericArraySink(IColumn & elements_, ColumnArray::Offsets & offsets_, size_t column_size)
: elements(assert_cast<ColVecType&>(elements_).getData()), offsets(offsets_)
{
offsets.resize(column_size);
}
@ -161,8 +162,8 @@ struct GenericArraySink : public ArraySinkImpl<GenericArraySink>
size_t row_num = 0;
ColumnArray::Offset current_offset = 0;
GenericArraySink(ColumnArray & arr, size_t column_size)
: elements(arr.getData()), offsets(arr.getOffsets())
GenericArraySink(IColumn & elements_, ColumnArray::Offsets & offsets_, size_t column_size)
: elements(elements_), offsets(offsets_)
{
offsets.resize(column_size);
}
@ -198,8 +199,9 @@ struct NullableArraySink : public ArraySink
NullMap & null_map;
NullableArraySink(ColumnArray & arr, NullMap & null_map_, size_t column_size)
: ArraySink(arr, column_size), null_map(null_map_)
NullableArraySink(IColumn & elements_, ColumnArray::Offsets & offsets_, size_t column_size)
: ArraySink(assert_cast<ColumnNullable &>(elements_).getNestedColumn(), offsets_, column_size)
, null_map(assert_cast<ColumnNullable &>(elements_).getNullMapData())
{
}

View File

@ -29,6 +29,12 @@ namespace ErrorCodes
namespace GatherUtils
{
template <typename T> struct NumericArraySink;
struct StringSink;
struct FixedStringSink;
struct GenericArraySink;
template <typename ArraySink> struct NullableArraySink;
template <typename T>
struct NumericArraySource : public ArraySourceImpl<NumericArraySource<T>>
{
@ -36,14 +42,23 @@ struct NumericArraySource : public ArraySourceImpl<NumericArraySource<T>>
using Slice = NumericArraySlice<T>;
using Column = ColumnArray;
using SinkType = NumericArraySink<T>;
const ColVecType & column;
const typename ColVecType::Container & elements;
const typename ColumnArray::Offsets & offsets;
size_t row_num = 0;
ColumnArray::Offset prev_offset = 0;
MutableColumnPtr createValuesColumn()
{
return column.cloneEmpty();
}
explicit NumericArraySource(const ColumnArray & arr)
: elements(typeid_cast<const ColVecType &>(arr.getData()).getData()), offsets(arr.getOffsets())
: column(typeid_cast<const ColVecType &>(arr.getData()))
, elements(typeid_cast<const ColVecType &>(arr.getData()).getData()), offsets(arr.getOffsets())
{
}
@ -143,6 +158,8 @@ struct ConstSource : public Base
using Slice = typename Base::Slice;
using Column = ColumnConst;
using SinkType = typename Base::SinkType;
size_t total_rows;
size_t row_num = 0;
@ -224,6 +241,8 @@ struct StringSource
using Slice = NumericArraySlice<UInt8>;
using Column = ColumnString;
using SinkType = StringSink;
const typename ColumnString::Chars & elements;
const typename ColumnString::Offsets & offsets;
@ -391,6 +410,8 @@ struct FixedStringSource
using Slice = NumericArraySlice<UInt8>;
using Column = ColumnFixedString;
using SinkType = FixedStringSink;
const UInt8 * pos;
const UInt8 * end;
size_t string_size;
@ -511,12 +532,19 @@ struct GenericArraySource : public ArraySourceImpl<GenericArraySource>
using Slice = GenericArraySlice;
using Column = ColumnArray;
using SinkType = GenericArraySink;
const IColumn & elements;
const typename ColumnArray::Offsets & offsets;
size_t row_num = 0;
ColumnArray::Offset prev_offset = 0;
MutableColumnPtr createValuesColumn()
{
return elements.cloneEmpty();
}
explicit GenericArraySource(const ColumnArray & arr)
: elements(arr.getData()), offsets(arr.getOffsets())
{
@ -550,7 +578,7 @@ struct GenericArraySource : public ArraySourceImpl<GenericArraySource>
size_t getColumnSize() const override
{
return elements.size();
return offsets.size();
}
size_t getElementSize() const
@ -605,6 +633,8 @@ struct NullableArraySource : public ArraySource
using ArraySource::row_num;
using ArraySource::offsets;
using SinkType = NullableArraySink<typename ArraySource::SinkType>;
const NullMap & null_map;
NullableArraySource(const ColumnArray & arr, const NullMap & null_map_)
@ -612,6 +642,11 @@ struct NullableArraySource : public ArraySource
{
}
MutableColumnPtr createValuesColumn()
{
return ColumnNullable::create(static_cast<ArraySource *>(this)->createValuesColumn(), ColumnUInt8::create());
}
void accept(ArraySourceVisitor & visitor) override { visitor.visit(*this); }
Slice getWhole() const
@ -674,6 +709,8 @@ struct NumericValueSource : ValueSourceImpl<NumericValueSource<T>>
using Slice = NumericValueSlice<T>;
using Column = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
using SinkType = NumericArraySink<T>;
const T * begin;
size_t total_rows;
size_t row_num = 0;
@ -716,6 +753,7 @@ struct NumericValueSource : ValueSourceImpl<NumericValueSource<T>>
struct GenericValueSource : public ValueSourceImpl<GenericValueSource>
{
using Slice = GenericValueSlice;
using SinkType = GenericArraySink;
const IColumn * column;
size_t total_rows;
@ -759,6 +797,8 @@ struct GenericValueSource : public ValueSourceImpl<GenericValueSource>
template <typename ValueSource>
struct NullableValueSource : public ValueSource
{
using SinkType = NullableArraySink<typename ValueSource::SinkType>;
using Slice = NullableSlice<typename ValueSource::Slice>;
using ValueSource::row_num;

View File

@ -16,37 +16,52 @@ namespace ErrorCodes
namespace GatherUtils
{
struct ArrayConcat : public ArraySinkSourceSelector<ArrayConcat>
struct ArrayConcat : public ArraySourceSelector<ArrayConcat>
{
using Sources = std::vector<std::unique_ptr<IArraySource>>;
template <typename Source, typename Sink>
static void selectSourceSink(Source &&, Sink && sink, const Sources & sources)
template <typename Source>
static void selectImpl(Source && source, const Sources & sources, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
concat<SourceType, Sink>(sources, sink);
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
concat<SourceType, Sink>(sources, std::move(sink));
}
template <typename Source, typename Sink>
static void selectSourceSink(ConstSource<Source> &&, Sink && sink, const Sources & sources)
template <typename Source>
static void selectImpl(ConstSource<Source> && source, const Sources & sources, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
concat<SourceType, Sink>(sources, sink);
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
concat<SourceType, Sink>(sources, std::move(sink));
}
template <typename Source, typename Sink>
static void selectSourceSink(ConstSource<Source> &, Sink && sink, const Sources & sources)
template <typename Source>
static void selectImpl(ConstSource<Source> & source, const Sources & sources, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
concat<SourceType, Sink>(sources, sink);
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
concat<SourceType, Sink>(sources, std::move(sink));
}
};
void concat(const std::vector<std::unique_ptr<IArraySource>> & sources, IArraySink & sink)
ColumnArray::MutablePtr concat(const std::vector<std::unique_ptr<IArraySource>> & sources)
{
if (sources.empty())
throw Exception("Concat function should get at least 1 ArraySource", ErrorCodes::LOGICAL_ERROR);
return ArrayConcat::select(*sources.front(), sink, sources);
ColumnArray::MutablePtr res;
ArrayConcat::select(*sources.front(), sources, res);
return res;
}
}

View File

@ -13,40 +13,44 @@ struct ArraySinkCreator;
template <typename Type, typename... Types>
struct ArraySinkCreator<Type, Types...>
{
static std::unique_ptr<IArraySink> create(ColumnArray & col, NullMap * null_map, size_t column_size)
static std::unique_ptr<IArraySink> create(IColumn & values, ColumnArray::Offsets & offsets, size_t column_size)
{
using ColVecType = std::conditional_t<IsDecimalNumber<Type>, ColumnDecimal<Type>, ColumnVector<Type>>;
if (typeid_cast<ColVecType *>(&col.getData()))
IColumn * not_null_values = &values;
bool is_nullable = false;
if (auto * nullable = typeid_cast<ColumnNullable *>(&values))
{
if (null_map)
return std::make_unique<NullableArraySink<NumericArraySink<Type>>>(col, *null_map, column_size);
return std::make_unique<NumericArraySink<Type>>(col, column_size);
not_null_values = &nullable->getNestedColumn();
is_nullable = true;
}
return ArraySinkCreator<Types...>::create(col, null_map, column_size);
if (typeid_cast<ColVecType *>(not_null_values))
{
if (is_nullable)
return std::make_unique<NullableArraySink<NumericArraySink<Type>>>(values, offsets, column_size);
return std::make_unique<NumericArraySink<Type>>(values, offsets, column_size);
}
return ArraySinkCreator<Types...>::create(values, offsets, column_size);
}
};
template <>
struct ArraySinkCreator<>
{
static std::unique_ptr<IArraySink> create(ColumnArray & col, NullMap * null_map, size_t column_size)
static std::unique_ptr<IArraySink> create(IColumn & values, ColumnArray::Offsets & offsets, size_t column_size)
{
if (null_map)
return std::make_unique<NullableArraySink<GenericArraySink>>(col, *null_map, column_size);
return std::make_unique<GenericArraySink>(col, column_size);
if (typeid_cast<ColumnNullable *>(&values))
return std::make_unique<NullableArraySink<GenericArraySink>>(values, offsets, column_size);
return std::make_unique<GenericArraySink>(values, offsets, column_size);
}
};
std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size)
{
using Creator = ApplyTypeListForClass<ArraySinkCreator, TypeListNumbersAndUInt128>::Type;
if (auto * column_nullable = typeid_cast<ColumnNullable *>(&col.getData()))
{
auto column = ColumnArray::create(column_nullable->getNestedColumnPtr()->assumeMutable(), col.getOffsetsPtr()->assumeMutable());
return Creator::create(*column, &column_nullable->getNullMapData(), column_size);
}
return Creator::create(col, nullptr, column_size);
return Creator::create(col.getData(), col.getOffsets(), column_size);
}
}

View File

@ -1,35 +0,0 @@
#include "GatherUtils.h"
#include "Selectors.h"
#include "Algorithms.h"
namespace DB::GatherUtils
{
struct ArrayHasSelectArraySourcePair : public ArraySourcePairSelector<ArrayHasSelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
static void selectSourcePair(FirstSource && first, SecondSource && second, ArraySearchType search_type, ColumnUInt8 & result)
{
switch (search_type)
{
case ArraySearchType::All:
arrayAllAny<ArraySearchType::All>(first, second, result);
break;
case ArraySearchType::Any:
arrayAllAny<ArraySearchType::Any>(first, second, result);
break;
case ArraySearchType::Substr:
arrayAllAny<ArraySearchType::Substr>(first, second, result);
break;
}
}
};
void sliceHas(IArraySource & first, IArraySource & second, ArraySearchType search_type, ColumnUInt8 & result)
{
ArrayHasSelectArraySourcePair::select(first, second, search_type, result);
}
}

View File

@ -0,0 +1,23 @@
#include "GatherUtils.h"
#include "Selectors.h"
#include "Algorithms.h"
namespace DB::GatherUtils
{
struct ArrayHasAllSelectArraySourcePair : public ArraySourcePairSelector<ArrayHasAllSelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
static void selectSourcePair(FirstSource && first, SecondSource && second, ColumnUInt8 & result)
{
arrayAllAny<ArraySearchType::All>(first, second, result);
}
};
void sliceHasAll(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{
ArrayHasAllSelectArraySourcePair::select(first, second, result);
}
}

View File

@ -0,0 +1,23 @@
#include "GatherUtils.h"
#include "Selectors.h"
#include "Algorithms.h"
namespace DB::GatherUtils
{
struct ArrayHasAnySelectArraySourcePair : public ArraySourcePairSelector<ArrayHasAnySelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
static void selectSourcePair(FirstSource && first, SecondSource && second, ColumnUInt8 & result)
{
arrayAllAny<ArraySearchType::Any>(first, second, result);
}
};
void sliceHasAny(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{
ArrayHasAnySelectArraySourcePair::select(first, second, result);
}
}

View File

@ -0,0 +1,23 @@
#include "GatherUtils.h"
#include "Selectors.h"
#include "Algorithms.h"
namespace DB::GatherUtils
{
struct ArrayHasSubstrSelectArraySourcePair : public ArraySourcePairSelector<ArrayHasSubstrSelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
static void selectSourcePair(FirstSource && first, SecondSource && second, ColumnUInt8 & result)
{
arrayAllAny<ArraySearchType::Substr>(first, second, result);
}
};
void sliceHasSubstr(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{
ArrayHasSubstrSelectArraySourcePair::select(first, second, result);
}
}

View File

@ -6,18 +6,24 @@
namespace DB::GatherUtils
{
struct SliceDynamicOffsetBoundedSelectArraySource : public ArraySinkSourceSelector<SliceDynamicOffsetBoundedSelectArraySource>
struct SliceDynamicOffsetBoundedSelectArraySource : public ArraySourceSelector<SliceDynamicOffsetBoundedSelectArraySource>
{
template <typename Source, typename Sink>
static void selectSourceSink(Source && source, Sink && sink, const IColumn & offset_column, const IColumn & length_column)
template <typename Source>
static void selectImpl(Source && source, const IColumn & offset_column, const IColumn & length_column, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
sliceDynamicOffsetBounded(source, sink, offset_column, length_column);
}
};
void sliceDynamicOffsetBounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column, const IColumn & length_column)
ColumnArray::MutablePtr sliceDynamicOffsetBounded(IArraySource & src, const IColumn & offset_column, const IColumn & length_column)
{
SliceDynamicOffsetBoundedSelectArraySource::select(src, sink, offset_column, length_column);
ColumnArray::MutablePtr res;
SliceDynamicOffsetBoundedSelectArraySource::select(src, offset_column, length_column, res);
return res;
}
}

View File

@ -6,19 +6,25 @@
namespace DB::GatherUtils
{
struct SliceDynamicOffsetUnboundedSelectArraySource : public ArraySinkSourceSelector<SliceDynamicOffsetUnboundedSelectArraySource>
struct SliceDynamicOffsetUnboundedSelectArraySource : public ArraySourceSelector<SliceDynamicOffsetUnboundedSelectArraySource>
{
template <typename Source, typename Sink>
static void selectSourceSink(Source && source, Sink && sink, const IColumn & offset_column)
template <typename Source>
static void selectImpl(Source && source, const IColumn & offset_column, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
sliceDynamicOffsetUnbounded(source, sink, offset_column);
}
};
void sliceDynamicOffsetUnbounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column)
ColumnArray::MutablePtr sliceDynamicOffsetUnbounded(IArraySource & src, const IColumn & offset_column)
{
SliceDynamicOffsetUnboundedSelectArraySource::select(src, sink, offset_column);
ColumnArray::MutablePtr res;
SliceDynamicOffsetUnboundedSelectArraySource::select(src, offset_column, res);
return res;
}
}

View File

@ -7,18 +7,24 @@
namespace DB::GatherUtils
{
struct SliceFromLeftConstantOffsetBoundedSelectArraySource
: public ArraySinkSourceSelector<SliceFromLeftConstantOffsetBoundedSelectArraySource>
: public ArraySourceSelector<SliceFromLeftConstantOffsetBoundedSelectArraySource>
{
template <typename Source, typename Sink>
static void selectSourceSink(Source && source, Sink && sink, size_t & offset, ssize_t & length)
template <typename Source>
static void selectImpl(Source && source, size_t & offset, ssize_t & length, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
sliceFromLeftConstantOffsetBounded(source, sink, offset, length);
}
};
void sliceFromLeftConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length)
ColumnArray::MutablePtr sliceFromLeftConstantOffsetBounded(IArraySource & src, size_t offset, ssize_t length)
{
SliceFromLeftConstantOffsetBoundedSelectArraySource::select(src, sink, offset, length);
ColumnArray::MutablePtr res;
SliceFromLeftConstantOffsetBoundedSelectArraySource::select(src, offset, length, res);
return res;
}
}

View File

@ -7,18 +7,24 @@
namespace DB::GatherUtils
{
struct SliceFromLeftConstantOffsetUnboundedSelectArraySource
: public ArraySinkSourceSelector<SliceFromLeftConstantOffsetUnboundedSelectArraySource>
: public ArraySourceSelector<SliceFromLeftConstantOffsetUnboundedSelectArraySource>
{
template <typename Source, typename Sink>
static void selectSourceSink(Source && source, Sink && sink, size_t & offset)
template <typename Source>
static void selectImpl(Source && source, size_t & offset, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
sliceFromLeftConstantOffsetUnbounded(source, sink, offset);
}
};
void sliceFromLeftConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset)
ColumnArray::MutablePtr sliceFromLeftConstantOffsetUnbounded(IArraySource & src, size_t offset)
{
SliceFromLeftConstantOffsetUnboundedSelectArraySource::select(src, sink, offset);
ColumnArray::MutablePtr res;
SliceFromLeftConstantOffsetUnboundedSelectArraySource::select(src, offset, res);
return res;
}
}

View File

@ -7,18 +7,24 @@
namespace DB::GatherUtils
{
struct SliceFromRightConstantOffsetBoundedSelectArraySource
: public ArraySinkSourceSelector<SliceFromRightConstantOffsetBoundedSelectArraySource>
: public ArraySourceSelector<SliceFromRightConstantOffsetBoundedSelectArraySource>
{
template <typename Source, typename Sink>
static void selectSourceSink(Source && source, Sink && sink, size_t & offset, ssize_t & length)
template <typename Source>
static void selectImpl(Source && source, size_t & offset, ssize_t & length, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
sliceFromRightConstantOffsetBounded(source, sink, offset, length);
}
};
void sliceFromRightConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length)
ColumnArray::MutablePtr sliceFromRightConstantOffsetBounded(IArraySource & src, size_t offset, ssize_t length)
{
SliceFromRightConstantOffsetBoundedSelectArraySource::select(src, sink, offset, length);
ColumnArray::MutablePtr res;
SliceFromRightConstantOffsetBoundedSelectArraySource::select(src, offset, length, res);
return res;
}
}

View File

@ -7,18 +7,24 @@
namespace DB::GatherUtils
{
struct SliceFromRightConstantOffsetUnboundedSelectArraySource
: public ArraySinkSourceSelector<SliceFromRightConstantOffsetUnboundedSelectArraySource>
: public ArraySourceSelector<SliceFromRightConstantOffsetUnboundedSelectArraySource>
{
template <typename Source, typename Sink>
static void selectSourceSink(Source && source, Sink && sink, size_t & offset)
template <typename Source>
static void selectImpl(Source && source, size_t & offset, ColumnArray::MutablePtr & result)
{
using SourceType = typename std::decay<Source>::type;
using Sink = typename SourceType::SinkType;
result = ColumnArray::create(source.createValuesColumn());
Sink sink(result->getData(), result->getOffsets(), source.getColumnSize());
sliceFromRightConstantOffsetUnbounded(source, sink, offset);
}
};
void sliceFromRightConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset)
ColumnArray::MutablePtr sliceFromRightConstantOffsetUnbounded(IArraySource & src, size_t offset)
{
SliceFromRightConstantOffsetUnboundedSelectArraySource::select(src, sink, offset);
ColumnArray::MutablePtr res;
SliceFromRightConstantOffsetUnboundedSelectArraySource::select(src, offset, res);
return res;
}
}

View File

@ -59,8 +59,6 @@ public:
return;
}
auto result_column = return_type->createColumn();
size_t rows = input_rows_count;
size_t num_args = arguments.size();
@ -95,10 +93,9 @@ public:
throw Exception{"Arguments for function " + getName() + " must be arrays.", ErrorCodes::LOGICAL_ERROR};
}
auto sink = GatherUtils::createArraySink(typeid_cast<ColumnArray &>(*result_column), rows);
GatherUtils::concat(sources, *sink);
auto sink = GatherUtils::concat(sources);
block.getByPosition(result).column = std::move(result_column);
block.getByPosition(result).column = std::move(sink);
}
bool useDefaultImplementationForConstants() const override { return true; }

View File

@ -48,8 +48,6 @@ public:
return;
}
auto result_column = return_type->createColumn();
const auto & array_column = block.getByPosition(arguments[0]).column;
std::unique_ptr<GatherUtils::IArraySource> source;
@ -61,14 +59,14 @@ public:
else
throw Exception{"First arguments for function " + getName() + " must be array.", ErrorCodes::LOGICAL_ERROR};
auto sink = GatherUtils::createArraySink(typeid_cast<ColumnArray &>(*result_column), size);
ColumnArray::MutablePtr sink;
if (pop_front)
GatherUtils::sliceFromLeftConstantOffsetUnbounded(*source, *sink, 1);
sink = GatherUtils::sliceFromLeftConstantOffsetUnbounded(*source, 1);
else
GatherUtils::sliceFromLeftConstantOffsetBounded(*source, *sink, 0, -1);
sink = GatherUtils::sliceFromLeftConstantOffsetBounded(*source, 0, -1);
block.getByPosition(result).column = std::move(result_column);
block.getByPosition(result).column = std::move(sink);
}
bool useDefaultImplementationForConstants() const override { return true; }

View File

@ -79,8 +79,6 @@ public:
return;
}
auto result_column = return_type->createColumn();
auto & array_column = block.getByPosition(arguments[0]).column;
const auto & offset_column = block.getByPosition(arguments[1]).column;
const auto & length_column = arguments.size() > 2 ? block.getByPosition(arguments[2]).column : nullptr;
@ -101,7 +99,7 @@ public:
else
throw Exception{"First arguments for function " + getName() + " must be array.", ErrorCodes::LOGICAL_ERROR};
auto sink = GatherUtils::createArraySink(typeid_cast<ColumnArray &>(*result_column), size);
ColumnArray::MutablePtr sink;
if (offset_column->onlyNull())
{
@ -111,11 +109,11 @@ public:
return;
}
else if (isColumnConst(*length_column))
GatherUtils::sliceFromLeftConstantOffsetBounded(*source, *sink, 0, length_column->getInt(0));
sink = GatherUtils::sliceFromLeftConstantOffsetBounded(*source, 0, length_column->getInt(0));
else
{
auto const_offset_column = ColumnConst::create(ColumnInt8::create(1, 1), size);
GatherUtils::sliceDynamicOffsetBounded(*source, *sink, *const_offset_column, *length_column);
sink = GatherUtils::sliceDynamicOffsetBounded(*source, *const_offset_column, *length_column);
}
}
else if (isColumnConst(*offset_column))
@ -125,30 +123,30 @@ public:
if (!length_column || length_column->onlyNull())
{
if (offset > 0)
GatherUtils::sliceFromLeftConstantOffsetUnbounded(*source, *sink, static_cast<size_t>(offset - 1));
sink = GatherUtils::sliceFromLeftConstantOffsetUnbounded(*source, static_cast<size_t>(offset - 1));
else
GatherUtils::sliceFromRightConstantOffsetUnbounded(*source, *sink, static_cast<size_t>(-offset));
sink = GatherUtils::sliceFromRightConstantOffsetUnbounded(*source, static_cast<size_t>(-offset));
}
else if (isColumnConst(*length_column))
{
ssize_t length = length_column->getInt(0);
if (offset > 0)
GatherUtils::sliceFromLeftConstantOffsetBounded(*source, *sink, static_cast<size_t>(offset - 1), length);
sink = GatherUtils::sliceFromLeftConstantOffsetBounded(*source, static_cast<size_t>(offset - 1), length);
else
GatherUtils::sliceFromRightConstantOffsetBounded(*source, *sink, static_cast<size_t>(-offset), length);
sink = GatherUtils::sliceFromRightConstantOffsetBounded(*source, static_cast<size_t>(-offset), length);
}
else
GatherUtils::sliceDynamicOffsetBounded(*source, *sink, *offset_column, *length_column);
sink = GatherUtils::sliceDynamicOffsetBounded(*source, *offset_column, *length_column);
}
else
{
if (!length_column || length_column->onlyNull())
GatherUtils::sliceDynamicOffsetUnbounded(*source, *sink, *offset_column);
sink = GatherUtils::sliceDynamicOffsetUnbounded(*source, *offset_column);
else
GatherUtils::sliceDynamicOffsetBounded(*source, *sink, *offset_column, *length_column);
sink = GatherUtils::sliceDynamicOffsetBounded(*source, *offset_column, *length_column);
}
block.getByPosition(result).column = std::move(result_column);
block.getByPosition(result).column = std::move(sink);
}
bool useDefaultImplementationForConstants() const override { return true; }

View File

@ -272,11 +272,12 @@ private:
return false;
auto res = block.getByPosition(result).type->createColumn();
auto & arr_res = assert_cast<ColumnArray &>(*res);
conditional(
NumericArraySource<T0>(*col_left_array),
NumericArraySource<T1>(*col_right_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
NumericArraySink<ResultType>(arr_res.getData(), arr_res.getOffsets(), input_rows_count),
cond_col->getData());
block.getByPosition(result).column = std::move(res);
@ -289,11 +290,12 @@ private:
return false;
auto res = block.getByPosition(result).type->createColumn();
auto & arr_res = assert_cast<ColumnArray &>(*res);
conditional(
NumericArraySource<T0>(*col_left_array),
ConstSource<NumericArraySource<T1>>(*col_right_const_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
NumericArraySink<ResultType>(arr_res.getData(), arr_res.getOffsets(), input_rows_count),
cond_col->getData());
block.getByPosition(result).column = std::move(res);
@ -329,11 +331,12 @@ private:
return false;
auto res = block.getByPosition(result).type->createColumn();
auto & arr_res = assert_cast<ColumnArray &>(*res);
conditional(
ConstSource<NumericArraySource<T0>>(*col_left_const_array),
NumericArraySource<T1>(*col_right_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
NumericArraySink<ResultType>(arr_res.getData(), arr_res.getOffsets(), input_rows_count),
cond_col->getData());
block.getByPosition(result).column = std::move(res);
@ -346,11 +349,12 @@ private:
return false;
auto res = block.getByPosition(result).type->createColumn();
auto & arr_res = assert_cast<ColumnArray &>(*res);
conditional(
ConstSource<NumericArraySource<T0>>(*col_left_const_array),
ConstSource<NumericArraySource<T1>>(*col_right_const_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
NumericArraySink<ResultType>(arr_res.getData(), arr_res.getOffsets(), input_rows_count),
cond_col->getData());
block.getByPosition(result).column = std::move(res);
@ -527,13 +531,13 @@ private:
auto * col_res = assert_cast<ColumnArray *>(res.get());
if (col_arr_then && col_arr_else)
conditional(GenericArraySource(*col_arr_then), GenericArraySource(*col_arr_else), GenericArraySink(*col_res, rows), cond_data);
conditional(GenericArraySource(*col_arr_then), GenericArraySource(*col_arr_else), GenericArraySink(col_res->getData(), col_res->getOffsets(), rows), cond_data);
else if (col_arr_then && col_arr_else_const)
conditional(GenericArraySource(*col_arr_then), ConstSource<GenericArraySource>(*col_arr_else_const), GenericArraySink(*col_res, rows), cond_data);
conditional(GenericArraySource(*col_arr_then), ConstSource<GenericArraySource>(*col_arr_else_const), GenericArraySink(col_res->getData(), col_res->getOffsets(), rows), cond_data);
else if (col_arr_then_const && col_arr_else)
conditional(ConstSource<GenericArraySource>(*col_arr_then_const), GenericArraySource(*col_arr_else), GenericArraySink(*col_res, rows), cond_data);
conditional(ConstSource<GenericArraySource>(*col_arr_then_const), GenericArraySource(*col_arr_else), GenericArraySink(col_res->getData(), col_res->getOffsets(), rows), cond_data);
else if (col_arr_then_const && col_arr_else_const)
conditional(ConstSource<GenericArraySource>(*col_arr_then_const), ConstSource<GenericArraySource>(*col_arr_else_const), GenericArraySink(*col_res, rows), cond_data);
conditional(ConstSource<GenericArraySource>(*col_arr_then_const), ConstSource<GenericArraySource>(*col_arr_else_const), GenericArraySink(col_res->getData(), col_res->getOffsets(), rows), cond_data);
else
return false;

View File

@ -190,7 +190,9 @@ SRCS(
GatherUtils/createArraySink.cpp
GatherUtils/createArraySource.cpp
GatherUtils/createValueSource.cpp
GatherUtils/has.cpp
GatherUtils/has_all.cpp
GatherUtils/has_any.cpp
GatherUtils/has_substr.cpp
GatherUtils/push.cpp
GatherUtils/resizeConstantSize.cpp
GatherUtils/resizeDynamicSize.cpp