Skip to content

Commit

Permalink
rebase to trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
den818 committed Dec 17, 2022
1 parent 4151639 commit 230fa79
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 36 deletions.
48 changes: 36 additions & 12 deletions clickhouse/columns/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ namespace clickhouse {

template <typename NestedColumnType, Type::Code type_code>
ColumnGeo<NestedColumnType, type_code>::ColumnGeo()
: Column(std::move(CreateGeoType<type_code>())),
: Column(std::move(CreateGeoType<type_code>()), Serialization::MakeDefault(this)),
data_(std::move(CreateColumn<NestedColumnType>())) {
}

template <typename NestedColumnType, Type::Code type_code>
ColumnGeo<NestedColumnType, type_code>::ColumnGeo(ColumnRef data)
: Column(std::move(CreateGeoType<type_code>()))
: Column(std::move(CreateGeoType<type_code>()), Serialization::MakeDefault(this))
, data_(std::move(WrapColumn<NestedColumnType>(std::move(data)))) {
}

Expand All @@ -66,16 +66,6 @@ void ColumnGeo<NestedColumnType, type_code>::Append(ColumnRef column) {
}
}

template <typename NestedColumnType, Type::Code type_code>
bool ColumnGeo<NestedColumnType, type_code>::LoadBody(InputStream* input, size_t rows) {
return data_->LoadBody(input, rows);
}

template <typename NestedColumnType, Type::Code type_code>
void ColumnGeo<NestedColumnType, type_code>::SaveBody(OutputStream* output) {
data_->SaveBody(output);
}

