Skip to content

Commit ad5fd98

Browse files
authored
Merge pull request #33 from Enmk/low-cardinality
LowCardinality column implementation
2 parents bdbf400 + 3682e35 commit ad5fd98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1439
-199
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ matrix:
3535
- MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0"
3636

3737
- os: osx
38-
osx_image: xcode8.2
38+
osx_image: xcode9.4
3939
compiler: clang
4040

4141
before_install:
@@ -51,4 +51,4 @@ script:
5151
- cd build
5252
- cmake .. -DBUILD_TESTS=ON && make
5353
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./ut/clickhouse-cpp-ut ; fi
54-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter='-Client/*' ; fi
54+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter=-"Client/*:*Performance*" ; fi

clickhouse/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ SET ( clickhouse-cpp-lib-src
1313
columns/factory.cpp
1414
columns/ip4.cpp
1515
columns/ip6.cpp
16+
columns/lowcardinality.cpp
1617
columns/nullable.cpp
1718
columns/numeric.cpp
1819
columns/string.cpp
1920
columns/tuple.cpp
2021
columns/uuid.cpp
2122

23+
columns/itemview.cpp
24+
2225
types/type_parser.cpp
2326
types/types.cpp
2427

@@ -82,6 +85,8 @@ INSTALL(FILES columns/enum.h DESTINATION include/clickhouse/columns/)
8285
INSTALL(FILES columns/factory.h DESTINATION include/clickhouse/columns/)
8386
INSTALL(FILES columns/ip4.h DESTINATION include/clickhouse/columns/)
8487
INSTALL(FILES columns/ip6.h DESTINATION include/clickhouse/columns/)
88+
INSTALL(FILES columns/itemview.h DESTINATION include/clickhouse/columns/)
89+
INSTALL(FILES columns/lowcardinality.h DESTINATION include/clickhouse/columns/)
8590
INSTALL(FILES columns/nullable.h DESTINATION include/clickhouse/columns/)
8691
INSTALL(FILES columns/numeric.h DESTINATION include/clickhouse/columns/)
8792
INSTALL(FILES columns/string.h DESTINATION include/clickhouse/columns/)

clickhouse/base/string_view.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class StringViewImpl {
7575
return size_;
7676
}
7777

78+
// to mimic std::string and std::string_view
79+
inline size_type length() const noexcept {
80+
return size();
81+
}
82+
7883
public:
7984
// Returns a substring [pos, pos + count).
8085
// If the requested substring extends past the end of the string,

clickhouse/client.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@
2222
#define DBMS_NAME "ClickHouse"
2323
#define DBMS_VERSION_MAJOR 1
2424
#define DBMS_VERSION_MINOR 1
25-
#define REVISION 54126
25+
#define REVISION 54405
2626

2727
#define DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES 50264
2828
#define DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS 51554
2929
#define DBMS_MIN_REVISION_WITH_BLOCK_INFO 51903
3030
#define DBMS_MIN_REVISION_WITH_CLIENT_INFO 54032
3131
#define DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE 54058
3232
#define DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO 54060
33+
//#define DBMS_MIN_REVISION_WITH_TABLES_STATUS 54226
34+
//#define DBMS_MIN_REVISION_WITH_TIME_ZONE_PARAMETER_IN_DATETIME_DATA_TYPE 54337
35+
#define DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME 54372
36+
#define DBMS_MIN_REVISION_WITH_VERSION_PATCH 54401
37+
#define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405
3338

3439
namespace clickhouse {
3540

@@ -45,14 +50,17 @@ struct ClientInfo {
4550
std::string initial_address = "[::ffff:127.0.0.1]:0";
4651
uint64_t client_version_major = 0;
4752
uint64_t client_version_minor = 0;
53+
uint64_t client_version_patch = 0;
4854
uint32_t client_revision = 0;
4955
};
5056

5157
struct ServerInfo {
5258
std::string name;
5359
std::string timezone;
60+
std::string display_name;
5461
uint64_t version_major;
5562
uint64_t version_minor;
63+
uint64_t version_patch;
5664
uint64_t revision;
5765
};
5866

@@ -563,6 +571,9 @@ void Client::Impl::SendQuery(const std::string& query) {
563571

564572
if (server_info_.revision >= DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO)
565573
WireFormat::WriteString(&output_, info.quota_key);
574+
if (server_info_.revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH) {
575+
WireFormat::WriteUInt64(&output_, info.client_version_patch);
576+
}
566577
}
567578

568579
/// Per query settings.
@@ -697,6 +708,18 @@ bool Client::Impl::ReceiveHello() {
697708
}
698709
}
699710

711+
if (server_info_.revision >= DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME) {
712+
if (!WireFormat::ReadString(&input_, &server_info_.display_name)) {
713+
return false;
714+
}
715+
}
716+
717+
if (server_info_.revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH) {
718+
if (!WireFormat::ReadUInt64(&input_, &server_info_.version_patch)) {
719+
return false;
720+
}
721+
}
722+
700723
return true;
701724
} else if (packet_type == ServerCodes::Exception) {
702725
ReceiveException(true);

clickhouse/client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "columns/enum.h"
1010
#include "columns/ip4.h"
1111
#include "columns/ip6.h"
12+
#include "columns/lowcardinality.h"
1213
#include "columns/nullable.h"
1314
#include "columns/numeric.h"
1415
#include "columns/string.h"

clickhouse/columns/array.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ size_t ColumnArray::Size() const {
7878
return offsets_->Size();
7979
}
8080

81+
void ColumnArray::Swap(Column& other) {
82+
auto & col = dynamic_cast<ColumnArray &>(other);
83+
data_.swap(col.data_);
84+
offsets_.swap(col.offsets_);
85+
}
86+
8187
void ColumnArray::OffsetsIncrease(size_t n) {
8288
offsets_->Append(n);
8389
}

clickhouse/columns/array.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class ColumnArray : public Column {
3838
/// Makes slice of the current column.
3939
ColumnRef Slice(size_t, size_t) override;
4040

41+
void Swap(Column&) override;
42+
4143
void OffsetsIncrease(size_t);
4244

4345
private:

clickhouse/columns/column.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "../base/coded.h"
44
#include "../base/input.h"
55
#include "../types/types.h"
6+
#include "../columns/itemview.h"
7+
8+
#include <memory>
69

710
namespace clickhouse {
811

@@ -31,6 +34,7 @@ class Column : public std::enable_shared_from_this<Column> {
3134

3235
/// Get type object of the column.
3336
inline TypeRef Type() const { return type_; }
37+
inline const class Type& GetType() const { return *type_; }
3438

3539
/// Appends content of given column to the end of current one.
3640
virtual void Append(ColumnRef column) = 0;
@@ -50,6 +54,18 @@ class Column : public std::enable_shared_from_this<Column> {
5054
/// Makes slice of the current column.
5155
virtual ColumnRef Slice(size_t begin, size_t len) = 0;
5256

57+
virtual void Swap(Column&) = 0;
58+
59+
/// Get a view on raw item data if it is supported by column, will throw an exception if index is out of range.
60+
/// Please note that view is invalidated once column is items are added or deleted, column is loaded from strean or destroyed.
61+
virtual ItemView GetItem(size_t) const {
62+
throw std::runtime_error("GetItem() is not supported for column of " + type_->GetName());
63+
}
64+
65+
friend void swap(Column& left, Column& right) {
66+
left.Swap(right);
67+
}
68+
5369
protected:
5470
TypeRef type_;
5571
};

clickhouse/columns/date.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ ColumnRef ColumnDate::Slice(size_t begin, size_t len) {
4848
return result;
4949
}
5050

51+
void ColumnDate::Swap(Column& other) {
52+
auto & col = dynamic_cast<ColumnDate &>(other);
53+
data_.swap(col.data_);
54+
}
55+
56+
ItemView ColumnDate::GetItem(size_t index) const {
57+
return data_->GetItem(index);
58+
}
59+
60+
5161

5262
ColumnDateTime::ColumnDateTime()
5363
: Column(Type::CreateDateTime())
@@ -94,4 +104,13 @@ ColumnRef ColumnDateTime::Slice(size_t begin, size_t len) {
94104
return result;
95105
}
96106

107+
void ColumnDateTime::Swap(Column& other) {
108+
auto & col = dynamic_cast<ColumnDateTime &>(other);
109+
data_.swap(col.data_);
110+
}
111+
112+
ItemView ColumnDateTime::GetItem(size_t index) const {
113+
return data_->GetItem(index);
114+
}
115+
97116
}

clickhouse/columns/date.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class ColumnDate : public Column {
3737
/// Makes slice of the current column.
3838
ColumnRef Slice(size_t begin, size_t len) override;
3939

40+
void Swap(Column& other) override;
41+
42+
ItemView GetItem(size_t index) const override;
43+
4044
private:
4145
std::shared_ptr<ColumnUInt16> data_;
4246
};
@@ -70,6 +74,10 @@ class ColumnDateTime : public Column {
7074
/// Makes slice of the current column.
7175
ColumnRef Slice(size_t begin, size_t len) override;
7276

77+
void Swap(Column& other) override;
78+
79+
ItemView GetItem(size_t index) const override;
80+
7381
private:
7482
std::shared_ptr<ColumnUInt32> data_;
7583
};

0 commit comments

Comments
 (0)