Merge pull request #14813 from ClickHouse/inline-gather-utils

Inline gather utils
This commit is contained in:
Nikolai Kochetov 2020-09-17 14:44:25 +03:00 committed by GitHub
commit daf6e0aa84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 153 additions and 12 deletions

View File

@ -66,7 +66,8 @@ class Visitor<>
public:
using List = TypeList<>;
virtual ~Visitor() = default;
protected:
~Visitor() = default;
};
template <typename Type>
@ -76,6 +77,9 @@ public:
using List = TypeList<Type>;
virtual void visit(Type &) = 0;
protected:
~Visitor() = default;
};
template <typename Type, typename ... Types>
@ -86,6 +90,9 @@ public:
using Visitor<Types ...>::visit;
virtual void visit(Type &) = 0;
protected:
~Visitor() = default;
};
@ -95,6 +102,8 @@ class VisitorImplHelper;
template <typename Derived, typename VisitorBase>
class VisitorImplHelper<Derived, VisitorBase> : public VisitorBase
{
protected:
~VisitorImplHelper() = default;
};
template <typename Derived, typename VisitorBase, typename Type>
@ -111,6 +120,8 @@ protected:
throw Exception("visitImpl(" + demangle(typeid(T).name()) + " &)" + " is not implemented for class"
+ demangle(typeid(Derived).name()), ErrorCodes::LOGICAL_ERROR);
}
~VisitorImplHelper() = default;
};
template <typename Derived, typename VisitorBase, typename Type, typename ... Types>
@ -128,6 +139,8 @@ protected:
throw Exception("visitImpl(" + demangle(typeid(T).name()) + " &)" + " is not implemented for class"
+ demangle(typeid(Derived).name()), ErrorCodes::LOGICAL_ERROR);
}
~VisitorImplHelper() = default;
};
template <typename Derived, typename VisitorBase>
@ -140,6 +153,8 @@ class VisitorImpl : public
>::Type
>::Type
{
protected:
~VisitorImpl() = default;
};
template <typename Derived, typename Base, typename Visitor>
@ -147,6 +162,8 @@ class Visitable : public Base
{
public:
void accept(Visitor & visitor) override { visitor.visit(*static_cast<Derived *>(this)); }
//virtual ~Visitable() = default;
};
}

View File

@ -21,6 +21,7 @@ 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

@ -4,6 +4,7 @@
namespace DB::GatherUtils
{
#pragma GCC visibility push(hidden)
template <typename T>
struct NumericArraySink;
@ -18,9 +19,18 @@ using BasicArraySinks = typename AppendToTypeList<GenericArraySink, NumericArray
using NullableArraySinks = typename TypeListMap<NullableArraySink, BasicArraySinks>::Type;
using TypeListArraySinks = typename TypeListConcat<BasicArraySinks, NullableArraySinks>::Type;
class ArraySinkVisitor : public ApplyTypeListForClass<Visitor, TypeListArraySinks>::Type {};
class ArraySinkVisitor : public ApplyTypeListForClass<Visitor, TypeListArraySinks>::Type
{
protected:
~ArraySinkVisitor() = default;
};
template <typename Derived>
class ArraySinkVisitorImpl : public VisitorImpl<Derived, ArraySinkVisitor> {};
class ArraySinkVisitorImpl : public VisitorImpl<Derived, ArraySinkVisitor>
{
protected:
~ArraySinkVisitorImpl() = default;
};
#pragma GCC visibility pop
}

View File

@ -4,6 +4,7 @@
namespace DB::GatherUtils
{
#pragma GCC visibility push(hidden)
template <typename T>
struct NumericArraySource;
@ -23,9 +24,18 @@ using BasicAndNullableArraySources = typename TypeListConcat<BasicArraySources,
using ConstArraySources = typename TypeListMap<ConstSource, BasicAndNullableArraySources>::Type;
using TypeListArraySources = typename TypeListConcat<BasicAndNullableArraySources, ConstArraySources>::Type;
class ArraySourceVisitor : public ApplyTypeListForClass<Visitor, TypeListArraySources>::Type {};
class ArraySourceVisitor : public ApplyTypeListForClass<Visitor, TypeListArraySources>::Type
{
protected:
~ArraySourceVisitor() = default;
};
template <typename Derived>
class ArraySourceVisitorImpl : public VisitorImpl<Derived, ArraySourceVisitor> {};
class ArraySourceVisitorImpl : public VisitorImpl<Derived, ArraySourceVisitor>
{
protected:
~ArraySourceVisitorImpl() = default;
};
#pragma GCC visibility pop
}

