Skip to content

Commit b599a7a

Browse files
committed
fmt
1 parent b98cdd4 commit b599a7a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/iceberg/expression/literal.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <cmath>
2323
#include <concepts>
2424

25-
#include <iceberg/result.h>
26-
2725
#include "iceberg/exception.h"
2826

2927
namespace iceberg {
@@ -284,8 +282,7 @@ Result<Literal> LiteralCaster::CastFromFixed(
284282
}
285283
case TypeId::kFixed: {
286284
auto target_fixed_type = std::dynamic_pointer_cast<FixedType>(target_type);
287-
if (fixed_val.size() ==
288-
target_fixed_type->length()) { // 长度匹配,可以认为是同类型转换,直接返回自身
285+
if (fixed_val.size() == target_fixed_type->length()) {
289286
return literal;
290287
}
291288
return NotSupported("Cannot cast Fixed({}) to Fixed({}) due to mismatched lengths",
@@ -468,11 +465,12 @@ std::string Literal::ToString() const {
468465
case TypeId::kString: {
469466
return std::get<std::string>(value_);
470467
}
471-
case TypeId::kBinary: {
468+
case TypeId::kBinary:
469+
case TypeId::kFixed: {
472470
const auto& binary_data = std::get<std::vector<uint8_t>>(value_);
473471
std::string result = "X'";
474472
result.reserve(2 + binary_data.size() * 2 +
475-
1); // 2 for X' + 2 chars per byte + 1 for '
473+
1); // 2 chars per byte and 2 + 1 for prefix and suffix
476474
for (const auto& byte : binary_data) {
477475
std::format_to(std::back_inserter(result), "{:02X}", byte);
478476
}
@@ -488,8 +486,7 @@ std::string Literal::ToString() const {
488486
return std::to_string(std::get<int32_t>(value_));
489487
}
490488
case TypeId::kDecimal:
491-
case TypeId::kUuid:
492-
case TypeId::kFixed: {
489+
case TypeId::kUuid: {
493490
throw IcebergError("Not implemented: ToString for " + type_->ToString());
494491
}
495492
default: {

test/literal_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ TEST(LiteralTest, FixedBasics) {
325325

326326
EXPECT_EQ(fixed_literal.type()->type_id(), TypeId::kFixed);
327327
EXPECT_EQ(empty_fixed.type()->type_id(), TypeId::kFixed);
328+
329+
EXPECT_EQ(fixed_literal.ToString(), "X'010203FF'");
330+
EXPECT_EQ(empty_fixed.ToString(), "X''");
328331
}
329332

330333
TEST(LiteralTest, FixedComparison) {

0 commit comments

Comments
 (0)