Skip to content

Commit 1663f19

Browse files
committed
fix
1 parent 24bec46 commit 1663f19

File tree

5 files changed

+16
-30
lines changed

5 files changed

+16
-30
lines changed

src/iceberg/expression/literal.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "iceberg/util/conversions.h"
2828
#include "iceberg/exception.h"
2929
#include "iceberg/type_fwd.h"
30+
#include "iceberg/util/checked_cast.h"
3031
#include "iceberg/util/macros.h"
3132

3233
namespace iceberg {
@@ -237,7 +238,7 @@ Result<Literal> LiteralCaster::CastFromBinary(
237238
auto binary_val = std::get<std::vector<uint8_t>>(literal.value_);
238239
switch (target_type->type_id()) {
239240
case TypeId::kFixed: {
240-
auto target_fixed_type = std::static_pointer_cast<FixedType>(target_type);
241+
auto target_fixed_type = internal::checked_pointer_cast<FixedType>(target_type);
241242
if (binary_val.size() == target_fixed_type->length()) {
242243
return Literal::Fixed(std::move(binary_val));
243244
}
@@ -404,13 +405,6 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
404405
}
405406

406407
std::string Literal::ToString() const {
407-
auto unsupported_error = [this]() {
408-
return std::format("ToString not supported for type: {}", type_->ToString());
409-
};
410-
auto invalid_argument = [this]() {
411-
return std::format("Invalid argument for type: {}", type_->ToString());
412-
};
413-
414408
if (std::holds_alternative<BelowMin>(value_)) {
415409
return "belowMin";
416410
}
@@ -460,7 +454,7 @@ std::string Literal::ToString() const {
460454
return std::to_string(std::get<int32_t>(value_));
461455
}
462456
default: {
463-
return unsupported_error();
457+
return std::format("invalid literal of type {}", type_->ToString());
464458
}
465459
}
466460
}

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: 9 additions & 15 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
}
@@ -145,16 +145,14 @@ TEST(LiteralTest, LongCastTo) {
145145
AssertCastSucceeds(long_literal.CastTo(date()), TypeId::kDate, 42);
146146

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

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

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

160158
TEST(LiteralTest, LongCastToOverflow) {
@@ -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(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
@@ -242,10 +239,8 @@ TEST(LiteralTest, DoubleCastTo) {
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

250245
auto max_result = max_double.CastTo(float32());
251246
ASSERT_THAT(max_result, IsOk());
@@ -313,8 +308,7 @@ TEST(LiteralTest, BinaryCastTo) {
313308
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(fixed(5)),
317-
IsError(ErrorKind::kInvalidArgument));
311+
EXPECT_THAT(binary_literal.CastTo(fixed(5)), IsError(ErrorKind::kInvalidArgument));
318312
}
319313

320314
// Fixed type 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)