Skip to content

Commit 0abbf84

Browse files
committed
fix
1 parent 6bcd33b commit 0abbf84

File tree

5 files changed

+37
-51
lines changed

5 files changed

+37
-51
lines changed

src/iceberg/expression/literal.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <string>
2626

2727
#include "iceberg/type_fwd.h"
28+
#include "iceberg/util/checked_cast.h"
2829
#include "iceberg/util/macros.h"
2930

3031
namespace iceberg {
@@ -235,7 +236,7 @@ Result<Literal> LiteralCaster::CastFromBinary(
235236
auto binary_val = std::get<std::vector<uint8_t>>(literal.value_);
236237
switch (target_type->type_id()) {
237238
case TypeId::kFixed: {
238-
auto target_fixed_type = std::static_pointer_cast<FixedType>(target_type);
239+
auto target_fixed_type = internal::checked_pointer_cast<FixedType>(target_type);
239240
if (binary_val.size() == target_fixed_type->length()) {
240241
return Literal::Fixed(std::move(binary_val));
241242
}
@@ -402,13 +403,6 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
402403
}
403404

404405
std::string Literal::ToString() const {
405-
auto unsupported_error = [this]() {
406-
return std::format("ToString not supported for type: {}", type_->ToString());
407-
};
408-
auto invalid_argument = [this]() {
409-
return std::format("Invalid argument for type: {}", type_->ToString());
410-
};
411-
412406
if (std::holds_alternative<BelowMin>(value_)) {
413407
return "belowMin";
414408
}
@@ -458,7 +452,7 @@ std::string Literal::ToString() const {
458452
return std::to_string(std::get<int32_t>(value_));
459453
}
460454
default: {
461-
return unsupported_error();
455+
return std::format("invalid literal of type {}", type_->ToString());
462456
}
463457
}
464458
}

src/iceberg/expression/literal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ICEBERG_EXPORT Literal : public util::Formattable {
5757
double, // for double
5858
std::string, // for string
5959
std::vector<uint8_t>, // for binary, fixed
60-
std::array<uint8_t, 16>, // for uuid
60+
std::array<uint8_t, 16>, // for uuid and decimal
6161
BelowMin, AboveMax>;
6262

6363
/// \brief Factory methods for primitive types

src/iceberg/expression/predicate.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ std::string UnboundPredicate<B>::ToString() const {
100100
return values_.size() == 1 ? std::format("{} != {}", term, values_[0])
101101
: invalid_predicate_string(op);
102102
case Expression::Operation::kStartsWith:
103-
return values_.size() == 1 ? std::format("{} startsWith \"{}\"", term, values_[0])
103+
return values_.size() == 1 ? std::format("{} startsWith {}", term, values_[0])
104104
: invalid_predicate_string(op);
105105
case Expression::Operation::kNotStartsWith:
106-
return values_.size() == 1
107-
? std::format("{} notStartsWith \"{}\"", term, values_[0])
108-
: invalid_predicate_string(op);
106+
return values_.size() == 1 ? std::format("{} notStartsWith {}", term, values_[0])
107+
: invalid_predicate_string(op);
109108
case Expression::Operation::kIn:
110109
return std::format("{} in {}", term, values_);
111110
case Expression::Operation::kNotIn:

src/iceberg/test/literal_test.cc

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ template <typename T>
3838
void AssertCastSucceeds(const Result<Literal>& result, TypeId expected_type_id,
3939
const T& expected_value) {
4040
ASSERT_THAT(result, IsOk());
41-
EXPECT_EQ(result->type()->type_id(), expected_type_id);
42-
ASSERT_NO_THROW(EXPECT_EQ(std::get<T>(result->value()), expected_value))
41+
ASSERT_EQ(result->type()->type_id(), expected_type_id);
42+
EXPECT_EQ(std::get<T>(result->value()), expected_value)
4343
<< "Type mismatch in std::get. Expected type for TypeId "
4444
<< static_cast<int>(expected_type_id);
4545
}
@@ -94,17 +94,17 @@ TEST(LiteralTest, IntCastTo) {
9494
auto int_literal = Literal::Int(42);
9595

9696
// Cast to Long
97-
AssertCastSucceeds(int_literal.CastTo(iceberg::int64()), TypeId::kLong,
97+
AssertCastSucceeds(int_literal.CastTo(int64()), TypeId::kLong,
9898
static_cast<int64_t>(42));
9999

100100
// Cast to Float
101-
AssertCastSucceeds(int_literal.CastTo(iceberg::float32()), TypeId::kFloat, 42.0f);
101+
AssertCastSucceeds(int_literal.CastTo(float32()), TypeId::kFloat, 42.0f);
102102

103103
// Cast to Double
104-
AssertCastSucceeds(int_literal.CastTo(iceberg::float64()), TypeId::kDouble, 42.0);
104+
AssertCastSucceeds(int_literal.CastTo(float64()), TypeId::kDouble, 42.0);
105105

106106
// Cast to Date
107-
AssertCastSucceeds(int_literal.CastTo(iceberg::date()), TypeId::kDate, 42);
107+
AssertCastSucceeds(int_literal.CastTo(date()), TypeId::kDate, 42);
108108
}
109109

110110
// Long type tests
@@ -133,28 +133,26 @@ TEST(LiteralTest, LongCastTo) {
133133
auto long_literal = Literal::Long(42L);
134134

135135
// Cast to Int (within range)
136-
AssertCastSucceeds(long_literal.CastTo(iceberg::int32()), TypeId::kInt, 42);
136+
AssertCastSucceeds(long_literal.CastTo(int32()), TypeId::kInt, 42);
137137

138138
// Cast to Float
139-
AssertCastSucceeds(long_literal.CastTo(iceberg::float32()), TypeId::kFloat, 42.0f);
139+
AssertCastSucceeds(long_literal.CastTo(float32()), TypeId::kFloat, 42.0f);
140140

141141
// Cast to Double
142-
AssertCastSucceeds(long_literal.CastTo(iceberg::float64()), TypeId::kDouble, 42.0);
142+
AssertCastSucceeds(long_literal.CastTo(float64()), TypeId::kDouble, 42.0);
143143

144144
// Cast to Date
145-
AssertCastSucceeds(long_literal.CastTo(iceberg::date()), TypeId::kDate, 42);
145+
AssertCastSucceeds(long_literal.CastTo(date()), TypeId::kDate, 42);
146146

147147
// Cast to Time
148-
AssertCastSucceeds(long_literal.CastTo(iceberg::time()), TypeId::kTime,
149-
static_cast<int64_t>(42));
148+
AssertCastSucceeds(long_literal.CastTo(time()), TypeId::kTime, int64_t{42});
150149

151150
// Cast to Timestamp
152-
AssertCastSucceeds(long_literal.CastTo(iceberg::timestamp()), TypeId::kTimestamp,
153-
static_cast<int64_t>(42));
151+
AssertCastSucceeds(long_literal.CastTo(timestamp()), TypeId::kTimestamp, int64_t{42});
154152

155153
// Cast to TimestampTz
156-
AssertCastSucceeds(long_literal.CastTo(iceberg::timestamp_tz()), TypeId::kTimestampTz,
157-
static_cast<int64_t>(42));
154+
AssertCastSucceeds(long_literal.CastTo(timestamp_tz()), TypeId::kTimestampTz,
155+
int64_t{42});
158156
}
159157

160158
TEST(LiteralTest, LongCastToOverflow) {
@@ -164,19 +162,19 @@ TEST(LiteralTest, LongCastToOverflow) {
164162
auto min_long =
165163
Literal::Long(static_cast<int64_t>(std::numeric_limits<int32_t>::min()) - 1);
166164

167-
auto max_result = max_long.CastTo(iceberg::int32());
165+
auto max_result = max_long.CastTo(int32());
168166
ASSERT_THAT(max_result, IsOk());
169167
EXPECT_TRUE(max_result->IsAboveMax());
170168

171-
auto min_result = min_long.CastTo(iceberg::int32());
169+
auto min_result = min_long.CastTo(int32());
172170
ASSERT_THAT(min_result, IsOk());
173171
EXPECT_TRUE(min_result->IsBelowMin());
174172

175-
max_result = max_long.CastTo(iceberg::date());
173+
max_result = max_long.CastTo(date());
176174
ASSERT_THAT(max_result, IsOk());
177175
EXPECT_TRUE(max_result->IsAboveMax());
178176

179-
min_result = min_long.CastTo(iceberg::date());
177+
min_result = min_long.CastTo(date());
180178
ASSERT_THAT(min_result, IsOk());
181179
EXPECT_TRUE(min_result->IsBelowMin());
182180
}
@@ -207,8 +205,7 @@ TEST(LiteralTest, FloatCastTo) {
207205
auto float_literal = Literal::Float(2.0f);
208206

209207
// Cast to Double
210-
AssertCastSucceeds(float_literal.CastTo(iceberg::float64()), TypeId::kDouble,
211-
static_cast<double>(2.0f));
208+
AssertCastSucceeds(float_literal.CastTo(float64()), TypeId::kDouble, double{2.0f});
212209
}
213210

214211
// Double type tests
@@ -237,21 +234,19 @@ TEST(LiteralTest, DoubleCastTo) {
237234
auto double_literal = Literal::Double(2.0);
238235

239236
// Cast to Float
240-
AssertCastSucceeds(double_literal.CastTo(iceberg::float32()), TypeId::kFloat, 2.0f);
237+
AssertCastSucceeds(double_literal.CastTo(float32()), TypeId::kFloat, 2.0f);
241238
}
242239

243240
TEST(LiteralTest, DoubleCastToOverflow) {
244241
// Test overflow cases for Double to Float
245-
auto max_double =
246-
Literal::Double(static_cast<double>(std::numeric_limits<float>::max()) * 2);
247-
auto min_double =
248-
Literal::Double(-static_cast<double>(std::numeric_limits<float>::max()) * 2);
242+
auto max_double = Literal::Double(double{std::numeric_limits<float>::max()} * 2);
243+
auto min_double = Literal::Double(-double{std::numeric_limits<float>::max()} * 2);
249244

250-
auto max_result = max_double.CastTo(iceberg::float32());
245+
auto max_result = max_double.CastTo(float32());
251246
ASSERT_THAT(max_result, IsOk());
252247
EXPECT_TRUE(max_result->IsAboveMax());
253248

254-
auto min_result = min_double.CastTo(iceberg::float32());
249+
auto min_result = min_double.CastTo(float32());
255250
ASSERT_THAT(min_result, IsOk());
256251
EXPECT_TRUE(min_result->IsBelowMin());
257252
}
@@ -310,11 +305,10 @@ TEST(LiteralTest, BinaryCastTo) {
310305
auto binary_literal = Literal::Binary(data4);
311306

312307
// Cast to Fixed with matching length
313-
AssertCastSucceeds(binary_literal.CastTo(iceberg::fixed(4)), TypeId::kFixed, data4);
308+
AssertCastSucceeds(binary_literal.CastTo(fixed(4)), TypeId::kFixed, data4);
314309

315310
// Cast to Fixed with different length should fail
316-
EXPECT_THAT(binary_literal.CastTo(iceberg::fixed(5)),
317-
IsError(ErrorKind::kInvalidArgument));
311+
EXPECT_THAT(binary_literal.CastTo(fixed(5)), IsError(ErrorKind::kInvalidArgument));
318312
}
319313

320314
// Fixed type tests
@@ -349,13 +343,13 @@ TEST(LiteralTest, FixedCastTo) {
349343
auto fixed_literal = Literal::Fixed(data4);
350344

351345
// Cast to Binary
352-
AssertCastSucceeds(fixed_literal.CastTo(iceberg::binary()), TypeId::kBinary, data4);
346+
AssertCastSucceeds(fixed_literal.CastTo(binary()), TypeId::kBinary, data4);
353347

354348
// Cast to Fixed with same length
355-
AssertCastSucceeds(fixed_literal.CastTo(iceberg::fixed(4)), TypeId::kFixed, data4);
349+
AssertCastSucceeds(fixed_literal.CastTo(fixed(4)), TypeId::kFixed, data4);
356350

357351
// Cast to Fixed with different length should fail
358-
EXPECT_THAT(fixed_literal.CastTo(iceberg::fixed(5)), IsError(ErrorKind::kNotSupported));
352+
EXPECT_THAT(fixed_literal.CastTo(fixed(5)), IsError(ErrorKind::kNotSupported));
359353
}
360354

361355
// Date type tests
@@ -461,7 +455,7 @@ TEST(LiteralTest, CrossTypeComparison) {
461455
TEST(LiteralTest, SameTypeCast) {
462456
auto int_literal = Literal::Int(42);
463457

464-
AssertCastSucceeds(int_literal.CastTo(iceberg::int32()), TypeId::kInt, 42);
458+
AssertCastSucceeds(int_literal.CastTo(int32()), TypeId::kInt, 42);
465459
}
466460

467461
// Special value tests

src/iceberg/transform_function.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include "iceberg/expression/literal.h"
2929
#include "iceberg/type.h"
30-
#include "iceberg/util/int128.h"
3130
#include "iceberg/util/murmurhash3_internal.h"
3231
#include "iceberg/util/truncate_util.h"
3332

0 commit comments

Comments
 (0)