Skip to content

Commit 94bf9dd

Browse files
committed
feat: Literal adapt Uuid representation
1 parent 24176f6 commit 94bf9dd

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/iceberg/expression/literal.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ Literal Literal::Double(double value) { return {Value{value}, float64()}; }
145145

146146
Literal Literal::String(std::string value) { return {Value{std::move(value)}, string()}; }
147147

148+
Literal Literal::UUID(Uuid value) { return {Value{std::move(value)}, uuid()}; }
149+
148150
Literal Literal::Binary(std::vector<uint8_t> value) {
149151
return {Value{std::move(value)}, binary()};
150152
}
@@ -285,6 +287,9 @@ std::string Literal::ToString() const {
285287
case TypeId::kString: {
286288
return std::get<std::string>(value_);
287289
}
290+
case TypeId::kUuid: {
291+
return std::get<Uuid>(value_).ToString();
292+
}
288293
case TypeId::kBinary: {
289294
const auto& binary_data = std::get<std::vector<uint8_t>>(value_);
290295
std::string result;
@@ -295,7 +300,6 @@ std::string Literal::ToString() const {
295300
return result;
296301
}
297302
case TypeId::kDecimal:
298-
case TypeId::kUuid:
299303
case TypeId::kFixed:
300304
case TypeId::kDate:
301305
case TypeId::kTime:

src/iceberg/expression/literal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "iceberg/result.h"
2929
#include "iceberg/type.h"
30+
#include "iceberg/util/uuid.h"
3031

3132
namespace iceberg {
3233

@@ -55,8 +56,9 @@ class ICEBERG_EXPORT Literal {
5556
float, // for float
5657
double, // for double
5758
std::string, // for string
59+
Uuid, // for uuid
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 decimal
6062
BelowMin, AboveMax>;
6163

6264
/// \brief Factory methods for primitive types
@@ -70,6 +72,7 @@ class ICEBERG_EXPORT Literal {
7072
static Literal Float(float value);
7173
static Literal Double(double value);
7274
static Literal String(std::string value);
75+
static Literal UUID(Uuid value);
7376
static Literal Binary(std::vector<uint8_t> value);
7477

7578
/// \brief Create a literal representing a null value.

src/iceberg/test/literal_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ TEST(LiteralTest, StringBasics) {
217217
EXPECT_EQ(empty_string.ToString(), "");
218218
}
219219

220+
// Uuid type tests
221+
TEST(LiteralTest, UuidBasics) {
222+
auto uuid = Uuid::FromString("123e4567-e89b-12d3-a456-426614174000").value();
223+
auto uuid_literal = Literal::UUID(uuid);
224+
225+
EXPECT_EQ(uuid_literal.type()->type_id(), TypeId::kUuid);
226+
EXPECT_EQ(uuid_literal.ToString(), "123e4567-e89b-12d3-a456-426614174000");
227+
}
228+
220229
TEST(LiteralTest, StringComparison) {
221230
auto string1 = Literal::String("apple");
222231
auto string2 = Literal::String("banana");

src/iceberg/transform_function.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "iceberg/type.h"
3030
#include "iceberg/util/murmurhash3_internal.h"
3131
#include "iceberg/util/truncate_util.h"
32+
#include "iceberg/util/uuid.h"
3233

3334
namespace iceberg {
3435

@@ -75,6 +76,9 @@ Result<Literal> BucketTransform::Transform(const Literal& literal) {
7576
MurmurHash3_x86_32(value.data(), sizeof(uint8_t) * 16, 0, &hash_value);
7677
} else if constexpr (std::is_same_v<T, std::string>) {
7778
MurmurHash3_x86_32(value.data(), value.size(), 0, &hash_value);
79+
} else if constexpr (std::is_same_v<T, Uuid>) {
80+
MurmurHash3_x86_32(std::get<Uuid>(literal.value()).bytes().data(),
81+
Uuid::kLength, 0, &hash_value);
7882
} else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
7983
MurmurHash3_x86_32(value.data(), value.size(), 0, &hash_value);
8084
} else if constexpr (std::is_same_v<T, std::monostate> ||

0 commit comments

Comments
 (0)