Skip to content

Commit a4b5dde

Browse files
committed
fix: remove unrelated codes
1 parent 78a6517 commit a4b5dde

File tree

4 files changed

+21
-63
lines changed

4 files changed

+21
-63
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ set(ICEBERG_INCLUDES "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
2020
set(ICEBERG_SOURCES
2121
arrow_c_data_internal.cc
2222
catalog/in_memory_catalog.cc
23-
util/decimal.cc
2423
expression/expression.cc
2524
expression/literal.cc
2625
file_reader.cc

src/iceberg/util/decimal.cc

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,17 @@
2424

2525
#include "iceberg/util/decimal.h"
2626

27-
#include <algorithm>
2827
#include <array>
2928
#include <bit>
3029
#include <cassert>
3130
#include <charconv>
3231
#include <climits>
3332
#include <cmath>
34-
#include <cstddef>
3533
#include <cstdint>
3634
#include <cstring>
3735
#include <format>
3836
#include <iomanip>
39-
#include <iostream>
4037
#include <limits>
41-
#include <ostream>
4238
#include <sstream>
4339
#include <string>
4440
#include <string_view>
@@ -427,11 +423,11 @@ std::string Decimal::ToIntegerString() const {
427423
Result<Decimal> Decimal::FromString(std::string_view str, int32_t* precision,
428424
int32_t* scale) {
429425
if (str.empty()) {
430-
return InvalidArgument("Decimal::FromString: empty string is not a valid Decimal");
426+
return InvalidArgument("Empty string is not a valid Decimal");
431427
}
432428
DecimalComponents dec;
433429
if (!ParseDecimalComponents(str, &dec)) {
434-
return InvalidArgument("Decimal::FromString: invalid decimal string '{}'", str);
430+
return InvalidArgument("Invalid decimal string '{}'", str);
435431
}
436432

437433
// Count number of significant digits (without leading zeros)
@@ -451,8 +447,6 @@ Result<Decimal> Decimal::FromString(std::string_view str, int32_t* precision,
451447
parsed_scale = static_cast<int32_t>(dec.fractional_digits.size());
452448
}
453449

454-
// Index 1 is the high part, index 0 is the low part
455-
std::array<uint64_t, 2> result_array = {0, 0};
456450
uint128_t value = 0;
457451
ShiftAndAdd(dec.while_digits, value);
458452
ShiftAndAdd(dec.fractional_digits, value);
@@ -466,9 +460,8 @@ Result<Decimal> Decimal::FromString(std::string_view str, int32_t* precision,
466460
// For the scale to 0, to avoid negative scales (due to compatibility issues with
467461
// external systems such as databases)
468462
if (parsed_scale < -kMaxScale) {
469-
return InvalidArgument(
470-
"Decimal::FromString: scale must be in the range [-{}, {}], was {}", kMaxScale,
471-
kMaxScale, parsed_scale);
463+
return InvalidArgument("scale must be in the range [-{}, {}], was {}", kMaxScale,
464+
kMaxScale, parsed_scale);
472465
}
473466

474467
result *= kDecimal128PowersOfTen[-parsed_scale];
@@ -552,8 +545,6 @@ struct RealTraits<float> {
552545
static constexpr const float* powers_of_ten() { return kFloatPowersOfTen.data(); }
553546

554547
static constexpr float two_to_64(float x) { return x * 1.8446744e+19f; }
555-
static constexpr float two_to_128(float x) { return x == 0 ? 0 : kFloatInf; }
556-
static constexpr float two_to_192(float x) { return x == 0 ? 0 : kFloatInf; }
557548

558549
static constexpr int32_t kMantissaBits = 24;
559550
// ceil(log10(2 ^ kMantissaBits))
@@ -567,8 +558,6 @@ struct RealTraits<double> {
567558
static constexpr const double* powers_of_ten() { return kDoublePowersOfTen.data(); }
568559

569560
static constexpr double two_to_64(double x) { return x * 1.8446744073709552e+19; }
570-
static constexpr double two_to_128(double x) { return x * 3.402823669209385e+38; }
571-
static constexpr double two_to_192(double x) { return x * 6.277101735386681e+57; }
572561

573562
static constexpr int32_t kMantissaBits = 53;
574563
// ceil(log10(2 ^ kMantissaBits))
@@ -791,7 +780,7 @@ struct DecimalRealConversion {
791780
return x;
792781
}
793782

794-
/// An approximate conversion from Decimal128 to Real that guarantees:
783+
/// An approximate conversion from Decimal to Real that guarantees:
795784
/// 1. If the decimal is an integer, the conversion is exact.
796785
/// 2. If the number of fractional digits is <= RealTraits<Real>::kMantissaDigits (e.g.
797786
/// 8 for float and 16 for double), the conversion is within 1 ULP of the exact
@@ -864,7 +853,7 @@ static inline uint64_t UInt64FromBigEndian(const uint8_t* bytes, int32_t length)
864853
// Using memcpy instead of special casing for length
865854
// and doing the conversion in 16, 32 parts, which could
866855
// possibly create unaligned memory access on certain platforms
867-
memcpy(reinterpret_cast<uint8_t*>(&result) + 8 - length, bytes, length);
856+
std::memcpy(reinterpret_cast<uint8_t*>(&result) + 8 - length, bytes, length);
868857

869858
if constexpr (std::endian::native == std::endian::little) {
870859
return std::byteswap(result);
@@ -1008,7 +997,7 @@ double Decimal::ToDouble(int32_t scale) const {
1008997

1009998
std::array<uint8_t, Decimal::kByteWidth> Decimal::ToBytes() const {
1010999
std::array<uint8_t, kByteWidth> out{{0}};
1011-
memcpy(out.data(), &data_, kByteWidth);
1000+
std::memcpy(out.data(), &data_, kByteWidth);
10121001
return out;
10131002
}
10141003

src/iceberg/util/decimal.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,27 +257,9 @@ class ICEBERG_EXPORT Decimal {
257257
friend Decimal operator%(const Decimal& lhs, const Decimal& rhs);
258258

259259
private:
260-
static constexpr int32_t highIndex() {
261-
if constexpr (std::endian::native == std::endian::little) {
262-
return 1;
263-
} else {
264-
return 0;
265-
}
266-
}
267-
268-
static constexpr int32_t lowIndex() {
269-
if constexpr (std::endian::native == std::endian::little) {
270-
return 0;
271-
} else {
272-
return 1;
273-
}
274-
}
275-
276260
int128_t data_{0};
277261
};
278262

279263
ICEBERG_EXPORT std::ostream& operator<<(std::ostream& os, const Decimal& decimal);
280264

281-
// Unary operators
282-
283265
} // namespace iceberg

test/decimal_test.cc

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
#include <bit>
2424
#include <cmath>
2525
#include <cstdint>
26-
#include <vector>
2726

2827
#include <gmock/gmock.h>
2928
#include <gtest/gtest.h>
30-
#include <sys/types.h>
3129

3230
#include "iceberg/util/int128.h"
3331
#include "matchers.h"
@@ -48,11 +46,6 @@ void AssertDecimalFromString(const std::string& s, const Decimal& expected,
4846
EXPECT_EQ(expected_scale, scale);
4947
}
5048

51-
Decimal DecimalFromInt128(int128_t value) {
52-
return {static_cast<int64_t>(value >> 64),
53-
static_cast<uint64_t>(value & 0xFFFFFFFFFFFFFFFFULL)};
54-
}
55-
5649
} // namespace
5750

5851
TEST(DecimalTest, Basics) {
@@ -279,23 +272,21 @@ TEST(DecimalTest, FromStringInvalid) {
279272
// Empty string
280273
auto result = Decimal::FromString("");
281274
ASSERT_THAT(result, IsError(ErrorKind::kInvalidArgument));
282-
ASSERT_THAT(result, HasErrorMessage(
283-
"Decimal::FromString: empty string is not a valid Decimal"));
275+
ASSERT_THAT(result, HasErrorMessage("Empty string is not a valid Decimal"));
284276
for (const auto& invalid_string :
285277
std::vector<std::string>{"-", "0.0.0", "0-13-32", "a", "-23092.235-",
286278
"-+23092.235", "+-23092.235", "00a", "1e1a", "0.00123D/3",
287279
"1.23eA8", "1.23E+3A", "-1.23E--5", "1.2345E+++07"}) {
288280
auto result = Decimal::FromString(invalid_string);
289281
ASSERT_THAT(result, IsError(ErrorKind::kInvalidArgument));
290-
ASSERT_THAT(result, HasErrorMessage("Decimal::FromString: invalid decimal string"));
282+
ASSERT_THAT(result, HasErrorMessage("Invalid decimal string"));
291283
}
292284

293285
for (const auto& invalid_string :
294286
std::vector<std::string>{"1e39", "-1e39", "9e39", "-9e39", "9.9e40", "-9.9e40"}) {
295287
auto result = Decimal::FromString(invalid_string);
296288
ASSERT_THAT(result, IsError(ErrorKind::kInvalidArgument));
297-
ASSERT_THAT(result,
298-
HasErrorMessage("Decimal::FromString: scale must be in the range"));
289+
ASSERT_THAT(result, HasErrorMessage("scale must be in the range"));
299290
}
300291
}
301292

@@ -1094,11 +1085,10 @@ TEST(DecimalTestFunctionality, Multiply) {
10941085
for (auto x : std::vector<int128_t>{-INT64_MAX, -INT32_MAX, 0, INT32_MAX, INT64_MAX}) {
10951086
for (auto y :
10961087
std::vector<int128_t>{-INT32_MAX, -32, -2, -1, 0, 1, 2, 32, INT32_MAX}) {
1097-
Decimal decimal_x = DecimalFromInt128(x);
1098-
Decimal decimal_y = DecimalFromInt128(y);
1088+
Decimal decimal_x(x);
1089+
Decimal decimal_y(y);
10991090
Decimal result = decimal_x * decimal_y;
1100-
EXPECT_EQ(DecimalFromInt128(x * y), result)
1101-
<< " x: " << decimal_x << " y: " << decimal_y;
1091+
EXPECT_EQ(Decimal(x * y), result) << " x: " << decimal_x << " y: " << decimal_y;
11021092
}
11031093
}
11041094
}
@@ -1111,11 +1101,10 @@ TEST(DecimalTestFunctionality, Divide) {
11111101

11121102
for (auto x : std::vector<int128_t>{-INT64_MAX, -INT32_MAX, 0, INT32_MAX, INT64_MAX}) {
11131103
for (auto y : std::vector<int128_t>{-INT32_MAX, -32, -2, -1, 1, 2, 32, INT32_MAX}) {
1114-
Decimal decimal_x = DecimalFromInt128(x);
1115-
Decimal decimal_y = DecimalFromInt128(y);
1104+
Decimal decimal_x(x);
1105+
Decimal decimal_y(y);
11161106
Decimal result = decimal_x / decimal_y;
1117-
EXPECT_EQ(DecimalFromInt128(x / y), result)
1118-
<< " x: " << decimal_x << " y: " << decimal_y;
1107+
EXPECT_EQ(Decimal(x / y), result) << " x: " << decimal_x << " y: " << decimal_y;
11191108
}
11201109
}
11211110
}
@@ -1129,11 +1118,10 @@ TEST(DecimalTestFunctionality, Modulo) {
11291118
// Test some edge cases
11301119
for (auto x : std::vector<int128_t>{-INT64_MAX, -INT32_MAX, 0, INT32_MAX, INT64_MAX}) {
11311120
for (auto y : std::vector<int128_t>{-INT32_MAX, -32, -2, -1, 1, 2, 32, INT32_MAX}) {
1132-
Decimal decimal_x = DecimalFromInt128(x);
1133-
Decimal decimal_y = DecimalFromInt128(y);
1121+
Decimal decimal_x(x);
1122+
Decimal decimal_y(y);
11341123
Decimal result = decimal_x % decimal_y;
1135-
EXPECT_EQ(DecimalFromInt128(x % y), result)
1136-
<< " x: " << decimal_x << " y: " << decimal_y;
1124+
EXPECT_EQ(Decimal(x % y), result) << " x: " << decimal_x << " y: " << decimal_y;
11371125
}
11381126
}
11391127
}
@@ -1206,8 +1194,8 @@ TEST(DecimalTestFunctionality, FitsInPrecision) {
12061194

12071195
TEST(DecimalTest, LeftShift) {
12081196
auto check = [](int128_t x, uint32_t bits) {
1209-
auto expected = DecimalFromInt128(x << bits);
1210-
auto actual = DecimalFromInt128(x) << bits;
1197+
auto expected = Decimal(x << bits);
1198+
auto actual = Decimal(x) << bits;
12111199
ASSERT_EQ(actual.low(), expected.low());
12121200
ASSERT_EQ(actual.high(), expected.high());
12131201
};

0 commit comments

Comments
 (0)