Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Generic constructor of ColumnVector from initializer list" #9448

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions dbms/src/Columns/ColumnVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class ColumnVector final : public COWHelper<ColumnVectorHelper, ColumnVector<T>>
ColumnVector(const ColumnVector & src) : data(src.data.begin(), src.data.end()) {}

/// Sugar constructor.
template <typename U>
ColumnVector(std::initializer_list<U> il) : data{il} {}
ColumnVector(std::initializer_list<T> il) : data{il} {}

public:
bool isNumeric() const override { return IsNumber<T>; }
Expand Down
39 changes: 11 additions & 28 deletions dbms/src/Common/PODArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cassert>
#include <algorithm>
#include <memory>
#include <iterator>

#include <boost/noncopyable.hpp>
#include <boost/iterator_adaptors.hpp>
Expand Down Expand Up @@ -304,17 +303,13 @@ class PODArray : public PODArrayBase<sizeof(T), initial_bytes, TAllocator, pad_r
assign(n, x);
}

template <typename It1, typename It2,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for iterator-like types
PODArray(It1 from_begin, It2 from_end)
PODArray(const_iterator from_begin, const_iterator from_end)
{
this->alloc_for_num_elements(from_end - from_begin);
insert(from_begin, from_end);
}

template <typename U>
PODArray(std::initializer_list<U> il) : PODArray(std::begin(il), std::end(il)) {}
PODArray(std::initializer_list<T> il) : PODArray(std::begin(il), std::end(il)) {}

PODArray(PODArray && other)
{
Expand Down Expand Up @@ -408,9 +403,7 @@ class PODArray : public PODArrayBase<sizeof(T), initial_bytes, TAllocator, pad_r
}

/// Do not insert into the array a piece of itself. Because with the resize, the iterators on themselves can be invalidated.
template <typename It1, typename It2, typename ... TAllocatorParams,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for iterator-like types>
template <typename It1, typename It2, typename ... TAllocatorParams>
void insertPrepare(It1 from_begin, It2 from_end, TAllocatorParams &&... allocator_params)
{
size_t required_capacity = this->size() + (from_end - from_begin);
Expand All @@ -419,34 +412,28 @@ class PODArray : public PODArrayBase<sizeof(T), initial_bytes, TAllocator, pad_r
}

/// Do not insert into the array a piece of itself. Because with the resize, the iterators on themselves can be invalidated.
template <typename It1, typename It2, typename ... TAllocatorParams,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for iterator-like types
template <typename It1, typename It2, typename ... TAllocatorParams>
void insert(It1 from_begin, It2 from_end, TAllocatorParams &&... allocator_params)
{
insertPrepare(from_begin, from_end, std::forward<TAllocatorParams>(allocator_params)...);
insert_assume_reserved(from_begin, from_end);
}

/// Works under assumption, that it's possible to read up to 15 excessive bytes after `from_end` and this PODArray is padded.
template <typename It1, typename It2, typename ... TAllocatorParams,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for types with operator*
template <typename It1, typename It2, typename ... TAllocatorParams>
void insertSmallAllowReadWriteOverflow15(It1 from_begin, It2 from_end, TAllocatorParams &&... allocator_params)
{
static_assert(pad_right_ >= 15);
insertPrepare(from_begin, from_end, std::forward<TAllocatorParams>(allocator_params)...);
size_t bytes_to_copy = (from_end - from_begin) * sizeof(*from_begin);
size_t bytes_to_copy = this->byte_size(from_end - from_begin);
memcpySmallAllowReadWriteOverflow15(this->c_end, reinterpret_cast<const void *>(&*from_begin), bytes_to_copy);
this->c_end += bytes_to_copy;
}

template <typename It1, typename It2,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for iterator-like types
template <typename It1, typename It2>
void insert(iterator it, It1 from_begin, It2 from_end)
{
size_t bytes_to_copy = (from_end - from_begin) * sizeof(*from_begin);
size_t bytes_to_copy = this->byte_size(from_end - from_begin);
size_t bytes_to_move = (end() - it) * sizeof(T);

insertPrepare(from_begin, from_end);
Expand All @@ -458,12 +445,10 @@ class PODArray : public PODArrayBase<sizeof(T), initial_bytes, TAllocator, pad_r
this->c_end += bytes_to_copy;
}

template <typename It1, typename It2,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for iterator-like types
template <typename It1, typename It2>
void insert_assume_reserved(It1 from_begin, It2 from_end)
{
size_t bytes_to_copy = (from_end - from_begin) * sizeof(*from_begin);
size_t bytes_to_copy = this->byte_size(from_end - from_begin);
memcpy(this->c_end, reinterpret_cast<const void *>(&*from_begin), bytes_to_copy);
this->c_end += bytes_to_copy;
}
Expand Down Expand Up @@ -592,9 +577,7 @@ class PODArray : public PODArrayBase<sizeof(T), initial_bytes, TAllocator, pad_r
std::fill(begin(), end(), x);
}

template <typename It1, typename It2, typename... TAllocatorParams,
typename std::iterator_traits<It1>::pointer * = nullptr,
typename std::iterator_traits<It2>::pointer * = nullptr> /// Only for iterator-like types
template <typename It1, typename It2, typename... TAllocatorParams>
void assign(It1 from_begin, It2 from_end, TAllocatorParams &&... allocator_params)
{
size_t required_capacity = from_end - from_begin;
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/DataStreams/tests/collapsing_sorted_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ try
ColumnWithTypeAndName column1;
column1.name = "Sign";
column1.type = std::make_shared<DataTypeInt8>();
column1.column = ColumnInt8::create({1, -1});
column1.column = ColumnInt8::create({static_cast<int8_t>(1), static_cast<int8_t>(-1)});
block1.insert(column1);

ColumnWithTypeAndName column2;
column2.name = "CounterID";
column2.type = std::make_shared<DataTypeUInt32>();
column2.column = ColumnUInt32::create({123, 123});
column2.column = ColumnUInt32::create({static_cast<uint32_t>(123), static_cast<uint32_t>(123)});
block1.insert(column2);
}

Expand All @@ -46,13 +46,13 @@ try
ColumnWithTypeAndName column1;
column1.name = "Sign";
column1.type = std::make_shared<DataTypeInt8>();
column1.column = ColumnInt8::create({1, 1});
column1.column = ColumnInt8::create({static_cast<int8_t>(1), static_cast<int8_t>(1)});
block2.insert(column1);

ColumnWithTypeAndName column2;
column2.name = "CounterID";
column2.type = std::make_shared<DataTypeUInt32>();
column2.column = ColumnUInt32::create({123, 456});
column2.column = ColumnUInt32::create({static_cast<uint32_t>(123), static_cast<uint32_t>(456)});
block2.insert(column2);
}

Expand Down