Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ matrix:
- MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0"

- os: osx
osx_image: xcode8.2
osx_image: xcode9.4
compiler: clang

before_install:
Expand All @@ -51,4 +51,4 @@ script:
- cd build
- cmake .. -DBUILD_TESTS=ON && make
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./ut/clickhouse-cpp-ut ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter='-Client/*' ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter=-"Client/*:*Performance*" ; fi
4 changes: 4 additions & 0 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ SET ( clickhouse-cpp-lib-src
columns/factory.cpp
columns/ip4.cpp
columns/ip6.cpp
columns/lowcardinality.cpp
columns/nullable.cpp
columns/numeric.cpp
columns/string.cpp
columns/tuple.cpp
columns/uuid.cpp
columns/itemview.cpp

types/type_parser.cpp
types/types.cpp
Expand Down Expand Up @@ -82,12 +84,14 @@ INSTALL(FILES columns/enum.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/factory.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/ip4.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/ip6.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/lowcardinality.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/nullable.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/numeric.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/string.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/tuple.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/utils.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/uuid.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/itemview.h DESTINATION include/clickhouse/columns/)

# types
INSTALL(FILES types/type_parser.h DESTINATION include/clickhouse/types/)
Expand Down
5 changes: 5 additions & 0 deletions clickhouse/base/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class StringViewImpl {
return size_;
}

// to mimic std::string and std::string_view
inline size_type length() const noexcept {
return size();
}

public:
// Returns a substring [pos, pos + count).
// If the requested substring extends past the end of the string,
Expand Down
23 changes: 22 additions & 1 deletion clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
#define DBMS_NAME "ClickHouse"
#define DBMS_VERSION_MAJOR 1
#define DBMS_VERSION_MINOR 1
#define REVISION 54126
#define REVISION 54405

#define DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES 50264
#define DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS 51554
#define DBMS_MIN_REVISION_WITH_BLOCK_INFO 51903
#define DBMS_MIN_REVISION_WITH_CLIENT_INFO 54032
#define DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE 54058
#define DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO 54060
//#define DBMS_MIN_REVISION_WITH_TABLES_STATUS 54226
//#define DBMS_MIN_REVISION_WITH_TIME_ZONE_PARAMETER_IN_DATETIME_DATA_TYPE 54337
#define DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME 54372
#define DBMS_MIN_REVISION_WITH_VERSION_PATCH 54401
#define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405

namespace clickhouse {

Expand All @@ -51,8 +56,10 @@ struct ClientInfo {
struct ServerInfo {
std::string name;
std::string timezone;
std::string display_name;
uint64_t version_major;
uint64_t version_minor;
uint64_t version_patch;
uint64_t revision;
};

Expand Down Expand Up @@ -563,6 +570,8 @@ void Client::Impl::SendQuery(const std::string& query) {

if (server_info_.revision >= DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO)
WireFormat::WriteString(&output_, info.quota_key);
if (server_info_.revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH)
WireFormat::WriteUInt64(&output_, info.client_revision);
}

/// Per query settings.
Expand Down Expand Up @@ -697,6 +706,18 @@ bool Client::Impl::ReceiveHello() {
}
}

if (server_info_.revision >= DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME) {
if (!WireFormat::ReadString(&input_, &server_info_.display_name)) {
return false;
}
}

if (server_info_.revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH) {
if (!WireFormat::ReadUInt64(&input_, &server_info_.version_patch)) {
return false;
}
}

return true;
} else if (packet_type == ServerCodes::Exception) {
ReceiveException(true);
Expand Down
1 change: 1 addition & 0 deletions clickhouse/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "columns/enum.h"
#include "columns/ip4.h"
#include "columns/ip6.h"
#include "columns/lowcardinality.h"
#include "columns/nullable.h"
#include "columns/numeric.h"
#include "columns/string.h"
Expand Down
7 changes: 7 additions & 0 deletions clickhouse/columns/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ size_t ColumnArray::Size() const {
return offsets_->Size();
}

void ColumnArray::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnArray*>(&other)) {
data_.swap(col->data_);
offsets_.swap(col->offsets_);
}
}

void ColumnArray::OffsetsIncrease(size_t n) {
offsets_->Append(n);
}
Expand Down
2 changes: 2 additions & 0 deletions clickhouse/columns/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ColumnArray : public Column {
/// Makes slice of the current column.
ColumnRef Slice(size_t, size_t) override;

void Swap(Column&) override;

void OffsetsIncrease(size_t);

private:
Expand Down
16 changes: 16 additions & 0 deletions clickhouse/columns/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "../base/coded.h"
#include "../base/input.h"
#include "../types/types.h"
#include "../columns/itemview.h"

#include <memory>

namespace clickhouse {

Expand Down Expand Up @@ -50,6 +53,19 @@ class Column : public std::enable_shared_from_this<Column> {
/// Makes slice of the current column.
virtual ColumnRef Slice(size_t begin, size_t len) = 0;

virtual void Swap(Column&) = 0;

/// Get a view on raw item data if it is supported by column, will throw an exception if index is out of range.
/// Please note that view is invalidated once column is items are added or deleted, column is loaded from strean or destroyed.
virtual ItemView GetItem(size_t) const {
throw std::runtime_error("GetItem() is not supported for column of " + type_->GetName());
}

friend void swap(Column& left, Column& right)
{
left.Swap(right);
}

protected:
TypeRef type_;
};
Expand Down
21 changes: 21 additions & 0 deletions clickhouse/columns/date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ ColumnRef ColumnDate::Slice(size_t begin, size_t len) {
return result;
}

void ColumnDate::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnDate*>(&other)) {
data_.swap(col->data_);
}
}