View File

@ -13,6 +13,7 @@ namespace ErrorCodes
namespace GatherUtils
{
#pragma GCC visibility push(hidden)
struct IArraySink
{
@ -27,6 +28,7 @@ struct IArraySink
template <typename Derived>
class ArraySinkImpl : public Visitable<Derived, IArraySink, ArraySinkVisitor> {};
#pragma GCC visibility pop
}
}

View File

@ -13,6 +13,7 @@ namespace ErrorCodes
namespace GatherUtils
{
#pragma GCC visibility push(hidden)
struct IArraySource
{
@ -33,6 +34,7 @@ struct IArraySource
template <typename Derived>
class ArraySourceImpl : public Visitable<Derived, IArraySource, ArraySourceVisitor> {};
#pragma GCC visibility pop
}
}

View File

@ -13,6 +13,7 @@ namespace ErrorCodes
namespace GatherUtils
{
#pragma GCC visibility push(hidden)
struct IValueSource
{
@ -29,6 +30,7 @@ struct IValueSource
template <typename Derived>
class ValueSourceImpl : public Visitable<Derived, IValueSource, ValueSourceVisitor> {};
#pragma GCC visibility pop
}
}

View File

@ -17,6 +17,7 @@ namespace ErrorCodes
namespace GatherUtils
{
#pragma GCC visibility push(hidden)
/// Base classes which selects template function implementation with concrete ArraySource or ArraySink
/// Derived classes should implement selectImpl for ArraySourceSelector and ArraySinkSelector,
@ -32,7 +33,7 @@ void callSelectMemberFunctionWithTupleArgument(Tuple & tuple, Args && ... args)
}
template <typename Base, typename ... Args>
struct ArraySourceSelectorVisitor : public ArraySourceVisitorImpl<ArraySourceSelectorVisitor<Base, Args ...>>
struct ArraySourceSelectorVisitor final : public ArraySourceVisitorImpl<ArraySourceSelectorVisitor<Base, Args ...>>
{
explicit ArraySourceSelectorVisitor(Args && ... args) : packed_args(args ...) {}
@ -60,7 +61,7 @@ struct ArraySourceSelector
template <typename Base, typename ... Args>
struct ArraySinkSelectorVisitor : public ArraySinkVisitorImpl<ArraySinkSelectorVisitor<Base, Args ...>>
struct ArraySinkSelectorVisitor final : public ArraySinkVisitorImpl<ArraySinkSelectorVisitor<Base, Args ...>>
{
explicit ArraySinkSelectorVisitor(Args && ... args) : packed_args(args ...) {}
@ -88,7 +89,7 @@ struct ArraySinkSelector
template <typename Base, typename ... Args>
struct ValueSourceSelectorVisitor : public ValueSourceVisitorImpl<ValueSourceSelectorVisitor<Base, Args ...>>
struct ValueSourceSelectorVisitor final : public ValueSourceVisitorImpl<ValueSourceSelectorVisitor<Base, Args ...>>
{
explicit ValueSourceSelectorVisitor(Args && ... args) : packed_args(args ...) {}
@ -201,6 +202,7 @@ struct ArrayAndValueSourceSelectorBySink : public ArraySinkSelector<ArrayAndValu
}
};
#pragma GCC visibility pop
}
}

View File

@ -15,6 +15,7 @@
namespace DB::GatherUtils
{
#pragma GCC visibility push(hidden)
template <typename T>
struct NumericArraySource;
@ -214,5 +215,5 @@ struct NullableArraySink : public ArraySink
}
};
#pragma GCC visibility pop
}

View File

@ -4,6 +4,7 @@
namespace DB::GatherUtils
{
#pragma GCC visibility push(hidden)
template <typename T>
struct NumericArraySlice
@ -42,5 +43,6 @@ struct GenericValueSlice
static constexpr size_t size = 1;
};
#pragma GCC visibility pop
}

View File

@ -28,6 +28,7 @@ namespace ErrorCodes
namespace GatherUtils
{
#pragma GCC visibility push(hidden)
template <typename T> struct NumericArraySink;
struct StringSink;
@ -819,4 +820,5 @@ struct NullableValueSource : public ValueSource
}
#pragma GCC visibility pop
}

View File

