32#include <unordered_map>
35#include "iceberg/iceberg_export.h"
36#include "iceberg/result.h"
46 ~Type()
override =
default;
62 [[nodiscard]]
virtual bool Equals(
const Type& other)
const = 0;
79 [[nodiscard]]
virtual std::span<const SchemaField>
fields()
const = 0;
80 using SchemaFieldConstRef = std::reference_wrapper<const SchemaField>;
84 [[nodiscard]]
virtual Result<std::optional<SchemaFieldConstRef>>
GetFieldById(
85 int32_t field_id)
const = 0;
90 int32_t index)
const = 0;
96 [[nodiscard]]
virtual Result<std::optional<SchemaFieldConstRef>>
GetFieldByName(
97 std::string_view name,
bool case_sensitive)
const = 0;
99 [[nodiscard]] Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
100 std::string_view name)
const;
110 constexpr static TypeId kTypeId = TypeId::kStruct;
111 explicit StructType(std::vector<SchemaField> fields);
114 TypeId type_id()
const override;
115 std::string ToString()
const override;
117 std::span<const SchemaField> fields()
const override;
118 Result<std::optional<SchemaFieldConstRef>> GetFieldById(
119 int32_t field_id)
const override;
120 Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex(
121 int32_t index)
const override;
122 Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
123 std::string_view name,
bool case_sensitive)
const override;
124 using NestedType::GetFieldByName;
126 std::unique_ptr<Schema> ToSchema()
const;
129 bool Equals(
const Type& other)
const override;
131 static Result<std::unordered_map<int32_t, SchemaFieldConstRef>> InitFieldById(
133 static Result<std::unordered_map<std::string_view, SchemaFieldConstRef>>
135 static Result<std::unordered_map<std::string, SchemaFieldConstRef>>
138 std::vector<SchemaField> fields_;
139 Lazy<InitFieldById> field_by_id_;
140 Lazy<InitFieldByName> field_by_name_;
141 Lazy<InitFieldByLowerCaseName> field_by_lowercase_name_;
147 constexpr static const TypeId kTypeId = TypeId::kList;
148 constexpr static const std::string_view kElementName =
"element";
154 ListType(int32_t field_id, std::shared_ptr<Type> type,
bool optional);
157 TypeId type_id()
const override;
159 std::string ToString()
const override;
161 std::span<const SchemaField> fields()
const override;
162 Result<std::optional<SchemaFieldConstRef>> GetFieldById(
163 int32_t field_id)
const override;
164 Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex(
165 int32_t index)
const override;
166 Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
167 std::string_view name,
bool case_sensitive)
const override;
168 using NestedType::GetFieldByName;
171 bool Equals(
const Type& other)
const override;
179 constexpr static const TypeId kTypeId = TypeId::kMap;
180 constexpr static const std::string_view kKeyName =
"key";
181 constexpr static const std::string_view kValueName =
"value";
191 TypeId type_id()
const override;
192 std::string ToString()
const override;
194 std::span<const SchemaField> fields()
const override;
195 Result<std::optional<SchemaFieldConstRef>> GetFieldById(
196 int32_t field_id)
const override;
197 Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex(
198 int32_t index)
const override;
199 Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
200 std::string_view name,
bool case_sensitive)
const override;
201 using NestedType::GetFieldByName;
204 bool Equals(
const Type& other)
const override;
206 std::array<SchemaField, 2> fields_;
218 constexpr static const TypeId kTypeId = TypeId::kBoolean;
223 TypeId type_id()
const override;
224 std::string ToString()
const override;
227 bool Equals(
const Type& other)
const override;
233 constexpr static const TypeId kTypeId = TypeId::kInt;
238 TypeId type_id()
const override;
239 std::string ToString()
const override;
242 bool Equals(
const Type& other)
const override;
248 constexpr static const TypeId kTypeId = TypeId::kLong;
253 TypeId type_id()
const override;
254 std::string ToString()
const override;
257 bool Equals(
const Type& other)
const override;
264 constexpr static const TypeId kTypeId = TypeId::kFloat;
269 TypeId type_id()
const override;
270 std::string ToString()
const override;
273 bool Equals(
const Type& other)
const override;
280 constexpr static const TypeId kTypeId = TypeId::kDouble;
285 TypeId type_id()
const override;
286 std::string ToString()
const override;
289 bool Equals(
const Type& other)
const override;
295 constexpr static const TypeId kTypeId = TypeId::kDecimal;
296 constexpr static const int32_t kMaxPrecision = 38;
303 [[nodiscard]] int32_t precision()
const;
306 [[nodiscard]] int32_t scale()
const;
308 TypeId type_id()
const override;
309 std::string ToString()
const override;
312 bool Equals(
const Type& other)
const override;
323 constexpr static const TypeId kTypeId = TypeId::kDate;
328 TypeId type_id()
const override;
329 std::string ToString()
const override;
332 bool Equals(
const Type& other)
const override;
339 constexpr static const TypeId kTypeId = TypeId::kTime;
344 TypeId type_id()
const override;
345 std::string ToString()
const override;
348 bool Equals(
const Type& other)
const override;
365 constexpr static const TypeId kTypeId = TypeId::kTimestamp;
370 bool is_zoned()
const override;
371 TimeUnit time_unit()
const override;
373 TypeId type_id()
const override;
374 std::string ToString()
const override;
377 bool Equals(
const Type& other)
const override;
384 constexpr static const TypeId kTypeId = TypeId::kTimestampTz;
389 bool is_zoned()
const override;
390 TimeUnit time_unit()
const override;
392 TypeId type_id()
const override;
393 std::string ToString()
const override;
396 bool Equals(
const Type& other)
const override;
402 constexpr static const TypeId kTypeId = TypeId::kBinary;
407 TypeId type_id()
const override;
408 std::string ToString()
const override;
411 bool Equals(
const Type& other)
const override;
418 constexpr static const TypeId kTypeId = TypeId::kString;
423 TypeId type_id()
const override;
424 std::string ToString()
const override;
427 bool Equals(
const Type& other)
const override;
433 constexpr static const TypeId kTypeId = TypeId::kFixed;
440 [[nodiscard]] int32_t length()
const;
442 TypeId type_id()
const override;
443 std::string ToString()
const override;
446 bool Equals(
const Type& other)
const override;
456 constexpr static const TypeId kTypeId = TypeId::kUuid;
461 TypeId type_id()
const override;
462 std::string ToString()
const override;
465 bool Equals(
const Type& other)
const override;
476ICEBERG_EXPORT
const std::shared_ptr<BooleanType>&
boolean();
478ICEBERG_EXPORT
const std::shared_ptr<IntType>&
int32();
480ICEBERG_EXPORT
const std::shared_ptr<LongType>&
int64();
482ICEBERG_EXPORT
const std::shared_ptr<FloatType>&
float32();
484ICEBERG_EXPORT
const std::shared_ptr<DoubleType>&
float64();
486ICEBERG_EXPORT
const std::shared_ptr<DateType>&
date();
488ICEBERG_EXPORT
const std::shared_ptr<TimeType>&
time();
490ICEBERG_EXPORT
const std::shared_ptr<TimestampType>&
timestamp();
494ICEBERG_EXPORT
const std::shared_ptr<BinaryType>&
binary();
496ICEBERG_EXPORT
const std::shared_ptr<StringType>&
string();
498ICEBERG_EXPORT
const std::shared_ptr<UuidType>&
uuid();
504ICEBERG_EXPORT std::shared_ptr<DecimalType>
decimal(int32_t precision, int32_t scale);
509ICEBERG_EXPORT std::shared_ptr<FixedType>
fixed(int32_t length);
514ICEBERG_EXPORT std::shared_ptr<StructType>
struct_(std::vector<SchemaField> fields);
536ICEBERG_EXPORT std::string_view ToString(
TypeId id);
A data type representing an arbitrary-length byte sequence.
Definition type.h:400
A data type representing a boolean (true or false).
Definition type.h:216
A data type representing a calendar date without reference to a timezone or time.
Definition type.h:321
A data type representing a fixed-precision decimal.
Definition type.h:293
A data type representing a 64-bit (double precision) IEEE-754 float.
Definition type.h:278
A data type representing a fixed-length bytestring.
Definition type.h:431
A data type representing a 32-bit (single precision) IEEE-754 float.
Definition type.h:262
A data type representing a 32-bit signed integer.
Definition type.h:231
A data type representing a list of values.
Definition type.h:145
A data type representing a 64-bit signed integer.
Definition type.h:246
A data type representing a dictionary of values.
Definition type.h:177
A data type that has child fields.
Definition type.h:73
virtual std::span< const SchemaField > fields() const =0
Get a view of the child fields.
virtual Result< std::optional< SchemaFieldConstRef > > GetFieldByName(std::string_view name, bool case_sensitive) const =0
Get a field by name. Return an error Status if the field name is not unique; prefer GetFieldById or G...
virtual Result< std::optional< SchemaFieldConstRef > > GetFieldById(int32_t field_id) const =0
Get a field by field ID.
virtual Result< std::optional< SchemaFieldConstRef > > GetFieldByIndex(int32_t index) const =0
Get a field by index.
bool is_primitive() const override
Is this a primitive type (may not have child fields)?
Definition type.h:75
bool is_nested() const override
Is this a nested type (may have child fields)?
Definition type.h:76
A data type that does not have child fields.
Definition type.h:66
bool is_primitive() const override
Is this a primitive type (may not have child fields)?
Definition type.h:68
bool is_nested() const override
Is this a nested type (may have child fields)?
Definition type.h:69
A type combined with a name.
Definition schema_field.h:39
A data type representing an arbitrary-length character sequence (encoded in UTF-8).
Definition type.h:416
A data type representing a struct with nested fields.
Definition type.h:108
A data type representing a wall clock time in microseconds without reference to a timezone or date.
Definition type.h:337
A base class for any timestamp time (irrespective of unit or timezone).
Definition type.h:353
virtual bool is_zoned() const =0
Is this type zoned or naive?
virtual TimeUnit time_unit() const =0
The time resolution.
A data type representing a timestamp in microseconds without reference to a timezone.
Definition type.h:363
A data type representing a timestamp as microseconds since the epoch in UTC. A time zone or offset is...
Definition type.h:382
Interface for a data type for a field.
Definition type.h:44
virtual TypeId type_id() const =0
Get the type ID.
virtual bool is_primitive() const =0
Is this a primitive type (may not have child fields)?
virtual bool is_nested() const =0
Is this a nested type (may have child fields)?
friend bool operator==(const Type &lhs, const Type &rhs)
Compare two types for equality.
Definition type.h:58
virtual bool Equals(const Type &other) const =0
Compare two types for equality.
A data type representing a UUID. While defined as a distinct type, it is effectively a fixed(16).
Definition type.h:454
ICEBERG_EXPORT const std::shared_ptr< BinaryType > & binary()
Return a BinaryType instance.
ICEBERG_EXPORT const std::shared_ptr< DateType > & date()
Return a DateType instance.
std::shared_ptr< MapType > map(SchemaField key, SchemaField value)
Create a MapType with the given key and value fields.
Definition type.cc:388
std::shared_ptr< ListType > list(SchemaField element)
Create a ListType with the given element field.
Definition type.cc:392
ICEBERG_EXPORT const std::shared_ptr< TimestampTzType > & timestamp_tz()
Return a TimestampTzType instance.
ICEBERG_EXPORT const std::shared_ptr< TimeType > & time()
Return a TimeType instance.
ICEBERG_EXPORT const std::shared_ptr< DoubleType > & float64()
Return a DoubleType instance.
ICEBERG_EXPORT const std::shared_ptr< StringType > & string()
Return a StringType instance.
ICEBERG_EXPORT const std::shared_ptr< IntType > & int32()
Return an IntType instance.
ICEBERG_EXPORT const std::shared_ptr< TimestampType > & timestamp()
Return a TimestampType instance.
std::shared_ptr< FixedType > fixed(int32_t length)
Create a FixedType with the given length.
Definition type.cc:384
ICEBERG_EXPORT const std::shared_ptr< FloatType > & float32()
Return a FloatType instance.
std::shared_ptr< StructType > struct_(std::vector< SchemaField > fields)
Create a StructType with the given fields.
Definition type.cc:396
std::shared_ptr< DecimalType > decimal(int32_t precision, int32_t scale)
Create a DecimalType with the given precision and scale.
Definition type.cc:380
ICEBERG_EXPORT const std::shared_ptr< BooleanType > & boolean()
Return a BooleanType instance.
ICEBERG_EXPORT const std::shared_ptr< LongType > & int64()
Return a LongType instance.
ICEBERG_EXPORT const std::shared_ptr< UuidType > & uuid()
Return a UuidType instance.
TimeUnit
The time unit. In Iceberg V3 nanoseconds are also supported.
Definition type_fwd.h:56
TypeId
A data type.
Definition type_fwd.h:35