mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
dbms: development.
This commit is contained in:
parent
9d8ea42cec
commit
87470640f1
@ -45,8 +45,8 @@ public:
|
||||
|
||||
Field operator[](size_t n) const
|
||||
{
|
||||
size_t offset = n == 0 ? 0 : offsets[n - 1];
|
||||
size_t size = offsets[n] - offset;
|
||||
size_t offset = offsetAt(n);
|
||||
size_t size = sizeAt(n);
|
||||
Array res(size);
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
@ -61,7 +61,7 @@ public:
|
||||
throw Exception("Parameter out of bound in IColumnArray::cut() method.",
|
||||
ErrorCodes::PARAMETER_OUT_OF_BOUND);
|
||||
|
||||
size_t nested_offset = start == 0 ? 0 : offsets[start - 1];
|
||||
size_t nested_offset = offsetAt(start);
|
||||
size_t nested_length = offsets[start + length - 1] - nested_offset;
|
||||
|
||||
data->cut(nested_offset, nested_length);
|
||||
@ -100,6 +100,38 @@ public:
|
||||
offsets.clear();
|
||||
}
|
||||
|
||||
void filter(const Filter & filt)
|
||||
{
|
||||
size_t size = offsets.size();
|
||||
if (size != filt.size())
|
||||
throw Exception("Size of filter doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
||||
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
/// Не слишком оптимально. Можно сделать специализацию для массивов известных типов.
|
||||
Filter nested_filt(offsets.back());
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
if (filt[i])
|
||||
memset(&nested_filt[offsetAt(i)], 1, sizeAt(i));
|
||||
data->filter(nested_filt);
|
||||
|
||||
Offsets_t tmp;
|
||||
tmp.reserve(size);
|
||||
|
||||
size_t current_offset = 0;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
if (filt[i])
|
||||
{
|
||||
current_offset += sizeAt(i);
|
||||
tmp.push_back(current_offset);
|
||||
}
|
||||
}
|
||||
|
||||
tmp.swap(offsets);
|
||||
}
|
||||
|
||||
/** Более эффективные методы манипуляции */
|
||||
IColumn & getData()
|
||||
{
|
||||
@ -124,6 +156,9 @@ public:
|
||||
protected:
|
||||
ColumnPtr data;
|
||||
Offsets_t offsets;
|
||||
|
||||
inline size_t offsetAt(size_t i) const { return i == 0 ? 0 : offsets[i - 1]; }
|
||||
inline size_t sizeAt(size_t i) const { return i == 0 ? offsets[0] : (offsets[i] - offsets[i - 1]); }
|
||||
};
|
||||
|
||||
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
throw Exception("Cannot insert element into constant column", ErrorCodes::CANNOT_INSERT_ELEMENT_INTO_CONSTANT_COLUMN);
|
||||
}
|
||||
void insertDefault() { ++s; }
|
||||
void filter(const Filter & filt) {}
|
||||
|
||||
/** Более эффективные методы манипуляции */
|
||||
T & getData() { return data; }
|
||||
|
@ -77,6 +77,23 @@ public:
|
||||
return *data;
|
||||
}
|
||||
|
||||
void filter(const Filter & filt)
|
||||
{
|
||||
size_t size = this->size();
|
||||
if (size != filt.size())
|
||||
throw Exception("Size of filter doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
||||
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
/// Не слишком оптимально. Можно сделать специализацию для массивов известных типов.
|
||||
Filter nested_filt(size * n);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
if (filt[i])
|
||||
memset(&nested_filt[i * n], 1, n);
|
||||
data->filter(nested_filt);
|
||||
}
|
||||
|
||||
const IColumn & getData() const
|
||||
{
|
||||
return *data;
|
||||
|
@ -75,6 +75,27 @@ public:
|
||||
data.clear();
|
||||
}
|
||||
|
||||
void filter(const Filter & filt)
|
||||
{
|
||||
size_t size = data.size();
|
||||
if (size != filt.size())
|
||||
throw Exception("Size of filter doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
||||
|
||||
Container_t tmp;
|
||||
tmp.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
if (filt[i])
|
||||
{
|
||||
tmp.push_back(T());
|
||||
std::swap(tmp.back(), data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
tmp.swap(data);
|
||||
}
|
||||
|
||||
/** Более эффективные методы манипуляции */
|
||||
Container_t & getData()
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
* Используется для операции WHERE / HAVING.
|
||||
*/
|
||||
typedef std::vector<UInt8> Filter;
|
||||
//virtual void filter(const Filter & filter) = 0;
|
||||
virtual void filter(const Filter & filt) = 0;
|
||||
|
||||
/** Очистить */
|
||||
virtual void clear() = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user