Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better ColumnEnum - less memory #192

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clickhouse/columns/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const T& ColumnEnum<T>::At(size_t n) const {
}

template <typename T>
const std::string ColumnEnum<T>::NameAt(size_t n) const {
std::string_view ColumnEnum<T>::NameAt(size_t n) const {
return type_->As<EnumType>()->GetEnumName(data_.at(n));
}

Expand Down
4 changes: 2 additions & 2 deletions clickhouse/columns/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ColumnEnum : public Column {

/// Returns element at given row number.
const T& At(size_t n) const;
const std::string NameAt(size_t n) const;
std::string_view NameAt(size_t n) const;

/// Returns element at given row number.
const T& operator[] (size_t n) const;
Expand All @@ -38,7 +38,7 @@ class ColumnEnum : public Column {
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;

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

/// Returns count of rows in the column.
Expand Down
6 changes: 3 additions & 3 deletions clickhouse/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ std::string DecimalType::GetName() const {

EnumType::EnumType(Type::Code type, const std::vector<EnumItem>& items) : Type(type) {
for (const auto& item : items) {
value_to_name_[item.second] = item.first;
name_to_value_[item.first] = item.second;
auto result = name_to_value_.insert(item);
value_to_name_[item.second] = result.first->first;
}
}

Expand Down Expand Up @@ -291,7 +291,7 @@ std::string EnumType::GetName() const {
return result;
}

const std::string& EnumType::GetEnumName(int16_t value) const {
std::string_view EnumType::GetEnumName(int16_t value) const {
return value_to_name_.at(value);
}

Expand Down
4 changes: 2 additions & 2 deletions clickhouse/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ class EnumType : public Type {
std::string GetName() const;

/// Methods to work with enum types.
const std::string& GetEnumName(int16_t value) const;
std::string_view GetEnumName(int16_t value) const;
int16_t GetEnumValue(const std::string& name) const;
bool HasEnumName(const std::string& name) const;
bool HasEnumValue(int16_t value) const;

private:
using ValueToNameType = std::map<int16_t, std::string>;
using ValueToNameType = std::map<int16_t, std::string_view>;
using NameToValueType = std::map<std::string, int16_t>;
using ValueToNameIterator = ValueToNameType::const_iterator;

Expand Down