template <typename NestedColumnType, Type::Code type_code>
size_t ColumnGeo<NestedColumnType, type_code>::Size() const {
return data_->Size();
Expand All @@ -97,6 +87,40 @@ void ColumnGeo<NestedColumnType, type_code>::Swap(Column& other) {
data_.swap(col.data_);
}

template <typename NestedColumnType, Type::Code type_code>
void ColumnGeo<NestedColumnType, type_code>::SetSerializationKind(Serialization::Kind kind) {
switch (kind)
{
case Serialization::Kind::DEFAULT:
serialization_ = Serialization::MakeDefault(this);
break;
default:
throw UnimplementedError("Serialization kind:" + std::to_string(static_cast<int>(kind))
+ " is not supported for column of " + type_->GetName());
}
}

template <typename NestedColumnType, Type::Code type_code>
bool ColumnGeo<NestedColumnType, type_code>::LoadPrefix(InputStream* input, size_t rows) {
return data_->GetSerialization()->LoadPrefix(data_.get(), input, rows);
}

template <typename NestedColumnType, Type::Code type_code>
bool ColumnGeo<NestedColumnType, type_code>::LoadBody(InputStream* input, size_t rows) {
return data_->GetSerialization()->LoadBody(data_.get(), input, rows);
}

template <typename NestedColumnType, Type::Code type_code>
void ColumnGeo<NestedColumnType, type_code>::SavePrefix(OutputStream* output) {
data_->GetSerialization()->SavePrefix(data_.get(), output);
}

template <typename NestedColumnType, Type::Code type_code>
void ColumnGeo<NestedColumnType, type_code>::SaveBody(OutputStream* output) {
data_->GetSerialization()->SaveBody(data_.get(), output);
}


template class ColumnGeo<ColumnTupleT<ColumnFloat64, ColumnFloat64>, Type::Code::Point>;

template class ColumnGeo<ColumnArrayT<ColumnPoint>, Type::Code::Ring>;
Expand Down
22 changes: 16 additions & 6 deletions clickhouse/columns/geo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ class ColumnGeo : public Column {
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;

/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;

/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;

/// Clear column data .
void Clear() override;

Expand All @@ -49,7 +43,23 @@ class ColumnGeo : public Column {
ColumnRef CloneEmpty() const override;
void Swap(Column& other) override;

void SetSerializationKind(Serialization::Kind kind) override;

private:
/// Loads column prefix from input stream.
bool LoadPrefix(InputStream* input, size_t rows);

/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows);

/// Saves column prefix to output stream.
void SavePrefix(OutputStream* output);

/// Saves column data to output stream.
void SaveBody(OutputStream* output);

friend SerializationDefault<ColumnGeo<NestedColumnType, type_code>>;

std::shared_ptr<NestedColumnType> data_;
};

Expand Down
23 changes: 18 additions & 5 deletions clickhouse/columns/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ TypeRef GetMapType(const Type& data_type) {
namespace clickhouse {

ColumnMap::ColumnMap(ColumnRef data)
: Column(GetMapType(data->GetType())), data_(data->As<ColumnArray>()) {
: Column(GetMapType(data->GetType()), Serialization::MakeDefault(this))
, data_(data->As<ColumnArray>()) {
}

void ColumnMap::Clear() {
Expand All @@ -44,19 +45,19 @@ void ColumnMap::Append(ColumnRef column) {
}

bool ColumnMap::LoadPrefix(InputStream* input, size_t rows) {
return data_->LoadPrefix(input, rows);
return data_->GetSerialization()->LoadPrefix(data_.get(), input, rows);
}

bool ColumnMap::LoadBody(InputStream* input, size_t rows) {
return data_->LoadBody(input, rows);
return data_->GetSerialization()->LoadBody(data_.get(),input, rows);
}

void ColumnMap::SavePrefix(OutputStream* output) {
data_->SavePrefix(output);
data_->GetSerialization()->SavePrefix(data_.get(), output);
}

void ColumnMap::SaveBody(OutputStream* output) {
data_->SaveBody(output);
data_->GetSerialization()->SaveBody(data_.get(), output);
}

size_t ColumnMap::Size() const {
Expand All @@ -76,6 +77,18 @@ void ColumnMap::Swap(Column& other) {
data_.swap(col.data_);
}

void ColumnMap::SetSerializationKind(Serialization::Kind kind) {
switch (kind)
{
case Serialization::Kind::DEFAULT:
serialization_ = Serialization::MakeDefault(this);
break;
default:
throw UnimplementedError("Serialization kind:" + std::to_string(static_cast<int>(kind))
+ " is not supported for column of " + type_->GetName());
}
}

ColumnRef ColumnMap::GetAsColumn(size_t n) const {
return data_->GetAsColumn(n);
}
Expand Down
28 changes: 16 additions & 12 deletions clickhouse/columns/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ class ColumnMap : public Column {
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;

/// Loads column prefix from input stream.
bool LoadPrefix(InputStream* input, size_t rows) override;

/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;

/// Saves column prefix to output stream.
void SavePrefix(OutputStream* output) override;

/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;

/// Clear column data .
void Clear() override;

Expand All @@ -51,6 +39,8 @@ class ColumnMap : public Column {
ColumnRef CloneEmpty() const override;
void Swap(Column&) override;

void SetSerializationKind(Serialization::Kind kind) override;

/// Converts map at pos n to column.
/// Type of row is tuple {key, value}.
ColumnRef GetAsColumn(size_t n) const;
Expand All @@ -62,6 +52,20 @@ class ColumnMap : public Column {
ColumnMap(ColumnMap&& map);

private:
/// Loads column prefix from input stream.
bool LoadPrefix(InputStream* input, size_t rows);

/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows);

/// Saves column prefix to output stream.
void SavePrefix(OutputStream* output);

/// Saves column data to output stream.
void SaveBody(OutputStream* output);

friend SerializationDefault<ColumnMap>;

std::shared_ptr<ColumnArray> data_;
};

Expand Down
2 changes: 1 addition & 1 deletion clickhouse/columns/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ColumnString::ColumnString()
}

ColumnString::ColumnString(size_t element_count)
: Column(Type::CreateString())
: Column(Type::CreateString(), Serialization::MakeDefault(this))
{
items_.reserve(element_count);
// 100 is arbitrary number, assumption that string values are about ~40 bytes long.
Expand Down

0 comments on commit 230fa79

Please sign in to comment.