ClickHouse/src/Columns/IColumn.cpp

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

98 lines
2.5 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>
2023-12-19 16:43:30 +00:00
#include <Columns/ColumnLowCardinality.h>
2019-07-01 11:44:19 +00:00
#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();
2022-11-16 00:46:57 +00:00
forEachSubcolumn([&](const auto & subcolumn)
{
res << ", " << subcolumn->dumpStructure();
2022-11-16 00:46:57 +00:00
});
res << ")";
return res.str();
}
2019-09-27 13:44:33 +00:00
void IColumn::insertFrom(const IColumn & src, size_t n)
{
insert(src[n]);
}
ColumnPtr IColumn::createWithOffsets(const Offsets & offsets, const ColumnConst & column_with_default_value, 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)
res->insertManyFrom(column_with_default_value.getDataColumn(), 0, 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)
res->insertManyFrom(column_with_default_value.getDataColumn(), 0, offsets_diff - 1);
2021-04-01 18:18:28 +00:00
return res;
2021-03-12 16:33:41 +00:00
}
void IColumn::forEachSubcolumn(ColumnCallback callback) const
2022-11-16 00:46:57 +00:00
{
const_cast<IColumn*>(this)->forEachSubcolumn([&callback](WrappedPtr & subcolumn)
2022-11-16 00:46:57 +00:00
{
callback(std::as_const(subcolumn));
2022-11-16 00:46:57 +00:00
});
}
void IColumn::forEachSubcolumnRecursively(RecursiveColumnCallback callback) const
2022-11-16 00:46:57 +00:00
{
const_cast<IColumn*>(this)->forEachSubcolumnRecursively([&callback](IColumn & subcolumn)
2022-11-16 00:46:57 +00:00
{
callback(std::as_const(subcolumn));
2022-11-16 00:46:57 +00:00
});
}
2019-07-01 11:44:19 +00:00
bool isColumnNullable(const IColumn & column)
{
return checkColumn<ColumnNullable>(column);
}
2023-12-19 16:43:30 +00:00
bool isColumnNullableOrLowCardinalityNullable(const IColumn & column)
{
return isColumnNullable(column) || isColumnLowCardinalityNullable(column);
}
2019-07-01 11:44:19 +00:00
bool isColumnConst(const IColumn & column)
{
return checkColumn<ColumnConst>(column);
}
}