Skip to content

Commit 4ed6037

Browse files
authored
Merge branch 'master' into SparceColumns
2 parents 5ae4fa1 + 4251535 commit 4ed6037

35 files changed

+1246
-53
lines changed

.github/workflows/linux.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Linux
22

33
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
46
push:
57
branches: [ master ]
68
pull_request:
@@ -12,7 +14,7 @@ env:
1214

1315
jobs:
1416
build:
15-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-20.04
1618
strategy:
1719
matrix:
1820
compiler: [clang-6, gcc-7, gcc-8, gcc-9]

.github/workflows/macos.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: macOS
22

33
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
46
push:
57
branches: [ master ]
68
pull_request:

.github/workflows/windows_mingw.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Windows mingw
22

33
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
46
push:
57
branches: [ master ]
68
pull_request:

.github/workflows/windows_msvc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Windows
22

33
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
46
push:
57
branches: [ master ]
68
pull_request:

CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ PROJECT (CLICKHOUSE-CLIENT)
2727
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-declarations")
2828
ENDIF ()
2929

30-
INCLUDE_DIRECTORIES (.)
31-
INCLUDE_DIRECTORIES (contrib)
32-
3330
SUBDIRS (
3431
clickhouse
3532
contrib/absl

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ C++ client for [ClickHouse](https://clickhouse.com/).
2121
* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
2222
* Int128
2323
* UUID
24+
* Map
25+
* Point, Ring, Polygon, MultiPolygon
2426

2527
## Building
2628

@@ -87,7 +89,7 @@ int main()
8789

8890
## Retries
8991
If you wish to implement some retry logic atop of `clickhouse::Client` there are few simple rules to make you life easier:
90-
- If previous attempt threw an exception, then make sure to call `clickhouse::Client::ResetConnection()` before the next try.
92+
- If previous attempt threw an exception, then make sure to call `clickhouse::Client::ResetConnection()` before the next try.
9193
- For `clickhouse::Client::Insert()` you can reuse a block from previous try, no need to rebuild it from scratch.
9294

9395
See https://github.com/ClickHouse/clickhouse-cpp/issues/184 for details.

bench/bench.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <benchmark/benchmark.h>
22

33
#include <clickhouse/client.h>
4+
#include <ut/utils.h>
45

56
namespace clickhouse {
67

clickhouse/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ SET ( clickhouse-cpp-lib-src
1212
columns/decimal.cpp
1313
columns/enum.cpp
1414
columns/factory.cpp
15+
columns/geo.cpp
1516
columns/ip4.cpp
1617
columns/ip6.cpp
1718
columns/lowcardinality.cpp
1819
columns/lowcardinalityadaptor.h
1920
columns/nullable.cpp
2021
columns/numeric.cpp
2122
columns/serialization.cpp
23+
columns/map.cpp
2224
columns/string.cpp
2325
columns/tuple.cpp
2426
columns/uuid.cpp
@@ -44,13 +46,19 @@ TARGET_LINK_LIBRARIES (clickhouse-cpp-lib
4446
cityhash-lib
4547
lz4-lib
4648
)
49+
TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib
50+
PUBLIC ${PROJECT_SOURCE_DIR}
51+
)
4752

4853
ADD_LIBRARY (clickhouse-cpp-lib-static STATIC ${clickhouse-cpp-lib-src})
4954
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
5055
absl-lib
5156
cityhash-lib
5257
lz4-lib
5358
)
59+
TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib-static
60+
PUBLIC ${PROJECT_SOURCE_DIR}
61+
)
5462

5563
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
5664
INCLUDE (CheckCXXSourceCompiles)
@@ -96,6 +104,7 @@ INSTALL(FILES base/input.h DESTINATION include/clickhouse/base/)
96104
INSTALL(FILES base/open_telemetry.h DESTINATION include/clickhouse/base/)
97105
INSTALL(FILES base/output.h DESTINATION include/clickhouse/base/)
98106
INSTALL(FILES base/platform.h DESTINATION include/clickhouse/base/)
107+
INSTALL(FILES base/projected_iterator.h DESTINATION include/clickhouse/base/)
99108
INSTALL(FILES base/singleton.h DESTINATION include/clickhouse/base/)
100109
INSTALL(FILES base/socket.h DESTINATION include/clickhouse/base/)
101110
INSTALL(FILES base/string_utils.h DESTINATION include/clickhouse/base/)
@@ -110,13 +119,15 @@ INSTALL(FILES columns/date.h DESTINATION include/clickhouse/columns/)
110119
INSTALL(FILES columns/decimal.h DESTINATION include/clickhouse/columns/)
111120
INSTALL(FILES columns/enum.h DESTINATION include/clickhouse/columns/)
112121
INSTALL(FILES columns/factory.h DESTINATION include/clickhouse/columns/)
122+
INSTALL(FILES columns/geo.h DESTINATION include/clickhouse/columns/)
113123
INSTALL(FILES columns/ip4.h DESTINATION include/clickhouse/columns/)
114124
INSTALL(FILES columns/ip6.h DESTINATION include/clickhouse/columns/)
115125
INSTALL(FILES columns/itemview.h DESTINATION include/clickhouse/columns/)
116126
INSTALL(FILES columns/lowcardinality.h DESTINATION include/clickhouse/columns/)
117127
INSTALL(FILES columns/nullable.h DESTINATION include/clickhouse/columns/)
118128
INSTALL(FILES columns/numeric.h DESTINATION include/clickhouse/columns/)
119129
INSTALL(FILES columns/serialization.h DESTINATION include/clickhouse/columns/)
130+
INSTALL(FILES columns/map.h DESTINATION include/clickhouse/columns/)
120131
INSTALL(FILES columns/string.h DESTINATION include/clickhouse/columns/)
121132
INSTALL(FILES columns/tuple.h DESTINATION include/clickhouse/columns/)
122133
INSTALL(FILES columns/utils.h DESTINATION include/clickhouse/columns/)

clickhouse/base/projected_iterator.h

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pragma once
2+
3+
#include <iterator>
4+
#include <type_traits>
5+
#include <utility>
6+
7+
namespace clickhouse {
8+
9+
template <typename UnaryFunction, typename Iterator, typename Reference = decltype(std::declval<UnaryFunction>()(std::declval<Iterator>())),
10+
typename Value = std::decay_t<Reference>>
11+
class ProjectedIterator {
12+
public:
13+
using value_type = Value;
14+
using reference = Reference;
15+
using pointer = Reference;
16+
using difference_type = typename std::iterator_traits<Iterator>::difference_type;
17+
using iterator_category = typename std::iterator_traits<Iterator>::iterator_category;
18+
19+
ProjectedIterator() = default;
20+
21+
inline ProjectedIterator(Iterator const& iterator, UnaryFunction functor)
22+
: iterator_(iterator)
23+
, functor_(std::move(functor)) {
24+
}
25+
26+
inline UnaryFunction functor() const { return functor; }
27+
28+
inline Iterator const& base() const { return iterator_; }
29+
30+
inline reference operator*() const { return functor_(iterator_); }
31+
32+
inline ProjectedIterator& operator++() {
33+
++iterator_;
34+
return *this;
35+
}
36+
37+
inline ProjectedIterator& operator--() {
38+
--iterator_;
39+
return *this;
40+
}
41+
42+
inline bool operator==(const ProjectedIterator& other) const {
43+
return this->iterator_ == other.iterator_;
44+
}
45+
46+
inline bool operator!=(const ProjectedIterator& other) const {
47+
return !(*this == other);
48+
}
49+
50+
private:
51+
Iterator iterator_;
52+
UnaryFunction functor_;
53+
};
54+
55+
} // namespace clickhouse

clickhouse/base/string_view.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ template <
1111
typename TChar,
1212
typename TTraits = std::char_traits<TChar>
1313
>
14-
class StringViewImpl {
14+
class
15+
[[deprecated("Obsolete due to C++17's std::string_view. Will be removed in next major release (3.0) ")]]
16+
StringViewImpl {
1517
public:
1618
using size_type = size_t;
1719
using traits_type = TTraits;

clickhouse/client.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
#include "columns/date.h"
88
#include "columns/decimal.h"
99
#include "columns/enum.h"
10+
#include "columns/geo.h"
1011
#include "columns/ip4.h"
1112
#include "columns/ip6.h"
1213
#include "columns/lowcardinality.h"
1314
#include "columns/nullable.h"
1415
#include "columns/numeric.h"
16+
#include "columns/map.h"
1517
#include "columns/string.h"
1618
#include "columns/tuple.h"
1719
#include "columns/uuid.h"
@@ -87,8 +89,8 @@ struct ClientOptions {
8789
DECLARE_FIELD(tcp_nodelay, bool, TcpNoDelay, true);
8890

8991
/// Connection socket timeout. If the timeout is set to zero then the operation will never timeout.
90-
DECLARE_FIELD(connection_recv_timeout, std::chrono::seconds, SetConnectionRecvTimeout, std::chrono::seconds(0));
91-
DECLARE_FIELD(connection_send_timeout, std::chrono::seconds, SetConnectionSendTimeout, std::chrono::seconds(0));
92+
DECLARE_FIELD(connection_recv_timeout, std::chrono::milliseconds, SetConnectionRecvTimeout, std::chrono::milliseconds(0));
93+
DECLARE_FIELD(connection_send_timeout, std::chrono::milliseconds, SetConnectionSendTimeout, std::chrono::milliseconds(0));
9294

9395
/** It helps to ease migration of the old codebases, which can't afford to switch
9496
* to using ColumnLowCardinalityT or ColumnLowCardinality directly,

clickhouse/columns/array.h

+38-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "column.h"
44
#include "numeric.h"
5+
#include "utils.h"
56

67
#include <memory>
78

@@ -125,13 +126,8 @@ class ColumnArrayT : public ColumnArray {
125126
* This is a static method to make such conversion verbose.
126127
*/
127128
static auto Wrap(ColumnArray&& col) {
128-
if constexpr (std::is_base_of_v<ColumnArray, NestedColumnType> && !std::is_same_v<ColumnArray, NestedColumnType>) {
129-
// assuming NestedColumnType is ArrayT specialization
130-
return std::make_shared<ColumnArrayT<NestedColumnType>>(NestedColumnType::Wrap(col.GetData()), col.offsets_);
131-
} else {
132-
auto nested_data = col.GetData()->template AsStrict<NestedColumnType>();
133-
return std::make_shared<ColumnArrayT<NestedColumnType>>(nested_data, col.offsets_);
134-
}
129+
auto nested_data = WrapColumn<NestedColumnType>(col.GetData());
130+
return std::make_shared<ColumnArrayT<NestedColumnType>>(nested_data, col.offsets_);
135131
}
136132

137133
static auto Wrap(Column&& col) {
@@ -150,7 +146,7 @@ class ColumnArrayT : public ColumnArray {
150146
const size_t size_;
151147

152148
public:
153-
using ValueType = typename NestedColumnType::ValueType;
149+
using ValueType = std::decay_t<decltype(std::declval<NestedColumnType>().At(0))>;
154150

155151
ArrayValueView(std::shared_ptr<NestedColumnType> data, size_t offset = 0, size_t size = std::numeric_limits<size_t>::max())
156152
: typed_nested_data_(data)
@@ -175,14 +171,16 @@ class ColumnArrayT : public ColumnArray {
175171
const size_t size_;
176172
size_t index_;
177173
public:
174+
Iterator() = default;
175+
178176
Iterator(std::shared_ptr<NestedColumnType> typed_nested_data, size_t offset, size_t size, size_t index)
179177
: typed_nested_data_(typed_nested_data)
180178
, offset_(offset)
181179
, size_(size)
182180
, index_(index)
183181
{}
184182

185-
using ValueType = typename NestedColumnType::ValueType;
183+
using ValueType = typename ArrayValueView::ValueType;
186184

187185
inline auto operator*() const {
188186
return typed_nested_data_->At(offset_ + index_);
@@ -230,6 +228,22 @@ class ColumnArrayT : public ColumnArray {
230228
inline size_t Size() const {
231229
return size_;
232230
}
231+
232+
inline bool operator==(const ArrayValueView& other) const {
233+
if (size() != other.size()) {
234+
return false;
235+
}
236+
for (size_t i = 0; i < size_; ++i) {
237+
if ((*this)[i] != other[i]) {
238+
return false;
239+
}
240+
}
241+
return true;
242+
}
243+
244+
inline bool operator!=(const ArrayValueView& other) const {
245+
return !(*this == other);
246+
}
233247
};
234248

235249
inline auto At(size_t index) const {
@@ -262,7 +276,7 @@ class ColumnArrayT : public ColumnArray {
262276
size_t counter = 0;
263277

264278
while (begin != end) {
265-
nested_data.Append(*begin);
279+
nested_data.Append(std::move(*begin));
266280
++begin;
267281
++counter;
268282
}
@@ -271,6 +285,20 @@ class ColumnArrayT : public ColumnArray {
271285
AddOffset(counter);
272286
}
273287

288+
ColumnRef Slice(size_t begin, size_t size) const override {
289+
return Wrap(ColumnArray::Slice(begin, size));
290+
}
291+
292+
ColumnRef CloneEmpty() const override {
293+
return Wrap(ColumnArray::CloneEmpty());
294+
}
295+
296+
void Swap(Column& other) override {
297+
auto & col = dynamic_cast<ColumnArrayT<NestedColumnType> &>(other);
298+
typed_nested_data_.swap(col.typed_nested_data_);
299+
ColumnArray::Swap(other);
300+
}
301+
274302
private:
275303
/// Helper to allow wrapping a "typeless" ColumnArray
276304
ColumnArrayT(ColumnArray&& array, std::shared_ptr<NestedColumnType> nested_data)

0 commit comments

Comments
 (0)