Skip to content

Commit 636e323

Browse files
committed
tmp
1 parent d9359fb commit 636e323

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(ICEBERG_SOURCES
5050
manifest_writer.cc
5151
arrow_c_data_guard_internal.cc
5252
util/decimal.cc
53+
util/gzip_internal.cc
5354
util/murmurhash3_internal.cc
5455
util/timepoint.cc)
5556

src/iceberg/expression/literal.cc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
#include <concepts>
2323
#include <cstdint>
24+
#include <string>
2425

2526
#include "iceberg/exception.h"
27+
#include "iceberg/type_fwd.h"
2628

2729
namespace iceberg {
2830

@@ -294,6 +296,15 @@ Literal Literal::Fixed(std::vector<uint8_t> value) {
294296
return {Value{std::move(value)}, fixed(size)};
295297
}
296298

299+
Literal Literal::Decimal(const iceberg::Decimal& value, int32_t precision,
300+
int32_t scale) {
301+
return {Value{value.value()}, decimal(precision, scale)};
302+
}
303+
304+
Literal Literal::Decimal(int128_t value, int32_t precision, int32_t scale) {
305+
return {Value{value}, decimal(precision, scale)};
306+
}
307+
297308
Result<Literal> Literal::Deserialize(std::span<const uint8_t> data,
298309
std::shared_ptr<PrimitiveType> type) {
299310
return NotImplemented("Deserialization of Literal is not implemented yet");
@@ -403,6 +414,8 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
403414
}
404415

405416
std::string Literal::ToString() const {
417+
auto invalid_ = [this]() { return std::format(" = {}", type_->ToString()); };
418+
406419
if (std::holds_alternative<BelowMin>(value_)) {
407420
return "belowMin";
408421
}
@@ -452,9 +465,20 @@ std::string Literal::ToString() const {
452465
case TypeId::kDate: {
453466
return std::to_string(std::get<int32_t>(value_));
454467
}
455-
case TypeId::kDecimal:
468+
case TypeId::kDecimal: {
469+
const auto unscaled_value = std::get<int128_t>(value_);
470+
auto decimal_type = std::static_pointer_cast<DecimalType>(type_);
471+
int32_t scale = decimal_type->scale();
472+
473+
iceberg::Decimal decimal_val(unscaled_value);
474+
Result<std::string> str_res = decimal_val.ToString(scale);
475+
if (str_res.has_value()) {
476+
return str_res.value();
477+
}
478+
return
479+
}
456480
case TypeId::kUuid: {
457-
throw NotImplemented("kDecimal and kUuid are not implemented yet");
481+
return {"kDecimal and kUuid are not implemented yet"};
458482
}
459483
default: {
460484
throw IcebergError("Unknown type: " + type_->ToString());

src/iceberg/expression/literal.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "iceberg/result.h"
2929
#include "iceberg/type.h"
30+
#include "iceberg/util/decimal.h"
31+
#include "iceberg/util/int128.h"
3032

3133
namespace iceberg {
3234

@@ -56,7 +58,8 @@ class ICEBERG_EXPORT Literal {
5658
double, // for double
5759
std::string, // for string
5860
std::vector<uint8_t>, // for binary, fixed
59-
std::array<uint8_t, 16>, // for uuid and decimal
61+
std::array<uint8_t, 16>, // for uuid
62+
int128_t, // for decimal
6063
BelowMin, AboveMax>;
6164

6265
/// \brief Factory methods for primitive types
@@ -73,6 +76,10 @@ class ICEBERG_EXPORT Literal {
7376
static Literal Binary(std::vector<uint8_t> value);
7477
static Literal Fixed(std::vector<uint8_t> value);
7578

79+
/// \brief Factory methods for decimal type
80+
static Literal Decimal(const Decimal& value, int32_t precision, int32_t scale);
81+
static Literal Decimal(int128_t value, int32_t precision, int32_t scale);
82+
7683
/// \brief Create a literal representing a null value.
7784
static Literal Null(std::shared_ptr<PrimitiveType> type) {
7885
return {Value{std::monostate{}}, std::move(type)};
@@ -139,7 +146,7 @@ class ICEBERG_EXPORT Literal {
139146
/// \return true if this literal is null, false otherwise
140147
bool IsNull() const;
141148

142-
std::string ToString() const;
149+
Result<std::string> ToString() const;
143150

144151
private:
145152
Literal(Value value, std::shared_ptr<PrimitiveType> type);

0 commit comments

Comments
 (0)