Skip to content

Commit 4c0766a

Browse files
committed
fix: use concepts to limit TTruncateInteger to int32_t and int64_t
1 parent f4d4f5d commit 4c0766a

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/iceberg/expression/literal.cc

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <cmath>
2323
#include <concepts>
24-
#include <sstream>
2524

2625
#include "iceberg/exception.h"
2726

@@ -126,33 +125,28 @@ Literal::Literal(Value value, std::shared_ptr<PrimitiveType> type)
126125
: value_(std::move(value)), type_(std::move(type)) {}
127126

128127
// Factory methods
128+
Literal Literal::Boolean(bool value) { return {Value{value}, boolean()}; }
129129

130-
Literal Literal::Boolean(bool value) { return {Value{value}, iceberg::boolean()}; }
130+
Literal Literal::Int(int32_t value) { return {Value{value}, int32()}; }
131131

132-
Literal Literal::Int(int32_t value) { return {Value{value}, iceberg::int32()}; }
132+
Literal Literal::Date(int32_t value) { return {Value{value}, date()}; }
133133

134-
Literal Literal::Date(int32_t value) { return {Value{value}, iceberg::date()}; }
134+
Literal Literal::Long(int64_t value) { return {Value{value}, int64()}; }
135135

136-
Literal Literal::Long(int64_t value) { return {Value{value}, iceberg::int64()}; }
136+
Literal Literal::Time(int64_t value) { return {Value{value}, time()}; }
137137

138-
Literal Literal::Time(int64_t value) { return {Value{value}, iceberg::time()}; }
138+
Literal Literal::Timestamp(int64_t value) { return {Value{value}, timestamp()}; }
139139

140-
Literal Literal::Timestamp(int64_t value) { return {Value{value}, iceberg::timestamp()}; }
140+
Literal Literal::TimestampTz(int64_t value) { return {Value{value}, timestamp_tz()}; }
141141

142-
Literal Literal::TimestampTz(int64_t value) {
143-
return {Value{value}, iceberg::timestamp_tz()};
144-
}
145-
146-
Literal Literal::Float(float value) { return {Value{value}, iceberg::float32()}; }
142+
Literal Literal::Float(float value) { return {Value{value}, float32()}; }
147143

148-
Literal Literal::Double(double value) { return {Value{value}, iceberg::float64()}; }
144+
Literal Literal::Double(double value) { return {Value{value}, float64()}; }
149145

150-
Literal Literal::String(std::string value) {
151-
return {Value{std::move(value)}, iceberg::string()};
152-
}
146+
Literal Literal::String(std::string value) { return {Value{std::move(value)}, string()}; }
153147

154148
Literal Literal::Binary(std::vector<uint8_t> value) {
155-
return {Value{std::move(value)}, iceberg::binary()};
149+
return {Value{std::move(value)}, binary()};
156150
}
157151

158152
Result<Literal> Literal::Deserialize(std::span<const uint8_t> data,

src/iceberg/util/truncate_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ICEBERG_EXPORT class TruncateUtils {
6363
/// The remainder, v % W, must be positive. For languages where % can produce negative
6464
/// values, the correct truncate function is: v - (((v % W) + W) % W)
6565
template <typename T>
66+
requires std::is_same_v<T, int32_t> || std::is_same_v<T, int64_t>
6667
static inline T TruncateInteger(T v, size_t W) {
6768
return v - (((v % W) + W) % W);
6869
}

0 commit comments

Comments
 (0)