Skip to content

Commit 71d5f11

Browse files
committed
feat: implement literal expressions with binary serialization support
1 parent b7fadf5 commit 71d5f11

File tree

13 files changed

+904
-66
lines changed

13 files changed

+904
-66
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ set(ICEBERG_SOURCES
5050
arrow_c_data_guard_internal.cc
5151
util/murmurhash3_internal.cc
5252
util/timepoint.cc
53-
util/gzip_internal.cc)
53+
util/gzip_internal.cc
54+
util/conversions.cc
55+
util/literal_format.cc)
5456

5557
set(ICEBERG_STATIC_BUILD_INTERFACE_LIBS)
5658
set(ICEBERG_SHARED_BUILD_INTERFACE_LIBS)

src/iceberg/expression/literal.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <concepts>
2424

2525
#include "iceberg/exception.h"
26+
#include "iceberg/util/conversions.h"
27+
#include "iceberg/util/literal_format.h"
2628

2729
namespace iceberg {
2830

@@ -151,11 +153,11 @@ Literal Literal::Binary(std::vector<uint8_t> value) {
151153

152154
Result<Literal> Literal::Deserialize(std::span<const uint8_t> data,
153155
std::shared_ptr<PrimitiveType> type) {
154-
return NotImplemented("Deserialization of Literal is not implemented yet");
156+
return Conversions::FromBytes(type, data);
155157
}
156158

157159
Result<std::vector<uint8_t>> Literal::Serialize() const {
158-
return NotImplemented("Serialization of Literal is not implemented yet");
160+
return Conversions::ToBytes(*this);
159161
}
160162

161163
// Getters

src/iceberg/expression/literal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ class ICEBERG_EXPORT Literal {
144144
Literal(Value value, std::shared_ptr<PrimitiveType> type);
145145

146146
friend class LiteralCaster;
147+
friend class Conversions;
147148

148-
private:
149149
Value value_;
150150
std::shared_ptr<PrimitiveType> type_;
151151
};

src/iceberg/type.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <format>
2323
#include <iterator>
2424
#include <memory>
25+
#include <utility>
2526

2627
#include "iceberg/exception.h"
2728
#include "iceberg/util/formatter.h" // IWYU pragma: keep
@@ -319,4 +320,45 @@ std::shared_ptr<FixedType> fixed(int32_t length) {
319320
return std::make_shared<FixedType>(length);
320321
}
321322

323+
std::string_view ToString(TypeId id) {
324+
switch (id) {
325+
case TypeId::kStruct:
326+
return "struct";
327+
case TypeId::kList:
328+
return "list";
329+
case TypeId::kMap:
330+
return "map";
331+
case TypeId::kBoolean:
332+
return "boolean";
333+
case TypeId::kInt:
334+
return "int";
335+
case TypeId::kLong:
336+
return "long";
337+
case TypeId::kFloat:
338+
return "float";
339+
case TypeId::kDouble:
340+
return "double";
341+
case TypeId::kDecimal:
342+
return "decimal";
343+
case TypeId::kDate:
344+
return "date";
345+
case TypeId::kTime:
346+
return "time";
347+
case TypeId::kTimestamp:
348+
return "timestamp";
349+
case TypeId::kTimestampTz:
350+
return "timestamptz";
351+
case TypeId::kString:
352+
return "string";
353+
case TypeId::kUuid:
354+
return "uuid";
355+
case TypeId::kFixed:
356+
return "fixed";
357+
case TypeId::kBinary:
358+
return "binary";
359+
}
360+
361+
std::unreachable();
362+
}
363+
322364
} // namespace iceberg

src/iceberg/type.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,13 @@ ICEBERG_EXPORT std::shared_ptr<FixedType> fixed(int32_t length);
489489

490490
/// @}
491491

492+
/// \brief Get the lowercase string representation of a TypeId.
493+
///
494+
/// This returns the same lowercase string as used by Type::ToString() methods.
495+
/// For example: TypeId::kBoolean -> "boolean", TypeId::kInt -> "int", etc.
496+
///
497+
/// \param id The TypeId to convert to string
498+
/// \return A string_view containing the lowercase type name
499+
ICEBERG_EXPORT std::string_view ToString(TypeId id);
500+
492501
} // namespace iceberg

0 commit comments

Comments
 (0)