28#include "iceberg/iceberg_export.h"
29#include "iceberg/result.h"
45 bool operator==(
const BelowMin&)
const =
default;
46 std::strong_ordering operator<=>(
const BelowMin&)
const =
default;
53 bool operator==(
const AboveMax&)
const =
default;
54 std::strong_ordering operator<=>(
const AboveMax&)
const =
default;
56 using Value = std::variant<std::monostate,
69 static Literal Boolean(
bool value);
70 static Literal Int(int32_t value);
71 static Literal Date(int32_t value);
72 static Literal Long(int64_t value);
73 static Literal Time(int64_t value);
74 static Literal Timestamp(int64_t value);
75 static Literal TimestampTz(int64_t value);
76 static Literal Float(
float value);
77 static Literal Double(
double value);
78 static Literal String(std::string value);
80 static Literal Binary(std::vector<uint8_t> value);
81 static Literal Fixed(std::vector<uint8_t> value);
85 static Literal Decimal(int128_t value, int32_t precision, int32_t scale);
89 return {Value{std::monostate{}}, std::move(type)};
96 static Result<Literal> Deserialize(std::span<const uint8_t> data,
97 std::shared_ptr<PrimitiveType> type);
103 Result<std::vector<uint8_t>> Serialize()
const;
106 const std::shared_ptr<PrimitiveType>& type()
const;
109 const Value&
value()
const {
return value_; }
129 Result<Literal> CastTo(
const std::shared_ptr<PrimitiveType>& target_type)
const;
131 bool operator==(
const Literal& other)
const;
139 std::partial_ordering operator<=>(
const Literal& other)
const;
145 bool IsAboveMax()
const;
151 bool IsBelowMin()
const;
161 std::string ToString()
const override;
164 Literal(Value value, std::shared_ptr<PrimitiveType> type);
170 std::shared_ptr<PrimitiveType> type_;
175 std::size_t operator()(
const Literal::Value& value)
const noexcept;
179 std::size_t operator()(
const Literal& value)
const noexcept {
184template <TypeId type_
id>
186 using ValueType = void;
189#define DEFINE_LITERAL_TRAIT(TYPE_ID, VALUE_TYPE) \
191 struct LiteralTraits<TypeId::TYPE_ID> { \
192 using ValueType = VALUE_TYPE; \
195DEFINE_LITERAL_TRAIT(kBoolean,
bool)
196DEFINE_LITERAL_TRAIT(kInt, int32_t)
197DEFINE_LITERAL_TRAIT(kDate, int32_t)
198DEFINE_LITERAL_TRAIT(kLong, int64_t)
199DEFINE_LITERAL_TRAIT(kTime, int64_t)
200DEFINE_LITERAL_TRAIT(kTimestamp, int64_t)
201DEFINE_LITERAL_TRAIT(kTimestampTz, int64_t)
202DEFINE_LITERAL_TRAIT(kFloat,
float)
203DEFINE_LITERAL_TRAIT(kDouble,
double)
204DEFINE_LITERAL_TRAIT(kDecimal,
Decimal)
205DEFINE_LITERAL_TRAIT(kString, std::string)
206DEFINE_LITERAL_TRAIT(kUuid,
Uuid)
207DEFINE_LITERAL_TRAIT(kBinary, std::vector<uint8_t>)
208DEFINE_LITERAL_TRAIT(kFixed, std::vector<uint8_t>)
210#undef DEFINE_LITERAL_TRAIT
Conversion utilities for primitive types.
Definition conversions.h:35
Represents 128-bit fixed-point decimal numbers. The max decimal precision that can be safely represen...
Definition decimal.h:46
LiteralCaster handles type casting operations for Literal. This is an internal implementation class.
Definition literal.cc:41
Literal is a literal value that is associated with a primitive type.
Definition literal.h:39
static Literal Null(std::shared_ptr< PrimitiveType > type)
Create a literal representing a null value.
Definition literal.h:88
const Value & value() const
Get the literal value.
Definition literal.h:109
128-bit fixed-point decimal numbers. Adapted from Apache Arrow with only Decimal128 support....
Hash function for Literal to facilitate use in unordered containers.
Definition literal.h:174
Sentinel value to indicate that the literal value is above the valid range of a specific primitive ty...
Definition literal.h:52
Sentinel value to indicate that the literal value is below the valid range of a specific primitive ty...
Definition literal.h:44
UUID (Universally Unique Identifier) representation.