iceberg-cpp
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
iceberg::Literal Class Reference

Literal is a literal value that is associated with a primitive type. More...

#include <literal.h>

Inheritance diagram for iceberg::Literal:
iceberg::util::Formattable

Classes

struct  AboveMax
 Sentinel value to indicate that the literal value is above the valid range of a specific primitive type. It can happen when casting a literal to a narrower primitive type. More...
 
struct  BelowMin
 Sentinel value to indicate that the literal value is below the valid range of a specific primitive type. It can happen when casting a literal to a narrower primitive type. More...
 

Public Types

using Value = std::variant< std::monostate, bool, int32_t, int64_t, float, double, std::string, std::vector< uint8_t >, ::iceberg::Decimal, Uuid, BelowMin, AboveMax >
 

Public Member Functions

Result< std::vector< uint8_t > > Serialize () const
 Perform single-value serialization.
 
const std::shared_ptr< PrimitiveType > & type () const
 Get the literal type.
 
const Value & value () const
 Get the literal value.
 
Result< LiteralCastTo (const std::shared_ptr< PrimitiveType > &target_type) const
 Converts this literal to a literal of the given type.
 
bool operator== (const Literal &other) const
 
std::partial_ordering operator<=> (const Literal &other) const
 Compare two literals of the same primitive type.
 
bool IsAboveMax () const
 
bool IsBelowMin () const
 
bool IsNull () const
 Check if this literal is null.
 
bool IsNaN () const
 Check if this literal is NaN.
 
std::string ToString () const override
 Get a user-readable string representation.
 

Static Public Member Functions

static Literal Boolean (bool value)
 Factory methods for primitive types.
 
static Literal Int (int32_t value)
 
static Literal Date (int32_t value)
 
static Literal Long (int64_t value)
 
static Literal Time (int64_t value)
 
static Literal Timestamp (int64_t value)
 
static Literal TimestampTz (int64_t value)
 
static Literal Float (float value)
 
static Literal Double (double value)
 
static Literal String (std::string value)
 
static Literal UUID (Uuid value)
 
static Literal Binary (std::vector< uint8_t > value)
 
static Literal Fixed (std::vector< uint8_t > value)
 
static Literal Decimal (int128_t value, int32_t precision, int32_t scale)
 Create a decimal literal.
 
static Literal Null (std::shared_ptr< PrimitiveType > type)
 Create a literal representing a null value.
 
static Result< LiteralDeserialize (std::span< const uint8_t > data, std::shared_ptr< PrimitiveType > type)
 Restore a literal from single-value serialization.
 

Friends

class Conversions
 
class LiteralCaster
 

Detailed Description

Literal is a literal value that is associated with a primitive type.

Member Function Documentation

◆ CastTo()

Result< Literal > iceberg::Literal::CastTo ( const std::shared_ptr< PrimitiveType > &  target_type) const

Converts this literal to a literal of the given type.

When a predicate is bound to a concrete data column, literals are converted to match the bound column's type. This conversion process is more narrow than a cast and is only intended for cases where substituting one type is a common mistake (e.g. 34 instead of 34L) or where this API avoids requiring a concrete class (e.g., dates).

If conversion to a target type is not supported, this method returns an error.

This method may return BelowMin or AboveMax when the target type is not as wide as the original type. These values indicate that the containing predicate can be simplified. For example, std::numeric_limits<int>::max()+1 converted to an int will result in AboveMax and can simplify a < std::numeric_limits<int>::max()+1 to always true.

Parameters
target_typeA primitive PrimitiveType
Returns
A Result containing a literal of the given type or an error if conversion was not valid

◆ Decimal()

Literal iceberg::Literal::Decimal ( int128_t  value,
int32_t  precision,
int32_t  scale 
)
static

Create a decimal literal.

Parameters
valueThe unscaled 128-bit integer value.

◆ Deserialize()

Result< Literal > iceberg::Literal::Deserialize ( std::span< const uint8_t >  data,
std::shared_ptr< PrimitiveType type 
)
static

Restore a literal from single-value serialization.

See this spec for reference.

◆ IsAboveMax()

bool iceberg::Literal::IsAboveMax ( ) const

Check if this literal represents a value above the maximum allowed value for its type. This occurs when casting from a wider type to a narrower type and the value exceeds the target type's maximum.

Returns
true if this literal represents an AboveMax value, false otherwise

◆ IsBelowMin()

bool iceberg::Literal::IsBelowMin ( ) const

Check if this literal represents a value below the minimum allowed value for its type. This occurs when casting from a wider type to a narrower type and the value is less than the target type's minimum.

Returns
true if this literal represents a BelowMin value, false otherwise

◆ IsNaN()

bool iceberg::Literal::IsNaN ( ) const

Check if this literal is NaN.

Returns
true if this literal is NaN, false otherwise

◆ IsNull()

bool iceberg::Literal::IsNull ( ) const

Check if this literal is null.

Returns
true if this literal is null, false otherwise

◆ operator<=>()

std::partial_ordering iceberg::Literal::operator<=> ( const Literal other) const

Compare two literals of the same primitive type.

Parameters
otherThe other literal to compare with.
Returns
The comparison result as std::partial_ordering. If either side is AboveMax, BelowMin or Null, the result is unordered. Note: This comparison cannot be used for sorting literals if any literal is AboveMax, BelowMin or Null.

◆ Serialize()

Result< std::vector< uint8_t > > iceberg::Literal::Serialize ( ) const

Perform single-value serialization.

See this spec for reference.

◆ ToString()

std::string iceberg::Literal::ToString ( ) const
overridevirtual

Get a user-readable string representation.

Implements iceberg::util::Formattable.


The documentation for this class was generated from the following files: