Skip to content

Commit

Permalink
Merge branch 'master' into SparceColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
Enmk authored Dec 16, 2022
2 parents 5ae4fa1 + 4251535 commit 4ed6037
Show file tree
Hide file tree
Showing 35 changed files with 1,246 additions and 53 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Linux

on:
schedule:
- cron: '0 0 * * 1'
push:
branches: [ master ]
pull_request:
Expand All @@ -12,7 +14,7 @@ env:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
compiler: [clang-6, gcc-7, gcc-8, gcc-9]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: macOS

on:
schedule:
- cron: '0 0 * * 1'
push:
branches: [ master ]
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows_mingw.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Windows mingw

on:
schedule:
- cron: '0 0 * * 1'
push:
branches: [ master ]
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows_msvc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Windows

on:
schedule:
- cron: '0 0 * * 1'
push:
branches: [ master ]
pull_request:
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ PROJECT (CLICKHOUSE-CLIENT)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-declarations")
ENDIF ()

INCLUDE_DIRECTORIES (.)
INCLUDE_DIRECTORIES (contrib)

SUBDIRS (
clickhouse
contrib/absl
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ C++ client for [ClickHouse](https://clickhouse.com/).
* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
* Int128
* UUID
* Map
* Point, Ring, Polygon, MultiPolygon

## Building

Expand Down Expand Up @@ -87,7 +89,7 @@ int main()

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

See https://github.com/ClickHouse/clickhouse-cpp/issues/184 for details.
1 change: 1 addition & 0 deletions bench/bench.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <benchmark/benchmark.h>

#include <clickhouse/client.h>
#include <ut/utils.h>

namespace clickhouse {

Expand Down
11 changes: 11 additions & 0 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ SET ( clickhouse-cpp-lib-src
columns/decimal.cpp
columns/enum.cpp
columns/factory.cpp
columns/geo.cpp
columns/ip4.cpp
columns/ip6.cpp
columns/lowcardinality.cpp
columns/lowcardinalityadaptor.h
columns/nullable.cpp
columns/numeric.cpp
columns/serialization.cpp
columns/map.cpp
columns/string.cpp
columns/tuple.cpp
columns/uuid.cpp
Expand All @@ -44,13 +46,19 @@ TARGET_LINK_LIBRARIES (clickhouse-cpp-lib
cityhash-lib
lz4-lib
)
TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib
PUBLIC ${PROJECT_SOURCE_DIR}
)

ADD_LIBRARY (clickhouse-cpp-lib-static STATIC ${clickhouse-cpp-lib-src})
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
absl-lib
cityhash-lib
lz4-lib
)
TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib-static
PUBLIC ${PROJECT_SOURCE_DIR}
)

IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
INCLUDE (CheckCXXSourceCompiles)
Expand Down Expand Up @@ -96,6 +104,7 @@ INSTALL(FILES base/input.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/open_telemetry.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/output.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/platform.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/projected_iterator.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/singleton.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/socket.h DESTINATION include/clickhouse/base/)
INSTALL(FILES base/string_utils.h DESTINATION include/clickhouse/base/)
Expand All @@ -110,13 +119,15 @@ INSTALL(FILES columns/date.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/decimal.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/enum.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/factory.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/geo.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/itemview.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/serialization.h DESTINATION include/clickhouse/columns/)
INSTALL(FILES columns/map.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/)
Expand Down
55 changes: 55 additions & 0 deletions clickhouse/base/projected_iterator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include <iterator>
#include <type_traits>
#include <utility>

namespace clickhouse {

template <typename UnaryFunction, typename Iterator, typename Reference = decltype(std::declval<UnaryFunction>()(std::declval<Iterator>())),
typename Value = std::decay_t<Reference>>
class ProjectedIterator {
public:
using value_type = Value;
using reference = Reference;
using pointer = Reference;
using difference_type = typename std::iterator_traits<Iterator>::difference_type;
using iterator_category = typename std::iterator_traits<Iterator>::iterator_category;

ProjectedIterator() = default;

inline ProjectedIterator(Iterator const& iterator, UnaryFunction functor)
: iterator_(iterator)
, functor_(std::move(functor)) {
}

inline UnaryFunction functor() const { return functor; }

inline Iterator const& base() const { return iterator_; }

inline reference operator*() const { return functor_(iterator_); }

inline ProjectedIterator& operator++() {
++iterator_;
return *this;
}

inline ProjectedIterator& operator--() {
--iterator_;
return *this;
}

inline bool operator==(const ProjectedIterator& other) const {
return this->iterator_ == other.iterator_;
}

inline bool operator!=(const ProjectedIterator& other) const {
return !(*this == other);
}

private:
Iterator iterator_;
UnaryFunction functor_;
};

} // namespace clickhouse
4 changes: 3 additions & 1 deletion clickhouse/base/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ template <
typename TChar,
typename TTraits = std::char_traits<TChar>
>
class StringViewImpl {
class
[[deprecated("Obsolete due to C++17's std::string_view. Will be removed in next major release (3.0) ")]]
StringViewImpl {
public:
using size_type = size_t;
using traits_type = TTraits;
Expand Down
6 changes: 4 additions & 2 deletions clickhouse/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#include "columns/date.h"
#include "columns/decimal.h"
#include "columns/enum.h"
#include "columns/geo.h"
#include "columns/ip4.h"
#include "columns/ip6.h"
#include "columns/lowcardinality.h"
#include "columns/nullable.h"
#include "columns/numeric.h"
#include "columns/map.h"
#include "columns/string.h"
#include "columns/tuple.h"
#include "columns/uuid.h"
Expand Down Expand Up @@ -87,8 +89,8 @@ struct ClientOptions {
DECLARE_FIELD(tcp_nodelay, bool, TcpNoDelay, true);

/// Connection socket timeout. If the timeout is set to zero then the operation will never timeout.
DECLARE_FIELD(connection_recv_timeout, std::chrono::seconds, SetConnectionRecvTimeout, std::chrono::seconds(0));
DECLARE_FIELD(connection_send_timeout, std::chrono::seconds, SetConnectionSendTimeout, std::chrono::seconds(0));
DECLARE_FIELD(connection_recv_timeout, std::chrono::milliseconds, SetConnectionRecvTimeout, std::chrono::milliseconds(0));
DECLARE_FIELD(connection_send_timeout, std::chrono::milliseconds, SetConnectionSendTimeout, std::chrono::milliseconds(0));

/** It helps to ease migration of the old codebases, which can't afford to switch
* to using ColumnLowCardinalityT or ColumnLowCardinality directly,
Expand Down
48 changes: 38 additions & 10 deletions clickhouse/columns/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "column.h"
#include "numeric.h"
#include "utils.h"

#include <memory>

Expand Down Expand Up @@ -125,13 +126,8 @@ class ColumnArrayT : public ColumnArray {
* This is a static method to make such conversion verbose.
*/
static auto Wrap(ColumnArray&& col) {
if constexpr (std::is_base_of_v<ColumnArray, NestedColumnType> && !std::is_same_v<ColumnArray, NestedColumnType>) {
// assuming NestedColumnType is ArrayT specialization
return std::make_shared<ColumnArrayT<NestedColumnType>>(NestedColumnType::Wrap(col.GetData()), col.offsets_);
} else {
auto nested_data = col.GetData()->template AsStrict<NestedColumnType>();
return std::make_shared<ColumnArrayT<NestedColumnType>>(nested_data, col.offsets_);
}
auto nested_data = WrapColumn<NestedColumnType>(col.GetData());
return std::make_shared<ColumnArrayT<NestedColumnType>>(nested_data, col.offsets_);
}

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

public:
using ValueType = typename NestedColumnType::ValueType;
using ValueType = std::decay_t<decltype(std::declval<NestedColumnType>().At(0))>;

ArrayValueView(std::shared_ptr<NestedColumnType> data, size_t offset = 0, size_t size = std::numeric_limits<size_t>::max())
: typed_nested_data_(data)
Expand All @@ -175,14 +171,16 @@ class ColumnArrayT : public ColumnArray {
const size_t size_;
size_t index_;
public:
Iterator() = default;

Iterator(std::shared_ptr<NestedColumnType> typed_nested_data, size_t offset, size_t size, size_t index)
: typed_nested_data_(typed_nested_data)
, offset_(offset)
, size_(size)
, index_(index)
{}

using ValueType = typename NestedColumnType::ValueType;
using ValueType = typename ArrayValueView::ValueType;

inline auto operator*() const {
return typed_nested_data_->At(offset_ + index_);
Expand Down Expand Up @@ -230,6 +228,22 @@ class ColumnArrayT : public ColumnArray {
inline size_t Size() const {
return size_;
}

inline bool operator==(const ArrayValueView& other) const {
if (size() != other.size()) {
return false;
}
for (size_t i = 0; i < size_; ++i) {
if ((*this)[i] != other[i]) {
return false;
}
}
return true;
}

inline bool operator!=(const ArrayValueView& other) const {
return !(*this == other);
}
};

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

while (begin != end) {
nested_data.Append(*begin);
nested_data.Append(std::move(*begin));
++begin;
++counter;
}
Expand All @@ -271,6 +285,20 @@ class ColumnArrayT : public ColumnArray {
AddOffset(counter);
}

ColumnRef Slice(size_t begin, size_t size) const override {
return Wrap(ColumnArray::Slice(begin, size));
}

ColumnRef CloneEmpty() const override {
return Wrap(ColumnArray::CloneEmpty());
}

void Swap(Column& other) override {
auto & col = dynamic_cast<ColumnArrayT<NestedColumnType> &>(other);
typed_nested_data_.swap(col.typed_nested_data_);
ColumnArray::Swap(other);
}

private:
/// Helper to allow wrapping a "typeless" ColumnArray
ColumnArrayT(ColumnArray&& array, std::shared_ptr<NestedColumnType> nested_data)
Expand Down
Loading

0 comments on commit 4ed6037

Please sign in to comment.