2121
2222#include < cmath>
2323#include < concepts>
24- #include < sstream>
2524
2625#include " iceberg/exception.h"
2726
@@ -126,22 +125,28 @@ Literal::Literal(Value value, std::shared_ptr<PrimitiveType> type)
126125 : value_(std::move(value)), type_(std::move(type)) {}
127126
128127// Factory methods
129- Literal Literal::Boolean (bool value) { return {Value{value}, iceberg:: boolean ()}; }
128+ Literal Literal::Boolean (bool value) { return {Value{value}, boolean ()}; }
130129
131- Literal Literal::Int (int32_t value) { return {Value{value}, iceberg:: int32 ()}; }
130+ Literal Literal::Int (int32_t value) { return {Value{value}, int32 ()}; }
132131
133- Literal Literal::Long ( int64_t value) { return {Value{value}, iceberg::int64 ()}; }
132+ Literal Literal::Date ( int32_t value) { return {Value{value}, date ()}; }
134133
135- Literal Literal::Float ( float value) { return {Value{value}, iceberg::float32 ()}; }
134+ Literal Literal::Long ( int64_t value) { return {Value{value}, int64 ()}; }
136135
137- Literal Literal::Double ( double value) { return {Value{value}, iceberg::float64 ()}; }
136+ Literal Literal::Time ( int64_t value) { return {Value{value}, time ()}; }
138137
139- Literal Literal::String (std::string value) {
140- return {Value{std::move (value)}, iceberg::string ()};
141- }
138+ Literal Literal::Timestamp (int64_t value) { return {Value{value}, timestamp ()}; }
139+
140+ Literal Literal::TimestampTz (int64_t value) { return {Value{value}, timestamp_tz ()}; }
141+
142+ Literal Literal::Float (float value) { return {Value{value}, float32 ()}; }
143+
144+ Literal Literal::Double (double value) { return {Value{value}, float64 ()}; }
145+
146+ Literal Literal::String (std::string value) { return {Value{std::move (value)}, string ()}; }
142147
143148Literal Literal::Binary (std::vector<uint8_t > value) {
144- return {Value{std::move (value)}, iceberg:: binary ()};
149+ return {Value{std::move (value)}, binary ()};
145150}
146151
147152Result<Literal> Literal::Deserialize (std::span<const uint8_t > data,
@@ -188,8 +193,9 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
188193 return std::partial_ordering::unordered;
189194 }
190195
191- // If either value is AboveMax or BelowMin, comparison is unordered
192- if (IsAboveMax () || IsBelowMin () || other.IsAboveMax () || other.IsBelowMin ()) {
196+ // If either value is AboveMax, BelowMin or null, comparison is unordered
197+ if (IsAboveMax () || IsBelowMin () || other.IsAboveMax () || other.IsBelowMin () ||
198+ IsNull () || other.IsNull ()) {
193199 return std::partial_ordering::unordered;
194200 }
195201
@@ -202,13 +208,16 @@ std::partial_ordering Literal::operator<=>(const Literal& other) const {
202208 return this_val ? std::partial_ordering::greater : std::partial_ordering::less;
203209 }
204210
205- case TypeId::kInt : {
211+ case TypeId::kInt :
212+ case TypeId::kDate : {
206213 auto this_val = std::get<int32_t >(value_);
207214 auto other_val = std::get<int32_t >(other.value_ );
208215 return this_val <=> other_val;
209216 }
210217
211- case TypeId::kLong : {
218+ case TypeId::kLong :
219+ case TypeId::kTimestamp :
220+ case TypeId::kTimestampTz : {
212221 auto this_val = std::get<int64_t >(value_);
213222 auto other_val = std::get<int64_t >(other.value_ );
214223 return this_val <=> other_val;
@@ -253,6 +262,9 @@ std::string Literal::ToString() const {
253262 if (std::holds_alternative<AboveMax>(value_)) {
254263 return " aboveMax" ;
255264 }
265+ if (std::holds_alternative<std::monostate>(value_)) {
266+ return " null" ;
267+ }
256268
257269 switch (type_->type_id ()) {
258270 case TypeId::kBoolean : {
@@ -301,6 +313,8 @@ bool Literal::IsBelowMin() const { return std::holds_alternative<BelowMin>(value
301313
302314bool Literal::IsAboveMax () const { return std::holds_alternative<AboveMax>(value_); }
303315
316+ bool Literal::IsNull () const { return std::holds_alternative<std::monostate>(value_); }
317+
304318// LiteralCaster implementation
305319
306320Result<Literal> LiteralCaster::CastTo (const Literal& literal,
@@ -312,7 +326,8 @@ Result<Literal> LiteralCaster::CastTo(const Literal& literal,
312326
313327 // Handle special values
314328 if (std::holds_alternative<Literal::BelowMin>(literal.value_ ) ||
315- std::holds_alternative<Literal::AboveMax>(literal.value_ )) {
329+ std::holds_alternative<Literal::AboveMax>(literal.value_ ) ||
330+ std::holds_alternative<std::monostate>(literal.value_ )) {
316331 // Cannot cast type for special values
317332 return NotSupported (" Cannot cast type for {}" , literal.ToString ());
318333 }
0 commit comments