Skip to content

Commit 56c265e

Browse files
committed
Resolve comments
1 parent 470259d commit 56c265e

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/iceberg/expression/literal.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Result<Literal> LiteralCaster::CastFromInt(
7777
return Literal::Double(static_cast<double>(int_val));
7878
default:
7979
return NotSupported("Cast from Int to {} is not implemented",
80-
static_cast<int>(target_type_id));
80+
target_type->ToString());
8181
}
8282
}
8383

@@ -103,7 +103,7 @@ Result<Literal> LiteralCaster::CastFromLong(
103103
return Literal::Double(static_cast<double>(long_val));
104104
default:
105105
return NotSupported("Cast from Long to {} is not supported",
106-
static_cast<int>(target_type_id));
106+
target_type->ToString());
107107
}
108108
}
109109

@@ -117,7 +117,7 @@ Result<Literal> LiteralCaster::CastFromFloat(
117117
return Literal::Double(static_cast<double>(float_val));
118118
default:
119119
return NotSupported("Cast from Float to {} is not supported",
120-
static_cast<int>(target_type_id));
120+
target_type->ToString());
121121
}
122122
}
123123

@@ -175,21 +175,21 @@ Result<Literal> Literal::CastTo(const std::shared_ptr<PrimitiveType>& target_typ
175175
// Template function for floating point comparison following Iceberg rules:
176176
// -NaN < NaN, but all NaN values (qNaN, sNaN) are treated as equivalent within their sign
177177
template <std::floating_point T>
178-
std::partial_ordering iceberg_float_compare(T lhs, T rhs) {
178+
std::strong_ordering CompareFloat(T lhs, T rhs) {
179+
// If both are NaN, check their signs
179180
bool lhs_is_nan = std::isnan(lhs);
180181
bool rhs_is_nan = std::isnan(rhs);
181-
182-
// If both are NaN, check their signs
183182
if (lhs_is_nan && rhs_is_nan) {
184183
bool lhs_is_negative = std::signbit(lhs);
185184
bool rhs_is_negative = std::signbit(rhs);
186185

187186
if (lhs_is_negative == rhs_is_negative) {
188187
// Same sign NaN values are equivalent (no qNaN vs sNaN distinction)
189-
return std::partial_ordering::equivalent;
188+
return std::strong_ordering::equivalent;
190189
}
191190
// -NaN < NaN
192-
return lhs_is_negative ? std::partial_ordering::less : std::partial_ordering::greater;
191+
return lhs_is_negative ? std::strong_ordering::less
192+
: std::strong_ordering::greater;
193193
}
194194

195195
// For non-NaN values, use standard strong ordering
@@ -233,14 +233,14 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
233233
auto this_val = std::get<float>(value_);
234234
auto other_val = std::get<float>(other.value_);
235235
// Use strong_ordering for floating point as spec requests
236-
return iceberg_float_compare(this_val, other_val);
236+
return CompareFloat(this_val, other_val);
237237
}
238238

239239
case TypeId::kDouble: {
240240
auto this_val = std::get<double>(value_);
241241
auto other_val = std::get<double>(other.value_);
242242
// Use strong_ordering for floating point as spec requests
243-
return iceberg_float_compare(this_val, other_val);
243+
return CompareFloat(this_val, other_val);
244244
}
245245

246246
case TypeId::kString: {
@@ -263,10 +263,10 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
263263

264264
std::string Literal::ToString() const {
265265
if (std::holds_alternative<BelowMin>(value_)) {
266-
return "BelowMin";
266+
return "belowMin";
267267
}
268268
if (std::holds_alternative<AboveMax>(value_)) {
269-
return "AboveMax";
269+
return "aboveMax";
270270
}
271271

272272
switch (type_->type_id()) {
@@ -293,7 +293,7 @@ std::string Literal::ToString() const {
293293
std::string result;
294294
result.reserve(binary_data.size() * 2); // 2 chars per byte
295295
for (const auto& byte : binary_data) {
296-
result += std::format("{:02X}", byte);
296+
std::format_to(std::back_inserter(result), "{:02X}", byte);
297297
}
298298
return result;
299299
}

test/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ target_link_libraries(catalog_test PRIVATE iceberg_static GTest::gtest_main GTes
5050
add_test(NAME catalog_test COMMAND catalog_test)
5151

5252
add_executable(expression_test)
53-
target_sources(expression_test PRIVATE expression_test.cc)
53+
target_sources(expression_test PRIVATE expression_test.cc literal_test.cc)
5454
target_link_libraries(expression_test PRIVATE iceberg_static GTest::gtest_main
5555
GTest::gmock)
5656
add_test(NAME expression_test COMMAND expression_test)
@@ -69,11 +69,6 @@ target_sources(util_test PRIVATE expected_test.cc formatter_test.cc config_test.
6969
target_link_libraries(util_test PRIVATE iceberg_static GTest::gtest_main GTest::gmock)
7070
add_test(NAME util_test COMMAND util_test)
7171

72-
add_executable(literal_test)
73-
target_sources(literal_test PRIVATE literal_test.cc)
74-
target_link_libraries(literal_test PRIVATE iceberg_static GTest::gtest_main GTest::gmock)
75-
add_test(NAME literal_test COMMAND literal_test)
76-
7772
if(ICEBERG_BUILD_BUNDLE)
7873
add_executable(avro_test)
7974
target_sources(avro_test PRIVATE avro_test.cc avro_schema_test.cc avro_stream_test.cc)

0 commit comments

Comments
 (0)