Skip to content

Commit 662e5c7

Browse files
committed
fix
1 parent 2cb617e commit 662e5c7

5 files changed

Lines changed: 37 additions & 51 deletions

File tree

src/iceberg/expression/literal.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "iceberg/util/macros.h"
3030
#include "iceberg/util/date_time_util.h"
3131
#include "iceberg/type_fwd.h"
32+
#include "iceberg/util/checked_cast.h"
3233
#include "iceberg/util/macros.h"
3334

3435
namespace iceberg {
@@ -239,7 +240,7 @@ Result<Literal> LiteralCaster::CastFromBinary(
239240
auto binary_val = std::get<std::vector<uint8_t>>(literal.value_);
240241
switch (target_type->type_id()) {
241242
case TypeId::kFixed: {
242-
auto target_fixed_type = std::static_pointer_cast<FixedType>(target_type);
243+
auto target_fixed_type = internal::checked_pointer_cast<FixedType>(target_type);
243244
if (binary_val.size() == target_fixed_type->length()) {
244245
return Literal::Fixed(std::move(binary_val));
245246
}
@@ -412,13 +413,6 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
412413
}
413414

414415
std::string Literal::ToString() const {
415-
auto unsupported_error = [this]() {
416-
return std::format("ToString not supported for type: {}", type_->ToString());
417-
};
418-
auto invalid_argument = [this]() {
419-
return std::format("Invalid argument for type: {}", type_->ToString());
420-
};
421-
422416
if (std::holds_alternative<BelowMin>(value_)) {
423417
return "belowMin";
424418
}
@@ -468,7 +462,7 @@ std::string Literal::ToString() const {
468462
return std::to_string(std::get<int32_t>(value_));
469463
}
470464
default: {
471-
return unsupported_error();
465+
return std::format("invalid literal of type {}", type_->ToString());
472466
}
473467
}
474468
}

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, LongCastToIntOverflow) {
@@ -163,19 +161,19 @@ TEST(LiteralTest, LongCastToIntOverflow) {
163161
auto min_long =
164162
Literal::Long(static_cast<int64_t>(std::numeric_limits<int32_t>::min()) - 1);
165163

166-
auto max_result = max_long.CastTo(iceberg::int32());
164+
auto max_result = max_long.CastTo(int32());
167165
ASSERT_THAT(max_result, IsOk());
168166
EXPECT_TRUE(max_result->IsAboveMax());
169167

170-
auto min_result = min_long.CastTo(iceberg::int32());
168+
auto min_result = min_long.CastTo(int32());
171169
ASSERT_THAT(min_result, IsOk());
172170
EXPECT_TRUE(min_result->IsBelowMin());
173171

174-
max_result = max_long.CastTo(iceberg::date());
172+
max_result = max_long.CastTo(date());
175173
ASSERT_THAT(max_result, IsOk());
176174
EXPECT_TRUE(max_result->IsAboveMax());
177175

178-
min_result = min_long.CastTo(iceberg::date());
176+
min_result = min_long.CastTo(date());
179177
ASSERT_THAT(min_result, IsOk());
180178
EXPECT_TRUE(min_result->IsBelowMin());
181179
}
@@ -206,8 +204,7 @@ TEST(LiteralTest, FloatCastTo) {
206204
auto float_literal = Literal::Float(2.0f);
207205

208206
// Cast to Double
209-
AssertCastSucceeds(float_literal.CastTo(iceberg::float64()), TypeId::kDouble,
210-
static_cast<double>(2.0f));
207+
AssertCastSucceeds(float_literal.CastTo(float64()), TypeId::kDouble, double{2.0f});
211208
}
212209

213210
// Double type tests
@@ -236,21 +233,19 @@ TEST(LiteralTest, DoubleCastTo) {
236233
auto double_literal = Literal::Double(2.0);
237234

238235
// Cast to Float
239-
AssertCastSucceeds(double_literal.CastTo(iceberg::float32()), TypeId::kFloat, 2.0f);
236+
AssertCastSucceeds(double_literal.CastTo(float32()), TypeId::kFloat, 2.0f);
240237
}
241238

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

249-
auto max_result = max_double.CastTo(iceberg::float32());
244+
auto max_result = max_double.CastTo(float32());
250245
ASSERT_THAT(max_result, IsOk());
251246
EXPECT_TRUE(max_result->IsAboveMax());
252247

253-
auto min_result = min_double.CastTo(iceberg::float32());
248+
auto min_result = min_double.CastTo(float32());
254249
ASSERT_THAT(min_result, IsOk());
255250
EXPECT_TRUE(min_result->IsBelowMin());
256251
}
@@ -309,11 +304,10 @@ TEST(LiteralTest, BinaryCastTo) {
309304
auto binary_literal = Literal::Binary(data4);
310305

311306
// Cast to Fixed with matching length
312-
AssertCastSucceeds(binary_literal.CastTo(iceberg::fixed(4)), TypeId::kFixed, data4);
307+
AssertCastSucceeds(binary_literal.CastTo(fixed(4)), TypeId::kFixed, data4);
313308

314309
// Cast to Fixed with different length should fail
315-
EXPECT_THAT(binary_literal.CastTo(iceberg::fixed(5)),
316-
IsError(ErrorKind::kInvalidArgument));
310+
EXPECT_THAT(binary_literal.CastTo(fixed(5)), IsError(ErrorKind::kInvalidArgument));
317311
}
318312

319313
// Fixed type tests
@@ -348,13 +342,13 @@ TEST(LiteralTest, FixedCastTo) {
348342
auto fixed_literal = Literal::Fixed(data4);
349343

350344
// Cast to Binary
351-
AssertCastSucceeds(fixed_literal.CastTo(iceberg::binary()), TypeId::kBinary, data4);
345+
AssertCastSucceeds(fixed_literal.CastTo(binary()), TypeId::kBinary, data4);
352346

353347
// Cast to Fixed with same length
354-
AssertCastSucceeds(fixed_literal.CastTo(iceberg::fixed(4)), TypeId::kFixed, data4);
348+
AssertCastSucceeds(fixed_literal.CastTo(fixed(4)), TypeId::kFixed, data4);
355349

356350
// Cast to Fixed with different length should fail
357-
EXPECT_THAT(fixed_literal.CastTo(iceberg::fixed(5)), IsError(ErrorKind::kNotSupported));
351+
EXPECT_THAT(fixed_literal.CastTo(fixed(5)), IsError(ErrorKind::kNotSupported));
358352
}
359353

360354
// Date type tests
@@ -460,7 +454,7 @@ TEST(LiteralTest, CrossTypeComparison) {
460454
TEST(LiteralTest, SameTypeCast) {
461455
auto int_literal = Literal::Int(42);
462456

463-
AssertCastSucceeds(int_literal.CastTo(iceberg::int32()), TypeId::kInt, 42);
457+
AssertCastSucceeds(int_literal.CastTo(int32()), TypeId::kInt, 42);
464458
}
465459

466460
// 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)