2727
2828namespace iceberg {
2929
30- // / \brief PrimitiveLiteralCaster handles type casting operations for PrimitiveLiteral .
30+ // / \brief LiteralCaster handles type casting operations for Literal .
3131// / This is an internal implementation class.
32- class PrimitiveLiteralCaster {
32+ class LiteralCaster {
3333 public:
34- // / Cast a PrimitiveLiteral to the target type.
35- static Result<PrimitiveLiteral > CastTo (
36- const PrimitiveLiteral& literal, const std::shared_ptr<PrimitiveType>& target_type);
34+ // / Cast a Literal to the target type.
35+ static Result<Literal > CastTo (const Literal& literal,
36+ const std::shared_ptr<PrimitiveType>& target_type);
3737
3838 // / Create a literal representing a value below the minimum for the given type.
39- static PrimitiveLiteral BelowMinLiteral (std::shared_ptr<PrimitiveType> type);
39+ static Literal BelowMinLiteral (std::shared_ptr<PrimitiveType> type);
4040
4141 // / Create a literal representing a value above the maximum for the given type.
42- static PrimitiveLiteral AboveMaxLiteral (std::shared_ptr<PrimitiveType> type);
42+ static Literal AboveMaxLiteral (std::shared_ptr<PrimitiveType> type);
4343
4444 private:
4545 // / Cast from Int type to target type.
46- static Result<PrimitiveLiteral > CastFromInt (
47- const PrimitiveLiteral& literal, const std::shared_ptr<PrimitiveType>& target_type);
46+ static Result<Literal > CastFromInt (const Literal& literal,
47+ const std::shared_ptr<PrimitiveType>& target_type);
4848
4949 // / Cast from Long type to target type.
50- static Result<PrimitiveLiteral > CastFromLong (
51- const PrimitiveLiteral& literal, const std::shared_ptr<PrimitiveType>& target_type);
50+ static Result<Literal > CastFromLong (const Literal& literal,
51+ const std::shared_ptr<PrimitiveType>& target_type);
5252
5353 // / Cast from Float type to target type.
54- static Result<PrimitiveLiteral > CastFromFloat (
55- const PrimitiveLiteral& literal, const std::shared_ptr<PrimitiveType>& target_type);
54+ static Result<Literal > CastFromFloat (const Literal& literal,
55+ const std::shared_ptr<PrimitiveType>& target_type);
5656};
5757
58- PrimitiveLiteral PrimitiveLiteralCaster::BelowMinLiteral (
59- std::shared_ptr<PrimitiveType> type) {
60- return PrimitiveLiteral (PrimitiveLiteral::BelowMin{}, std::move (type));
58+ Literal LiteralCaster::BelowMinLiteral (std::shared_ptr<PrimitiveType> type) {
59+ return Literal (Literal::BelowMin{}, std::move (type));
6160}
6261
63- PrimitiveLiteral PrimitiveLiteralCaster::AboveMaxLiteral (
64- std::shared_ptr<PrimitiveType> type) {
65- return PrimitiveLiteral (PrimitiveLiteral::AboveMax{}, std::move (type));
62+ Literal LiteralCaster::AboveMaxLiteral (std::shared_ptr<PrimitiveType> type) {
63+ return Literal (Literal::AboveMax{}, std::move (type));
6664}
6765
68- Result<PrimitiveLiteral> PrimitiveLiteralCaster ::CastFromInt (
69- const PrimitiveLiteral & literal, const std::shared_ptr<PrimitiveType>& target_type) {
66+ Result<Literal> LiteralCaster ::CastFromInt (
67+ const Literal & literal, const std::shared_ptr<PrimitiveType>& target_type) {
7068 auto int_val = std::get<int32_t >(literal.value_ );
7169 auto target_type_id = target_type->type_id ();
7270
7371 switch (target_type_id) {
7472 case TypeId::kLong :
75- return PrimitiveLiteral ::Long (static_cast <int64_t >(int_val));
73+ return Literal ::Long (static_cast <int64_t >(int_val));
7674 case TypeId::kFloat :
77- return PrimitiveLiteral ::Float (static_cast <float >(int_val));
75+ return Literal ::Float (static_cast <float >(int_val));
7876 case TypeId::kDouble :
79- return PrimitiveLiteral ::Double (static_cast <double >(int_val));
77+ return Literal ::Double (static_cast <double >(int_val));
8078 default :
8179 return NotSupported (" Cast from Int to {} is not implemented" ,
8280 static_cast <int >(target_type_id));
8381 }
8482}
8583
86- Result<PrimitiveLiteral> PrimitiveLiteralCaster ::CastFromLong (
87- const PrimitiveLiteral & literal, const std::shared_ptr<PrimitiveType>& target_type) {
84+ Result<Literal> LiteralCaster ::CastFromLong (
85+ const Literal & literal, const std::shared_ptr<PrimitiveType>& target_type) {
8886 auto long_val = std::get<int64_t >(literal.value_ );
8987 auto target_type_id = target_type->type_id ();
9088
@@ -97,82 +95,81 @@ Result<PrimitiveLiteral> PrimitiveLiteralCaster::CastFromLong(
9795 if (long_val <= std::numeric_limits<int32_t >::min ()) {
9896 return BelowMinLiteral (target_type);
9997 }
100- return PrimitiveLiteral ::Int (static_cast <int32_t >(long_val));
98+ return Literal ::Int (static_cast <int32_t >(long_val));
10199 }
102100 case TypeId::kFloat :
103- return PrimitiveLiteral ::Float (static_cast <float >(long_val));
101+ return Literal ::Float (static_cast <float >(long_val));
104102 case TypeId::kDouble :
105- return PrimitiveLiteral ::Double (static_cast <double >(long_val));
103+ return Literal ::Double (static_cast <double >(long_val));
106104 default :
107105 return NotSupported (" Cast from Long to {} is not supported" ,
108106 static_cast <int >(target_type_id));
109107 }
110108}
111109
112- Result<PrimitiveLiteral> PrimitiveLiteralCaster ::CastFromFloat (
113- const PrimitiveLiteral & literal, const std::shared_ptr<PrimitiveType>& target_type) {
110+ Result<Literal> LiteralCaster ::CastFromFloat (
111+ const Literal & literal, const std::shared_ptr<PrimitiveType>& target_type) {
114112 auto float_val = std::get<float >(literal.value_ );
115113 auto target_type_id = target_type->type_id ();
116114
117115 switch (target_type_id) {
118116 case TypeId::kDouble :
119- return PrimitiveLiteral ::Double (static_cast <double >(float_val));
117+ return Literal ::Double (static_cast <double >(float_val));
120118 default :
121119 return NotSupported (" Cast from Float to {} is not supported" ,
122120 static_cast <int >(target_type_id));
123121 }
124122}
125123
126124// Constructor
127- PrimitiveLiteral::PrimitiveLiteral (Value value, std::shared_ptr<PrimitiveType> type)
125+ Literal::Literal (Value value, std::shared_ptr<PrimitiveType> type)
128126 : value_(std::move(value)), type_(std::move(type)) {}
129127
130128// Factory methods
131- PrimitiveLiteral PrimitiveLiteral ::Boolean (bool value) {
129+ Literal Literal ::Boolean (bool value) {
132130 return {Value{value}, std::make_shared<BooleanType>()};
133131}
134132
135- PrimitiveLiteral PrimitiveLiteral ::Int (int32_t value) {
133+ Literal Literal ::Int (int32_t value) {
136134 return {Value{value}, std::make_shared<IntType>()};
137135}
138136
139- PrimitiveLiteral PrimitiveLiteral ::Long (int64_t value) {
137+ Literal Literal ::Long (int64_t value) {
140138 return {Value{value}, std::make_shared<LongType>()};
141139}
142140
143- PrimitiveLiteral PrimitiveLiteral ::Float (float value) {
141+ Literal Literal ::Float (float value) {
144142 return {Value{value}, std::make_shared<FloatType>()};
145143}
146144
147- PrimitiveLiteral PrimitiveLiteral ::Double (double value) {
145+ Literal Literal ::Double (double value) {
148146 return {Value{value}, std::make_shared<DoubleType>()};
149147}
150148
151- PrimitiveLiteral PrimitiveLiteral ::String (std::string value) {
149+ Literal Literal ::String (std::string value) {
152150 return {Value{std::move (value)}, std::make_shared<StringType>()};
153151}
154152
155- PrimitiveLiteral PrimitiveLiteral ::Binary (std::vector<uint8_t > value) {
153+ Literal Literal ::Binary (std::vector<uint8_t > value) {
156154 return {Value{std::move (value)}, std::make_shared<BinaryType>()};
157155}
158156
159- Result<PrimitiveLiteral> PrimitiveLiteral ::Deserialize (
160- std::span< const uint8_t > data, std::shared_ptr<PrimitiveType> type) {
161- return NotImplemented (" Deserialization of PrimitiveLiteral is not implemented yet" );
157+ Result<Literal> Literal ::Deserialize (std::span< const uint8_t > data,
158+ std::shared_ptr<PrimitiveType> type) {
159+ return NotImplemented (" Deserialization of Literal is not implemented yet" );
162160}
163161
164- Result<std::vector<uint8_t >> PrimitiveLiteral ::Serialize () const {
165- return NotImplemented (" Serialization of PrimitiveLiteral is not implemented yet" );
162+ Result<std::vector<uint8_t >> Literal ::Serialize () const {
163+ return NotImplemented (" Serialization of Literal is not implemented yet" );
166164}
167165
168166// Getters
169167
170- const std::shared_ptr<PrimitiveType>& PrimitiveLiteral ::type () const { return type_; }
168+ const std::shared_ptr<PrimitiveType>& Literal ::type () const { return type_; }
171169
172170// Cast method
173- Result<PrimitiveLiteral> PrimitiveLiteral::CastTo (
174- const std::shared_ptr<PrimitiveType>& target_type) const {
175- return PrimitiveLiteralCaster::CastTo (*this , target_type);
171+ Result<Literal> Literal::CastTo (const std::shared_ptr<PrimitiveType>& target_type) const {
172+ return LiteralCaster::CastTo (*this , target_type);
176173}
177174
178175// Template function for floating point comparison following Iceberg rules:
@@ -200,7 +197,7 @@ std::partial_ordering iceberg_float_compare(T lhs, T rhs) {
200197}
201198
202199// Three-way comparison operator
203- std::partial_ordering PrimitiveLiteral ::operator <=>(const PrimitiveLiteral & other) const {
200+ std::partial_ordering Literal ::operator <=>(const Literal & other) const {
204201 // If types are different, comparison is unordered
205202 if (type_->type_id () != other.type_ ->type_id ()) {
206203 return std::partial_ordering::unordered;
@@ -264,7 +261,7 @@ std::partial_ordering PrimitiveLiteral::operator<=>(const PrimitiveLiteral& othe
264261 }
265262}
266263
267- std::string PrimitiveLiteral ::ToString () const {
264+ std::string Literal ::ToString () const {
268265 if (std::holds_alternative<BelowMin>(value_)) {
269266 return " BelowMin" ;
270267 }
@@ -315,26 +312,22 @@ std::string PrimitiveLiteral::ToString() const {
315312 }
316313}
317314
318- bool PrimitiveLiteral::IsBelowMin () const {
319- return std::holds_alternative<BelowMin>(value_);
320- }
315+ bool Literal::IsBelowMin () const { return std::holds_alternative<BelowMin>(value_); }
321316
322- bool PrimitiveLiteral::IsAboveMax () const {
323- return std::holds_alternative<AboveMax>(value_);
324- }
317+ bool Literal::IsAboveMax () const { return std::holds_alternative<AboveMax>(value_); }
325318
326- // PrimitiveLiteralCaster implementation
319+ // LiteralCaster implementation
327320
328- Result<PrimitiveLiteral> PrimitiveLiteralCaster ::CastTo (
329- const PrimitiveLiteral& literal, const std::shared_ptr<PrimitiveType>& target_type) {
321+ Result<Literal> LiteralCaster ::CastTo (const Literal& literal,
322+ const std::shared_ptr<PrimitiveType>& target_type) {
330323 if (*literal.type_ == *target_type) {
331324 // If types are the same, return a copy of the current literal
332- return PrimitiveLiteral (literal.value_ , target_type);
325+ return Literal (literal.value_ , target_type);
333326 }
334327
335328 // Handle special values
336- if (std::holds_alternative<PrimitiveLiteral ::BelowMin>(literal.value_ ) ||
337- std::holds_alternative<PrimitiveLiteral ::AboveMax>(literal.value_ )) {
329+ if (std::holds_alternative<Literal ::BelowMin>(literal.value_ ) ||
330+ std::holds_alternative<Literal ::AboveMax>(literal.value_ )) {
338331 // Cannot cast type for special values
339332 return NotSupported (" Cannot cast type for {}" , literal.ToString ());
340333 }
0 commit comments