@ -4,6 +4,7 @@
namespace DB::GatherUtils
{
#pragma GCC visibility push(hidden)
template <typename T>
struct NumericValueSource;
@ -23,9 +24,18 @@ using BasicAndNullableValueSources = typename TypeListConcat<BasicValueSources,
using ConstValueSources = typename TypeListMap<ConstSource, BasicAndNullableValueSources>::Type;
using TypeListValueSources = typename TypeListConcat<BasicAndNullableValueSources, ConstValueSources>::Type;
class ValueSourceVisitor : public ApplyTypeListForClass<Visitor, TypeListValueSources>::Type {};
class ValueSourceVisitor : public ApplyTypeListForClass<Visitor, TypeListValueSources>::Type
{
protected:
~ValueSourceVisitor() = default;
};
template <typename Derived>
class ValueSourceVisitorImpl : public VisitorImpl<Derived, ValueSourceVisitor> {};
class ValueSourceVisitorImpl : public VisitorImpl<Derived, ValueSourceVisitor>
{
protected:
~ValueSourceVisitorImpl() = default;
};
#pragma GCC visibility pop
}

View File

@ -16,6 +16,9 @@ namespace ErrorCodes
namespace GatherUtils
{
namespace
{
struct ArrayConcat : public ArraySourceSelector<ArrayConcat>
{
using Sources = std::vector<std::unique_ptr<IArraySource>>;
@ -54,6 +57,8 @@ struct ArrayConcat : public ArraySourceSelector<ArrayConcat>
}
};
}
ColumnArray::MutablePtr concat(const std::vector<std::unique_ptr<IArraySource>> & sources)
{
if (sources.empty())

View File

@ -7,6 +7,9 @@ namespace DB::GatherUtils
{
/// Creates IArraySink from ColumnArray
namespace
{
template <typename... Types>
struct ArraySinkCreator;
@ -48,6 +51,8 @@ struct ArraySinkCreator<>
}
};
}
std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size)
{
using Creator = ApplyTypeListForClass<ArraySinkCreator, TypeListNumbersAndUInt128>::Type;

View File

@ -7,6 +7,9 @@ namespace DB::GatherUtils
{
/// Creates IArraySource from ColumnArray
namespace
{
template <typename... Types>
struct ArraySourceCreator;
@ -51,6 +54,8 @@ struct ArraySourceCreator<>
}
};
}
std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is_const, size_t total_rows)
{
using Creator = typename ApplyTypeListForClass<ArraySourceCreator, TypeListNumbersAndUInt128>::Type;

View File

@ -7,6 +7,9 @@ namespace DB::GatherUtils
{
/// Creates IValueSource from Column
namespace
{
template <typename... Types>
struct ValueSourceCreator;
@ -51,6 +54,8 @@ struct ValueSourceCreator<>
}
};
}
std::unique_ptr<IValueSource> createValueSource(const IColumn & col, bool is_const, size_t total_rows)
{
using Creator = typename ApplyTypeListForClass<ValueSourceCreator, TypeListNumbersAndUInt128>::Type;

View File

@ -5,6 +5,9 @@
namespace DB::GatherUtils
{
namespace
{
struct ArrayHasAllSelectArraySourcePair : public ArraySourcePairSelector<ArrayHasAllSelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
@ -14,6 +17,7 @@ struct ArrayHasAllSelectArraySourcePair : public ArraySourcePairSelector<ArrayHa
}
};
}
void sliceHasAll(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{

View File

@ -5,6 +5,9 @@
namespace DB::GatherUtils
{
namespace
{
struct ArrayHasAnySelectArraySourcePair : public ArraySourcePairSelector<ArrayHasAnySelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
@ -14,6 +17,7 @@ struct ArrayHasAnySelectArraySourcePair : public ArraySourcePairSelector<ArrayHa
}
};
}
void sliceHasAny(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{

View File

@ -5,6 +5,9 @@
namespace DB::GatherUtils
{
namespace
{
struct ArrayHasSubstrSelectArraySourcePair : public ArraySourcePairSelector<ArrayHasSubstrSelectArraySourcePair>
{
template <typename FirstSource, typename SecondSource>
@ -14,6 +17,7 @@ struct ArrayHasSubstrSelectArraySourcePair : public ArraySourcePairSelector<Arra
}
};
}
void sliceHasSubstr(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{

View File

@ -5,6 +5,9 @@
namespace DB::GatherUtils
{
namespace
{
struct ArrayPush : public ArrayAndValueSourceSelectorBySink<ArrayPush>
{
template <typename ArraySource, typename ValueSource, typename Sink>
@ -18,6 +21,7 @@ struct ArrayPush : public ArrayAndValueSourceSelectorBySink<ArrayPush>
}
};
}
void push(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, bool push_front)
{

View File

@ -7,6 +7,9 @@
namespace DB::GatherUtils
{
namespace
{
struct ArrayResizeConstant : public ArrayAndValueSourceSelectorBySink<ArrayResizeConstant>
{
template <typename ArraySource, typename ValueSource, typename Sink>
@ -17,6 +20,7 @@ struct ArrayResizeConstant : public ArrayAndValueSourceSelectorBySink<ArrayResiz
}
};
}
void resizeConstantSize(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, ssize_t size)
{

View File

@ -7,6 +7,9 @@
namespace DB::GatherUtils
{
namespace
{
struct ArrayResizeDynamic : public ArrayAndValueSourceSelectorBySink<ArrayResizeDynamic>
{
template <typename ArraySource, typename ValueSource, typename Sink>
@ -17,6 +20,7 @@ struct ArrayResizeDynamic : public ArrayAndValueSourceSelectorBySink<ArrayResize
}
};
}
void resizeDynamicSize(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, const IColumn & size_column)
{

View File

@ -6,6 +6,10 @@
namespace DB::GatherUtils
{
namespace
{
struct SliceDynamicOffsetBoundedSelectArraySource : public ArraySourceSelector<SliceDynamicOffsetBoundedSelectArraySource>
{
template <typename Source>
@ -19,6 +23,8 @@ struct SliceDynamicOffsetBoundedSelectArraySource : public ArraySourceSelector<S
}
};
}
ColumnArray::MutablePtr sliceDynamicOffsetBounded(IArraySource & src, const IColumn & offset_column, const IColumn & length_column)
{
ColumnArray::MutablePtr res;

View File

@ -6,7 +6,12 @@
namespace DB::GatherUtils
{
struct SliceDynamicOffsetUnboundedSelectArraySource : public ArraySourceSelector<SliceDynamicOffsetUnboundedSelectArraySource>
namespace
{
struct SliceDynamicOffsetUnboundedSelectArraySource
: public ArraySourceSelector<SliceDynamicOffsetUnboundedSelectArraySource>
{
template <typename Source>
static void selectImpl(Source && source, const IColumn & offset_column, ColumnArray::MutablePtr & result)
@ -19,6 +24,7 @@ struct SliceDynamicOffsetUnboundedSelectArraySource : public ArraySourceSelector
}
};
}
ColumnArray::MutablePtr sliceDynamicOffsetUnbounded(IArraySource & src, const IColumn & offset_column)
{

View File

@ -6,6 +6,10 @@
namespace DB::GatherUtils
{
namespace
{
struct SliceFromLeftConstantOffsetBoundedSelectArraySource
: public ArraySourceSelector<SliceFromLeftConstantOffsetBoundedSelectArraySource>
{
@ -20,6 +24,8 @@ struct SliceFromLeftConstantOffsetBoundedSelectArraySource
}
};
}
ColumnArray::MutablePtr sliceFromLeftConstantOffsetBounded(IArraySource & src, size_t offset, ssize_t length)
{
ColumnArray::MutablePtr res;

View File

@ -6,6 +6,10 @@
namespace DB::GatherUtils
{
namespace
{
struct SliceFromLeftConstantOffsetUnboundedSelectArraySource
: public ArraySourceSelector<SliceFromLeftConstantOffsetUnboundedSelectArraySource>
{
@ -20,6 +24,8 @@ struct SliceFromLeftConstantOffsetUnboundedSelectArraySource
}
};
}
ColumnArray::MutablePtr sliceFromLeftConstantOffsetUnbounded(IArraySource & src, size_t offset)
{
ColumnArray::MutablePtr res;

View File

@ -6,6 +6,10 @@
namespace DB::GatherUtils
{
namespace
{
struct SliceFromRightConstantOffsetBoundedSelectArraySource
: public ArraySourceSelector<SliceFromRightConstantOffsetBoundedSelectArraySource>
{
@ -20,6 +24,8 @@ struct SliceFromRightConstantOffsetBoundedSelectArraySource
}
};
}
ColumnArray::MutablePtr sliceFromRightConstantOffsetBounded(IArraySource & src, size_t offset, ssize_t length)
{
ColumnArray::MutablePtr res;

View File

@ -6,6 +6,10 @@
namespace DB::GatherUtils
{
namespace
{
struct SliceFromRightConstantOffsetUnboundedSelectArraySource
: public ArraySourceSelector<SliceFromRightConstantOffsetUnboundedSelectArraySource>
{
@ -20,6 +24,8 @@ struct SliceFromRightConstantOffsetUnboundedSelectArraySource
}
};
}
ColumnArray::MutablePtr sliceFromRightConstantOffsetUnbounded(IArraySource & src, size_t offset)
{
ColumnArray::MutablePtr res;