Skip to content

Commit bf03ba0

Browse files
committed
Allow clients that lack absl to built and use the library
Moved Int128 definition to a separate header Added few extra methods to ColumnDecimal that do not rely on Int128 Ensured that client programs can be built without absl headers present.
1 parent 1415b59 commit bf03ba0

File tree

16 files changed

+77
-21
lines changed

16 files changed

+77
-21
lines changed

.travis.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ before_install: |
4949
fi
5050
5151
# Build steps
52-
script:
53-
- eval "${MATRIX_EVAL}"
54-
- mkdir build
55-
- cd build
56-
- cmake .. -DBUILD_TESTS=ON && make
57-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./ut/clickhouse-cpp-ut ; fi
58-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter=-"Client/*:*Performance*" ; fi
52+
script: |
53+
eval "${MATRIX_EVAL}"
54+
mkdir build
55+
cd build
56+
cmake .. -DBUILD_TESTS=ON && cmake --build . --target all
57+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./ut/clickhouse-cpp-ut ; fi
58+
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter=-"Client/*:*Performance*" ; fi
59+
# Test clients that do not have absl in the system still can be built
60+
cmake --build . --target install . && cmake --build . --target clean
61+
cd ./tests/simple && mkdir build && cd ./build
62+
cmake .. -DBUILD_SAMPLE_WITH_INT128=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON && cmake --build . --target all

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ PROJECT (CLICKHOUSE-CLIENT)
1010

1111
USE_CXX17()
1212

13-
IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
14-
set(CMAKE_BUILD_TYPE "Debug")
15-
ENDIF()
13+
IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
14+
set(CMAKE_BUILD_TYPE "Debug")
15+
ENDIF()
1616

1717
IF (UNIX)
1818
IF (APPLE)
@@ -43,4 +43,4 @@ PROJECT (CLICKHOUSE-CLIENT)
4343
tests/simple
4444
ut
4545
)
46-
ENDIF (BUILD_TESTS)
46+
ENDIF (BUILD_TESTS)

clickhouse/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ INSTALL(FILES columns/uuid.h DESTINATION include/clickhouse/columns/)
100100
# types
101101
INSTALL(FILES types/type_parser.h DESTINATION include/clickhouse/types/)
102102
INSTALL(FILES types/types.h DESTINATION include/clickhouse/types/)
103+
INSTALL(FILES types/int128.h DESTINATION include/clickhouse/types/)

clickhouse/columns/date.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "date.h"
22

3+
#include "../types/int128.h"
4+
35
namespace clickhouse {
46

57
ColumnDate::ColumnDate()

clickhouse/columns/decimal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "decimal.h"
22

3+
#include "../types/int128.h"
4+
35
namespace
46
{
57
using namespace clickhouse;
@@ -117,6 +119,10 @@ ColumnDecimal::ColumnDecimal(TypeRef type, ColumnRef data)
117119
{
118120
}
119121

122+
void ColumnDecimal::Append(Int64 value) {
123+
Append(static_cast<Int128>(value));
124+
}
125+
120126
void ColumnDecimal::Append(const Int128& value) {
121127
if (data_->Type()->GetCode() == Type::Int32) {
122128
data_->As<ColumnInt32>()->Append(static_cast<ColumnInt32::DataType>(value));
@@ -191,6 +197,10 @@ Int128 ColumnDecimal::At(size_t i) const {
191197
}
192198
}
193199

200+
Int64 ColumnDecimal::AtAsInt64(size_t i) const {
201+
return static_cast<Int64>(At(i));
202+
}
203+
194204
void ColumnDecimal::Append(ColumnRef column) {
195205
if (auto col = column->As<ColumnDecimal>()) {
196206
data_->Append(col->data_);

clickhouse/columns/decimal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ class ColumnDecimal : public Column {
1212
public:
1313
ColumnDecimal(size_t precision, size_t scale);
1414

15+
void Append(Int64 value); /// When Int128 is not supported by\not available to users.
1516
void Append(const Int128& value);
1617
void Append(const std::string& value);
1718

1819
Int128 At(size_t i) const;
20+
Int64 AtAsInt64(size_t i) const; /// result will overflow if value doesn't fit into Int64.
1921

2022
public:
2123
void Append(ColumnRef column) override;

clickhouse/columns/factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "uuid.h"
1717

1818
#include "../types/type_parser.h"
19+
#include "../types/int128.h"
1920

2021
#include <stdexcept>
2122

clickhouse/columns/numeric.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "numeric.h"
22
#include "utils.h"
33

4+
#include "../types/int128.h"
5+
46
namespace clickhouse {
57

68
template <typename T>

clickhouse/columns/numeric.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#pragma once
22

33
#include "column.h"
4-
#include "absl/numeric/int128.h"
4+
5+
namespace absl
6+
{
7+
class int128;
8+
}
59

610
namespace clickhouse {
711

clickhouse/types/int128.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
/// In a separate header to allow basic non-Int128 functionality on systems that lack absl.
4+
#include <absl/numeric/int128.h>
5+
6+
namespace clickhouse
7+
{
8+
using Int128 = absl::int128;
9+
}

0 commit comments

Comments
 (0)