32#include <unordered_map>
46 ~Type()
override =
default;
58 bool is_struct()
const {
return type_id() == TypeId::kStruct; }
61 bool is_list()
const {
return type_id() == TypeId::kList; }
64 bool is_map()
const {
return type_id() == TypeId::kMap; }
67 bool is_variant()
const {
return type_id() == TypeId::kVariant; }
91 virtual std::span<const SchemaField>
fields()
const = 0;
92 using SchemaFieldConstRef = std::reference_wrapper<const SchemaField>;
97 int32_t field_id)
const = 0;
102 int32_t index)
const = 0;
109 std::string_view name,
bool case_sensitive)
const = 0;
121 constexpr static TypeId kTypeId = TypeId::kStruct;
122 explicit StructType(std::vector<SchemaField> fields);
128 std::span<const SchemaField>
fields()
const override;
130 int32_t field_id)
const override;
132 int32_t index)
const override;
134 std::string_view name,
bool case_sensitive)
const override;
135 using NestedType::GetFieldByName;
137 std::unique_ptr<Schema> ToSchema()
const;
149 std::vector<SchemaField> fields_;
158 constexpr static const TypeId kTypeId = TypeId::kList;
159 constexpr static const std::string_view kElementName =
"element";
168 ListType(int32_t field_id, std::shared_ptr<Type> type,
bool optional);
175 std::span<const SchemaField>
fields()
const override;
177 int32_t field_id)
const override;
179 int32_t index)
const override;
181 std::string_view name,
bool case_sensitive)
const override;
182 using NestedType::GetFieldByName;
193 constexpr static const TypeId kTypeId = TypeId::kMap;
194 constexpr static const std::string_view kKeyName =
"key";
195 constexpr static const std::string_view kValueName =
"value";
211 std::span<const SchemaField>
fields()
const override;
213 int32_t field_id)
const override;
215 int32_t index)
const override;
217 std::string_view name,
bool case_sensitive)
const override;
218 using NestedType::GetFieldByName;
223 std::array<SchemaField, 2> fields_;
235 constexpr static const TypeId kTypeId = TypeId::kVariant;
259 constexpr static const TypeId kTypeId = TypeId::kBoolean;
274 constexpr static const TypeId kTypeId = TypeId::kInt;
289 constexpr static const TypeId kTypeId = TypeId::kLong;
305 constexpr static const TypeId kTypeId = TypeId::kFloat;
321 constexpr static const TypeId kTypeId = TypeId::kDouble;
336 constexpr static const TypeId kTypeId = TypeId::kDecimal;
337 constexpr static const int32_t kMaxPrecision = 38;
365 constexpr static const TypeId kTypeId = TypeId::kDate;
381 constexpr static const TypeId kTypeId = TypeId::kTime;
407 constexpr static const TypeId kTypeId = TypeId::kTimestamp;
426 constexpr static const TypeId kTypeId = TypeId::kTimestampTz;
445 constexpr static const TypeId kTypeId = TypeId::kTimestampNs;
464 constexpr static const TypeId kTypeId = TypeId::kTimestampTzNs;
482 constexpr static const TypeId kTypeId = TypeId::kBinary;
498 constexpr static const TypeId kTypeId = TypeId::kString;
513 constexpr static const TypeId kTypeId = TypeId::kFixed;
537 constexpr static const TypeId kTypeId = TypeId::kUuid;
552 constexpr static const TypeId kTypeId = TypeId::kUnknown;
567 constexpr static const TypeId kTypeId = TypeId::kGeometry;
568 constexpr static std::string_view kDefaultCrs =
"OGC:CRS84";
574 std::string_view crs()
const;
586 std::string crs_{kDefaultCrs};
592 constexpr static const TypeId kTypeId = TypeId::kGeography;
593 constexpr static std::string_view kDefaultCrs =
"OGC:CRS84";
594 constexpr static EdgeAlgorithm kDefaultAlgorithm = EdgeAlgorithm::kSpherical;
602 std::string_view crs()
const;
616 std::string crs_{kDefaultCrs};
628ICEBERG_EXPORT
const std::shared_ptr<BooleanType>&
boolean();
630ICEBERG_EXPORT
const std::shared_ptr<IntType>&
int32();
632ICEBERG_EXPORT
const std::shared_ptr<LongType>&
int64();
634ICEBERG_EXPORT
const std::shared_ptr<FloatType>&
float32();
636ICEBERG_EXPORT
const std::shared_ptr<DoubleType>&
float64();
638ICEBERG_EXPORT
const std::shared_ptr<DateType>&
date();
640ICEBERG_EXPORT
const std::shared_ptr<TimeType>&
time();
642ICEBERG_EXPORT
const std::shared_ptr<TimestampType>&
timestamp();
650ICEBERG_EXPORT
const std::shared_ptr<BinaryType>&
binary();
652ICEBERG_EXPORT
const std::shared_ptr<StringType>&
string();
654ICEBERG_EXPORT
const std::shared_ptr<UuidType>&
uuid();
656ICEBERG_EXPORT
const std::shared_ptr<UnknownType>&
unknown();
658ICEBERG_EXPORT
const std::shared_ptr<VariantType>&
variant();
660ICEBERG_EXPORT
const std::shared_ptr<GeometryType>&
geometry();
662ICEBERG_EXPORT
const std::shared_ptr<GeographyType>&
geography();
669ICEBERG_EXPORT std::shared_ptr<DecimalType>
decimal(int32_t precision, int32_t scale);
675ICEBERG_EXPORT std::shared_ptr<FixedType>
fixed(int32_t length);
679ICEBERG_EXPORT std::shared_ptr<GeometryType>
geometry(std::string crs);
683ICEBERG_EXPORT std::shared_ptr<GeographyType>
geography(std::string crs);
687ICEBERG_EXPORT std::shared_ptr<GeographyType>
geography(std::string crs,
693ICEBERG_EXPORT std::shared_ptr<StructType>
struct_(std::vector<SchemaField> fields);
A data type representing an arbitrary-length byte sequence.
Definition type.h:480
bool Equals(const Type &other) const override
Compare two types for equality.
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
A data type representing a boolean (true or false).
Definition type.h:257
bool Equals(const Type &other) const override
Compare two types for equality.
std::string ToString() const override
Get a user-readable string representation.
TypeId type_id() const override
Get the type ID.
A data type representing a calendar date without reference to a timezone or time.
Definition type.h:363
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing a fixed-precision decimal.
Definition type.h:334
bool Equals(const Type &other) const override
Compare two types for equality.
int32_t scale() const
Get the scale (essentially, the number of decimal digits after the decimal point; precisely,...
std::string ToString() const override
Get a user-readable string representation.
TypeId type_id() const override
Get the type ID.
DecimalType(int32_t precision, int32_t scale)
Construct a decimal type with the given precision and scale.
int32_t precision() const
Get the precision (the number of decimal digits).
A data type representing a 64-bit (double precision) IEEE-754 float.
Definition type.h:319
bool Equals(const Type &other) const override
Compare two types for equality.
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
A data type representing a fixed-length bytestring.
Definition type.h:511
int32_t length() const
The length (the number of bytes to store).
FixedType(int32_t length)
Construct a fixed type with the given length.
TypeId type_id() const override
Get the type ID.
bool Equals(const Type &other) const override
Compare two types for equality.
std::string ToString() const override
Get a user-readable string representation.
A data type representing a 32-bit (single precision) IEEE-754 float.
Definition type.h:303
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing OGC geography in WKB format.
Definition type.h:590
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
TypeId type_id() const override
Get the type ID.
A data type representing OGC geometry in WKB format.
Definition type.h:565
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
TypeId type_id() const override
Get the type ID.
A data type representing a 32-bit signed integer.
Definition type.h:272
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing a list of values.
Definition type.h:156
Result< std::optional< SchemaFieldConstRef > > GetFieldById(int32_t field_id) const override
Get a field by field ID.
std::string ToString() const override
Get a user-readable string representation.
std::span< const SchemaField > fields() const override
Get a view of the child fields.
Result< std::optional< SchemaFieldConstRef > > GetFieldByIndex(int32_t index) const override
Get a field by index.
Result< std::optional< SchemaFieldConstRef > > GetFieldByName(std::string_view name, bool case_sensitive) const override
Get a field by name. Return an error Status if the field name is not unique; prefer GetFieldById or G...
ListType(int32_t field_id, std::shared_ptr< Type > type, bool optional)
Construct a list of the given element type.
TypeId type_id() const override
Get the type ID.
ListType(SchemaField element)
Construct a list of the given element.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing a 64-bit signed integer.
Definition type.h:287
bool Equals(const Type &other) const override
Compare two types for equality.
std::string ToString() const override
Get a user-readable string representation.
TypeId type_id() const override
Get the type ID.
A data type representing a dictionary of values.
Definition type.h:191
std::string ToString() const override
Get a user-readable string representation.
Result< std::optional< SchemaFieldConstRef > > GetFieldByIndex(int32_t index) const override
Get a field by index.
bool Equals(const Type &other) const override
Compare two types for equality.
std::span< const SchemaField > fields() const override
Get a view of the child fields.
Result< std::optional< SchemaFieldConstRef > > GetFieldByName(std::string_view name, bool case_sensitive) const override
Get a field by name. Return an error Status if the field name is not unique; prefer GetFieldById or G...
MapType(SchemaField key, SchemaField value)
Construct a map of the given key/value fields.
TypeId type_id() const override
Get the type ID.
Result< std::optional< SchemaFieldConstRef > > GetFieldById(int32_t field_id) const override
Get a field by field ID.
A data type that has child fields.
Definition type.h:85
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.
Result< std::optional< SchemaFieldConstRef > > GetFieldByName(std::string_view name) const
Get a field by name (case-sensitive).
bool is_primitive() const override
Is this a primitive type (may not have child fields)?
Definition type.h:87
bool is_nested() const override
Is this a nested type (may have child fields)?
Definition type.h:88
A data type that does not have child fields.
Definition type.h:78
bool is_primitive() const override
Is this a primitive type (may not have child fields)?
Definition type.h:80
bool is_nested() const override
Is this a nested type (may have child fields)?
Definition type.h:81
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:496
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing a struct with nested fields.
Definition type.h:119
TypeId type_id() const override
Get the type ID.
std::span< const SchemaField > fields() const override
Get a view of the child fields.
std::string ToString() const override
Get a user-readable string representation.
Result< std::optional< SchemaFieldConstRef > > GetFieldById(int32_t field_id) const override
Get a field by field ID.
Result< std::optional< SchemaFieldConstRef > > GetFieldByIndex(int32_t index) const override
Get a field by index.
bool Equals(const Type &other) const override
Compare two types for equality.
Result< std::optional< SchemaFieldConstRef > > GetFieldByName(std::string_view name, bool case_sensitive) const override
Get a field by name. Return an error Status if the field name is not unique; prefer GetFieldById or G...
A data type representing a wall clock time in microseconds without reference to a timezone or date.
Definition type.h:379
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
TypeId type_id() const override
Get the type ID.
A base class for any timestamp time (irrespective of unit or timezone).
Definition type.h:395
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 nanoseconds without reference to a timezone.
Definition type.h:443
std::string ToString() const override
Get a user-readable string representation.
TimeUnit time_unit() const override
The time resolution.
bool Equals(const Type &other) const override
Compare two types for equality.
TypeId type_id() const override
Get the type ID.
bool is_zoned() const override
Is this type zoned or naive?
A data type representing a timestamp in microseconds without reference to a timezone.
Definition type.h:405
std::string ToString() const override
Get a user-readable string representation.
TypeId type_id() const override
Get the type ID.
bool is_zoned() const override
Is this type zoned or naive?
TimeUnit time_unit() const override
The time resolution.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing a timestamp as nanoseconds since the epoch in UTC. A time zone or offset is ...
Definition type.h:462
TypeId type_id() const override
Get the type ID.
TimeUnit time_unit() const override
The time resolution.
bool is_zoned() const override
Is this type zoned or naive?
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
A data type representing a timestamp as microseconds since the epoch in UTC. A time zone or offset is...
Definition type.h:424
bool is_zoned() const override
Is this type zoned or naive?
TimeUnit time_unit() const override
The time resolution.
bool Equals(const Type &other) const override
Compare two types for equality.
std::string ToString() const override
Get a user-readable string representation.
TypeId type_id() const override
Get the type ID.
Interface for a data type for a field.
Definition type.h:44
bool is_struct() const
Is this a struct type?
Definition type.h:58
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)?
bool is_variant() const
Is this a variant type?
Definition type.h:67
friend bool operator==(const Type &lhs, const Type &rhs)
Compare two types for equality.
Definition type.h:70
virtual bool Equals(const Type &other) const =0
Compare two types for equality.
bool is_list() const
Is this a list type?
Definition type.h:61
bool is_map() const
Is this a map type?
Definition type.h:64
A null-only placeholder type used when a more specific type is not known.
Definition type.h:550
TypeId type_id() const override
Get the type ID.
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
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:535
TypeId type_id() const override
Get the type ID.
bool Equals(const Type &other) const override
Compare two types for equality.
std::string ToString() const override
Get a user-readable string representation.
A semi-structured type whose structure may vary across rows.
Definition type.h:233
bool is_nested() const override
Is this a nested type (may have child fields)?
Definition type.h:241
std::string ToString() const override
Get a user-readable string representation.
bool Equals(const Type &other) const override
Compare two types for equality.
bool is_primitive() const override
Is this a primitive type (may not have child fields)?
Definition type.h:240
TypeId type_id() const override
Get the type ID.
ICEBERG_EXPORT const std::shared_ptr< GeographyType > & geography()
Return the default GeographyType instance.
ICEBERG_EXPORT const std::shared_ptr< TimestampNsType > & timestamp_ns()
Return a TimestampNsType instance.
ICEBERG_EXPORT const std::shared_ptr< VariantType > & variant()
Return a VariantType instance.
ICEBERG_EXPORT const std::shared_ptr< BinaryType > & binary()
Return a BinaryType instance.
ICEBERG_EXPORT const std::shared_ptr< DateType > & date()
Return a DateType instance.
ICEBERG_EXPORT std::shared_ptr< MapType > map(SchemaField key, SchemaField value)
Create a MapType with the given key and value fields.
ICEBERG_EXPORT std::shared_ptr< ListType > list(SchemaField element)
Create a ListType with the given element field.
ICEBERG_EXPORT const std::shared_ptr< TimestampTzType > & timestamp_tz()
Return a TimestampTzType instance.
ICEBERG_EXPORT const std::shared_ptr< UnknownType > & unknown()
Return an UnknownType 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.
ICEBERG_EXPORT const std::shared_ptr< TimestampTzNsType > & timestamptz_ns()
Return a TimestampTzNsType instance.
ICEBERG_EXPORT std::shared_ptr< FixedType > fixed(int32_t length)
Create a FixedType with the given length.
ICEBERG_EXPORT const std::shared_ptr< FloatType > & float32()
Return a FloatType instance.
ICEBERG_EXPORT std::shared_ptr< StructType > struct_(std::vector< SchemaField > fields)
Create a StructType with the given fields.
ICEBERG_EXPORT const std::shared_ptr< GeometryType > & geometry()
Return the default GeometryType instance.
ICEBERG_EXPORT std::shared_ptr< DecimalType > decimal(int32_t precision, int32_t scale)
Create a DecimalType with the given precision and scale.
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.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
TimeUnit
The time unit. In Iceberg V3 nanoseconds are also supported.
Definition type_fwd.h:62
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
EdgeAlgorithm
The algorithm used to interpolate geography edges.
Definition type_fwd.h:68
std::expected< T, E > Result
Result alias.
Definition result.h:88
ICEBERG_EXPORT Result< EdgeAlgorithm > EdgeAlgorithmFromString(std::string_view name)
Parse a lowercase edge algorithm name.
TypeId
A data type.
Definition type_fwd.h:35
Define Result, Status, and error helpers.