ItemView ColumnDate::GetItem(size_t index) const {
return data_->GetItem(index);
}



ColumnDateTime::ColumnDateTime()
: Column(Type::CreateDateTime())
Expand Down Expand Up @@ -94,4 +105,14 @@ ColumnRef ColumnDateTime::Slice(size_t begin, size_t len) {
return result;
}

void ColumnDateTime::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnDateTime*>(&other)) {
data_.swap(col->data_);
}
}

ItemView ColumnDateTime::GetItem(size_t index) const {
return data_->GetItem(index);
}

}
8 changes: 8 additions & 0 deletions clickhouse/columns/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ColumnDate : public Column {
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) override;

void Swap(Column& other) override;

ItemView GetItem(size_t index) const override;

private:
std::shared_ptr<ColumnUInt16> data_;
};
Expand Down Expand Up @@ -70,6 +74,10 @@ class ColumnDateTime : public Column {
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) override;

void Swap(Column& other) override;

ItemView GetItem(size_t index) const override;

private:
std::shared_ptr<ColumnUInt32> data_;
};
Expand Down
10 changes: 10 additions & 0 deletions clickhouse/columns/decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,14 @@ ColumnRef ColumnDecimal::Slice(size_t begin, size_t len) {
return slice;
}

void ColumnDecimal::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnDecimal*>(&other)) {
data_.swap(col->data_);
}
}

ItemView ColumnDecimal::GetItem(size_t index) const {
return data_->GetItem(index);
}

}
2 changes: 2 additions & 0 deletions clickhouse/columns/decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ColumnDecimal : public Column {
void Clear() override;
size_t Size() const override;
ColumnRef Slice(size_t begin, size_t len) override;
void Swap(Column& other) override;
ItemView GetItem(size_t index) const override;

private:
/// Depending on a precision it can be one of:
Expand Down
13 changes: 13 additions & 0 deletions clickhouse/columns/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ ColumnRef ColumnEnum<T>::Slice(size_t begin, size_t len) {
return std::make_shared<ColumnEnum<T>>(type_, SliceVector(data_, begin, len));
}

template <typename T>
void ColumnEnum<T>::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnEnum<T>*>(&other)) {
data_.swap(col->data_);
}
}

template <typename T>
ItemView ColumnEnum<T>::GetItem(size_t index) const {
const T value = data_[index];
return ItemView{type_->GetCode(), value};
}

template class ColumnEnum<int8_t>;
template class ColumnEnum<int16_t>;

Expand Down
4 changes: 4 additions & 0 deletions clickhouse/columns/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class ColumnEnum : public Column {
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) override;

void Swap(Column& other) override;

ItemView GetItem(size_t index) const override;

private:
std::vector<T> data_;
};
Expand Down
13 changes: 13 additions & 0 deletions clickhouse/columns/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "nothing.h"
#include "nullable.h"
#include "numeric.h"
#include "lowcardinality.h"
#include "string.h"
#include "tuple.h"
#include "uuid.h"
Expand Down Expand Up @@ -134,6 +135,18 @@ static ColumnRef CreateColumnFromAst(const TypeAst& ast) {
}
break;
}
case TypeAst::LowCardinality: {
const auto nested = ast.elements.front();
switch (nested.code) {
// TODO (nemkov): update this to maximize code reuse.
case Type::String:
return std::make_shared<ColumnLowCardinalityT<ColumnString>>();
case Type::FixedString:
return std::make_shared<ColumnLowCardinalityT<ColumnFixedString>>(nested.elements.front().value);
default:
throw std::runtime_error("LowCardinality(" + nested.name + ") is not supported");
}
}

case TypeAst::Null:
case TypeAst::Number:
Expand Down
10 changes: 10 additions & 0 deletions clickhouse/columns/ip4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ ColumnRef ColumnIPv4::Slice(size_t begin, size_t len) {
return std::make_shared<ColumnIPv4>(data_->Slice(begin, len));
}

void ColumnIPv4::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnIPv4*>(&other)) {
data_.swap(col->data_);
}
}

ItemView ColumnIPv4::GetItem(size_t index) const {
return data_->GetItem(index);
}

}
4 changes: 4 additions & 0 deletions clickhouse/columns/ip4.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class ColumnIPv4 : public Column {
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) override;

void Swap(Column& other) override;

ItemView GetItem(size_t index) const override;

private:
std::shared_ptr<ColumnUInt32> data_;
};
Expand Down
10 changes: 10 additions & 0 deletions clickhouse/columns/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ ColumnRef ColumnIPv6::Slice(size_t begin, size_t len) {
return std::make_shared<ColumnIPv6>(data_->Slice(begin, len));
}

void ColumnIPv6::Swap(Column& other) {
if (auto col = dynamic_cast<ColumnIPv6*>(&other)) {
data_.swap(col->data_);
}
}

ItemView ColumnIPv6::GetItem(size_t index) const {
return data_->GetItem(index);
}

}
2 changes: 2 additions & 0 deletions clickhouse/columns/ip6.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class ColumnIPv6 : public Column{

/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) override;
void Swap(Column& other) override;
ItemView GetItem(size_t index) const override;

private:
std::shared_ptr<ColumnFixedString> data_;
Expand Down
Loading