File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 22
22
#include < cmath>
23
23
#include < concepts>
24
24
25
- #include < iceberg/result.h>
26
-
27
25
#include " iceberg/exception.h"
28
26
29
27
namespace iceberg {
@@ -284,8 +282,7 @@ Result<Literal> LiteralCaster::CastFromFixed(
284
282
}
285
283
case TypeId::kFixed : {
286
284
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 ()) {
289
286
return literal;
290
287
}
291
288
return NotSupported (" Cannot cast Fixed({}) to Fixed({}) due to mismatched lengths" ,
@@ -468,11 +465,12 @@ std::string Literal::ToString() const {
468
465
case TypeId::kString : {
469
466
return std::get<std::string>(value_);
470
467
}
471
- case TypeId::kBinary : {
468
+ case TypeId::kBinary :
469
+ case TypeId::kFixed : {
472
470
const auto & binary_data = std::get<std::vector<uint8_t >>(value_);
473
471
std::string result = " X'" ;
474
472
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
476
474
for (const auto & byte : binary_data) {
477
475
std::format_to (std::back_inserter (result), " {:02X}" , byte);
478
476
}
@@ -488,8 +486,7 @@ std::string Literal::ToString() const {
488
486
return std::to_string (std::get<int32_t >(value_));
489
487
}
490
488
case TypeId::kDecimal :
491
- case TypeId::kUuid :
492
- case TypeId::kFixed : {
489
+ case TypeId::kUuid : {
493
490
throw IcebergError (" Not implemented: ToString for " + type_->ToString ());
494
491
}
495
492
default : {
Original file line number Diff line number Diff line change @@ -325,6 +325,9 @@ TEST(LiteralTest, FixedBasics) {
325
325
326
326
EXPECT_EQ (fixed_literal.type ()->type_id (), TypeId::kFixed );
327
327
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''" );
328
331
}
329
332
330
333
TEST (LiteralTest, FixedComparison) {
You can’t perform that action at this time.
0 commit comments