ClickHouse/src/Columns/IColumn.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 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>
2021-10-29 17:21:02 +00:00
#include <DataTypes/Serializations/SerializationInfo.h>
namespace DB
{
2021-05-21 00:57:11 +00:00
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
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-09-16 13:57:45 +00:00
ColumnPtr IColumn::createWithOffsets(const Offsets & offsets, const Field & default_field, size_t total_rows, size_t shift) const
2021-03-12 16:33:41 +00:00
{
2021-05-21 00:57:11 +00:00
if (offsets.size() + shift != size())
throw Exception(ErrorCodes::LOGICAL_ERROR,
"Incompatible sizes of offsets ({}), shift ({}) and size of column {}", offsets.size(), shift, size());
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)
2021-09-16 13:57:45 +00:00
res->insertMany(default_field, offsets_diff - 1);
2021-04-01 18:18:28 +00:00
2021-05-21 00:57:11 +00:00
res->insertFrom(*this, i + shift);
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-05-16 18:59:43 +00:00
if (offsets_diff > 1)
2021-09-16 13:57:45 +00:00
res->insertMany(default_field, offsets_diff - 1);
2021-04-01 18:18:28 +00:00
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);
}
}