ClickHouse/src/Columns/IColumn.cpp

76 lines
1.8 KiB
C++
Raw Normal View History

#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
#include <Columns/IColumn.h>
2019-07-01 11:44:19 +00:00
#include <Columns/ColumnNullable.h>
#include <Columns/ColumnConst.h>
2019-09-27 13:44:33 +00:00
#include <Core/Field.h>
namespace DB
{
String IColumn::dumpStructure() const
{
WriteBufferFromOwnString res;
res << getFamilyName() << "(size = " << size();
ColumnCallback callback = [&](ColumnPtr & subcolumn)
{
res << ", " << subcolumn->dumpStructure();
};
const_cast<IColumn*>(this)->forEachSubcolumn(callback);
res << ")";
return res.str();
}
2019-09-27 13:44:33 +00:00
void IColumn::insertFrom(const IColumn & src, size_t n)
{
insert(src[n]);
}
2021-04-03 00:04:48 +00:00
void IColumn::getIndicesOfNonDefaultValues(Offsets & indices, size_t from, size_t limit) const
{
size_t to = limit && from + limit < size() ? from + limit : size();
indices.reserve(indices.size() + to - from);
for (size_t i = from; i < to; ++i)
indices.push_back(i);
}
2021-04-01 18:18:28 +00:00
ColumnPtr IColumn::createWithOffsets(const Offsets & offsets, size_t total_rows) const
2021-03-12 16:33:41 +00:00
{
2021-04-01 18:18:28 +00:00
auto res = cloneEmpty();
res->reserve(total_rows);
2021-04-03 00:04:48 +00:00
ssize_t current_offset = -1;
2021-03-12 16:33:41 +00:00
for (size_t i = 0; i < offsets.size(); ++i)
{
2021-04-03 00:04:48 +00:00
ssize_t offsets_diff = static_cast<ssize_t>(offsets[i]) - current_offset;
2021-04-01 18:18:28 +00:00
current_offset = offsets[i];
if (offsets_diff > 1)
res->insertManyFrom(*this, 0, offsets_diff - 1);
res->insertFrom(*this, i + 1);
2021-03-12 16:33:41 +00:00
}
2021-04-01 18:18:28 +00:00
2021-04-03 00:04:48 +00:00
ssize_t offsets_diff = static_cast<ssize_t>(total_rows) - current_offset;
2021-04-01 18:18:28 +00:00
if(offsets_diff > 1)
res->insertManyFrom(*this, 0, offsets_diff - 1);
return res;
2021-03-12 16:33:41 +00:00
}
2019-07-01 11:44:19 +00:00
bool isColumnNullable(const IColumn & column)
{
return checkColumn<ColumnNullable>(column);
}
bool isColumnConst(const IColumn & column)
{
return checkColumn<ColumnConst>(column);
}
}