mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 10:02:01 +00:00
removed createImmutable
This commit is contained in:
parent
5c91eecb2b
commit
cc2c1f5171
@ -34,7 +34,7 @@ namespace ErrorCodes
|
||||
ColumnArray::ColumnArray(MutableColumnPtr && nested_column, MutableColumnPtr && offsets_column)
|
||||
: data(std::move(nested_column)), offsets(std::move(offsets_column))
|
||||
{
|
||||
if (!typeid_cast<const ColumnOffsets *>(offsets_column.get()))
|
||||
if (!typeid_cast<const ColumnOffsets *>(offsets.get()))
|
||||
throw Exception("offsets_column must be a ColumnUInt64", ErrorCodes::ILLEGAL_COLUMN);
|
||||
|
||||
/** NOTE
|
||||
|
@ -27,23 +27,29 @@ private:
|
||||
ColumnArray(MutableColumnPtr && nested_column, MutableColumnPtr && offsets_column);
|
||||
|
||||
/** Create an empty column of arrays with the type of values as in the column `nested_column` */
|
||||
ColumnArray(MutableColumnPtr && nested_column);
|
||||
|
||||
using Ptr = COWPtrHelper<IColumn, ColumnArray>::Ptr;
|
||||
|
||||
static Ptr createImmutable(const ColumnPtr & nested_column, const ColumnPtr & offsets_column)
|
||||
{
|
||||
return ColumnArray::create(nested_column->assumeMutable(), offsets_column->assumeMutable());
|
||||
}
|
||||
|
||||
static Ptr createImmutable(const ColumnPtr & nested_column)
|
||||
{
|
||||
return ColumnArray::create(nested_column->assumeMutable());
|
||||
}
|
||||
explicit ColumnArray(MutableColumnPtr && nested_column);
|
||||
|
||||
ColumnArray(const ColumnArray &) = default;
|
||||
|
||||
public:
|
||||
/** Create immutable column using immutable arguments. This arguments may be shared with other columns.
|
||||
* Use IColumn::mutate in order to make mutable column and mutate shared nested columns.
|
||||
*/
|
||||
using Base = COWPtrHelper<IColumn, ColumnArray>;
|
||||
|
||||
static Ptr create(const ColumnPtr & nested_column, const ColumnPtr & offsets_column)
|
||||
{
|
||||
return ColumnArray::create(nested_column->assumeMutable(), offsets_column->assumeMutable());
|
||||
}
|
||||
|
||||
static Ptr create(const ColumnPtr & nested_column)
|
||||
{
|
||||
return ColumnArray::create(nested_column->assumeMutable());
|
||||
}
|
||||
|
||||
template <typename ... Args, typename = typename std::enable_if<IsMutableColumns<Args ...>::value>::type>
|
||||
static MutablePtr create(Args &&... args) { return Base::create(std::forward<Args>(args)...); }
|
||||
|
||||
/** On the index i there is an offset to the beginning of the i + 1 -th element. */
|
||||
using ColumnOffsets = ColumnVector<Offset>;
|
||||
|
||||
|
@ -26,14 +26,19 @@ private:
|
||||
ColumnNullable(MutableColumnPtr && nested_column_, MutableColumnPtr && null_map_);
|
||||
ColumnNullable(const ColumnNullable &) = default;
|
||||
|
||||
using Ptr = COWPtrHelper<IColumn, ColumnNullable>::Ptr;
|
||||
|
||||
static Ptr createImmutable(const ColumnPtr & nested_column_, const ColumnPtr & null_map_)
|
||||
public:
|
||||
/** Create immutable column using immutable arguments. This arguments may be shared with other columns.
|
||||
* Use IColumn::mutate in order to make mutable column and mutate shared nested columns.
|
||||
*/
|
||||
using Base = COWPtrHelper<IColumn, ColumnNullable>;
|
||||
static Ptr create(const ColumnPtr & nested_column_, const ColumnPtr & null_map_)
|
||||
{
|
||||
return ColumnNullable::create(nested_column_->assumeMutable(), null_map_->assumeMutable());
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename ... Args, typename = typename std::enable_if<IsMutableColumns<Args ...>::value>::type>
|
||||
static MutablePtr create(Args &&... args) { return Base::create(std::forward<Args>(args)...); }
|
||||
|
||||
const char * getFamilyName() const override { return "Nullable"; }
|
||||
std::string getName() const override { return "Nullable(" + nested_column->getName() + ")"; }
|
||||
MutableColumnPtr cloneResized(size_t size) const override;
|
||||
|
@ -43,7 +43,7 @@ ColumnTuple::ColumnTuple(MutableColumns && mutable_columns)
|
||||
}
|
||||
}
|
||||
|
||||
ColumnTuple::Ptr ColumnTuple::createImmutable(const Columns & columns)
|
||||
ColumnTuple::Ptr ColumnTuple::create(const Columns & columns)
|
||||
{
|
||||
for (const auto & column : columns)
|
||||
if (column->isColumnConst())
|
||||
|
@ -22,12 +22,19 @@ private:
|
||||
template <bool positive>
|
||||
struct Less;
|
||||
|
||||
ColumnTuple(MutableColumns && columns);
|
||||
explicit ColumnTuple(MutableColumns && columns);
|
||||
ColumnTuple(const ColumnTuple &) = default;
|
||||
|
||||
static Ptr createImmutable(const Columns & columns);
|
||||
|
||||
public:
|
||||
/** Create immutable column using immutable arguments. This arguments may be shared with other columns.
|
||||
* Use IColumn::mutate in order to make mutable column and mutate shared nested columns.
|
||||
*/
|
||||
using Base = COWPtrHelper<IColumn, ColumnTuple>;
|
||||
static Ptr create(const Columns & columns);
|
||||
|
||||
template <typename Arg, typename = typename std::enable_if<std::is_rvalue_reference<Arg &&>::value>::type>
|
||||
static MutablePtr create(Arg && arg) { return Base::create(std::forward<Arg>(arg)); }
|
||||
|
||||
std::string getName() const override;
|
||||
const char * getFamilyName() const override { return "Tuple"; }
|
||||
|
||||
|
@ -360,4 +360,16 @@ using MutableColumns = std::vector<MutableColumnPtr>;
|
||||
using ColumnRawPtrs = std::vector<const IColumn *>;
|
||||
//using MutableColumnRawPtrs = std::vector<IColumn *>;
|
||||
|
||||
template <typename ... Args>
|
||||
struct IsMutableColumns;
|
||||
|
||||
template <typename Arg, typename ... Args>
|
||||
struct IsMutableColumns<Arg, Args ...>
|
||||
{
|
||||
static const bool value = std::is_assignable<MutableColumnPtr &&, Arg>::value && IsMutableColumns<Args ...>::value;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsMutableColumns<> { static const bool value = true; };
|
||||
|
||||
}
|
||||
|
@ -226,53 +226,15 @@ private:
|
||||
Derived * derived() { return static_cast<Derived *>(this); }
|
||||
const Derived * derived() const { return static_cast<const Derived *>(this); }
|
||||
|
||||
template<typename Class, typename... Args>
|
||||
struct HasCreateImmutable
|
||||
{
|
||||
private:
|
||||
template<typename T>
|
||||
static constexpr auto check(decltype(std::declval<T>().createImmutable(std::declval<Args>()... )) *) -> std::true_type;
|
||||
|
||||
template<typename>
|
||||
static constexpr std::false_type check(...);
|
||||
|
||||
typedef decltype(check<Class>(nullptr)) type;
|
||||
|
||||
public:
|
||||
static constexpr bool value = type::value;
|
||||
};
|
||||
|
||||
template<typename Class, typename... Args>
|
||||
struct IsConstructable
|
||||
{
|
||||
private:
|
||||
template<typename T>
|
||||
static constexpr auto check(decltype(T(std::declval<Args>()... )) *) -> std::true_type;
|
||||
|
||||
template<typename>
|
||||
static constexpr std::false_type check(...);
|
||||
|
||||
typedef decltype(check<Class>(nullptr)) type;
|
||||
|
||||
public:
|
||||
static constexpr bool value = type::value;
|
||||
};
|
||||
|
||||
public:
|
||||
using Ptr = typename Base::template immutable_ptr<Derived>;
|
||||
using MutablePtr = typename Base::template mutable_ptr<Derived>;
|
||||
|
||||
template <typename... Args>
|
||||
static auto create(Args &&... args)
|
||||
{
|
||||
if constexpr (HasCreateImmutable<Derived, Args ...>::value && !IsConstructable<Derived, Args ...>::value)
|
||||
return Derived::createImmutable(std::forward<Args>(args)...);
|
||||
else
|
||||
return MutablePtr(new Derived(std::forward<Args>(args)...));
|
||||
}
|
||||
static MutablePtr create(Args &&... args) { return MutablePtr(new Derived(std::forward<Args>(args)...)); }
|
||||
|
||||
template <typename T>
|
||||
static auto create(std::initializer_list<T> && arg) { return create(std::forward<std::initializer_list<T>>(arg)); }
|
||||
static MutablePtr create(std::initializer_list<T> && arg) { return create(std::forward<std::initializer_list<T>>(arg)); }
|
||||
|
||||
typename Base::MutablePtr clone() const override { return typename Base::MutablePtr(new Derived(*derived())); }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user