Skip to content

Commit cc53825

Browse files
committed
cpp11 compatible int128
1 parent eb19440 commit cc53825

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PROJECT (CLICKHOUSE-CLIENT)
2929
SUBDIRS (
3030
clickhouse
3131
contrib/cityhash
32+
contrib/abseil-cpp
3233
contrib/lz4
3334
)
3435

clickhouse/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ SET_TARGET_PROPERTIES(clickhouse-cpp-lib PROPERTIES LINKER_LANGUAGE CXX)
3232
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib
3333
cityhash-lib
3434
lz4-lib
35+
absl::numeric
36+
absl::strings
3537
)
3638

3739
ADD_LIBRARY (clickhouse-cpp-lib-static STATIC ${clickhouse-cpp-lib-src})
3840
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
3941
cityhash-lib
4042
lz4-lib
43+
absl::numeric
44+
absl::strings
4145
)
4246

4347
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

clickhouse/columns/decimal.cpp

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

3+
#include <absl/strings/numbers.h>
34
#include <iostream>
45

56
namespace clickhouse {
@@ -61,10 +62,13 @@ void ColumnDecimal::Append(const std::string& value) {
6162

6263
has_dot = true;
6364
} else if (*c >= '0' && *c <= '9') {
64-
if (__builtin_mul_overflow(int_value, 10, &int_value) ||
65-
__builtin_add_overflow(int_value, *c - '0', &int_value)) {
66-
throw std::runtime_error("value is too big for 128-bit integer");
67-
}
65+
int_value *= 10;
66+
int_value += *c - '0';
67+
// TODO: check overflows
68+
//if (__builtin_mul_overflow(int_value, 10, &int_value) ||
69+
// __builtin_add_overflow(int_value, *c - '0', &int_value)) {
70+
// throw std::runtime_error("value is too big for 128-bit integer");
71+
//}
6872
} else {
6973
throw std::runtime_error(std::string("unexpected symbol '") + (*c) + "' in decimal value");
7074
}
@@ -76,9 +80,11 @@ void ColumnDecimal::Append(const std::string& value) {
7680
}
7781

7882
while (zeros) {
79-
if (__builtin_mul_overflow(int_value, 10, &int_value)) {
80-
throw std::runtime_error("value is too big for 128-bit integer");
81-
}
83+
int_value *= 10;
84+
// TODO: check overflows
85+
//if (__builtin_mul_overflow(int_value, 10, &int_value)) {
86+
// throw std::runtime_error("value is too big for 128-bit integer");
87+
//}
8288
--zeros;
8389
}
8490

clickhouse/columns/numeric.h

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

3+
#include <absl/numeric/int128.h>
34
#include "column.h"
45

56
namespace clickhouse {
@@ -48,7 +49,7 @@ class ColumnVector : public Column {
4849
std::vector<T> data_;
4950
};
5051

51-
using Int128 = __int128;
52+
using Int128 = absl::int128;
5253

5354
using ColumnUInt8 = ColumnVector<uint8_t>;
5455
using ColumnUInt16 = ColumnVector<uint16_t>;

clickhouse/types/types.h

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

3+
#include <absl/numeric/int128.h>
4+
35
#include <map>
46
#include <memory>
57
#include <string>
68
#include <vector>
79

810
namespace clickhouse {
911

12+
using Int128 = absl::int128;
1013
using TypeRef = std::shared_ptr<class Type>;
1114

1215
class Type {
@@ -200,7 +203,7 @@ inline TypeRef Type::CreateSimple<int64_t>() {
200203
}
201204

202205
template <>
203-
inline TypeRef Type::CreateSimple<__int128>() {
206+
inline TypeRef Type::CreateSimple<Int128>() {
204207
return TypeRef(new Type(Int128));
205208
}
206209

0 commit comments

Comments
 (0)