iceberg-cpp
Loading...
Searching...
No Matches
Classes | Functions
type_util.h File Reference
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "iceberg/iceberg_export.h"
#include "iceberg/result.h"
#include "iceberg/schema_field.h"
#include "iceberg/type_fwd.h"
#include "iceberg/util/string_util.h"

Go to the source code of this file.

Classes

class  iceberg::IdToFieldVisitor
 Visitor for building a map from field ID to SchemaField reference. More...
 
class  iceberg::NameToIdVisitor
 Visitor for building maps from field name to field ID and field ID to field name. More...
 
class  iceberg::PositionPathVisitor
 Visitor for building a map from field ID to position path. More...
 
class  iceberg::PruneColumnVisitor
 Visitor for pruning columns based on selected field IDs. More...
 
class  iceberg::GetProjectedIdsVisitor
 Visitor for getting projected field IDs. More...
 
class  iceberg::AssignFreshIdVisitor
 Assigns fresh IDs to all fields in the schema. More...
 

Functions

std::unordered_map< int32_t, int32_t > iceberg::IndexParents (const StructType &root_struct)
 Index parent field IDs for all fields in a struct hierarchy.
 
Result< std::shared_ptr< Schema > > iceberg::AssignFreshIds (int32_t schema_id, const Schema &schema, std::function< int32_t()> next_id)
 Assigns fresh IDs to all fields in a schema.
 
bool iceberg::IsPromotionAllowed (const std::shared_ptr< Type > &from_type, const std::shared_ptr< Type > &to_type)
 Check if type promotion from one type to another is allowed.
 

Detailed Description

Utility functions and visitors for Iceberg types.

Function Documentation

◆ AssignFreshIds()

ICEBERG_EXPORT Result< std::shared_ptr< Schema > > iceberg::AssignFreshIds ( int32_t  schema_id,
const Schema schema,
std::function< int32_t()>  next_id 
)

Assigns fresh IDs to all fields in a schema.

Parameters
schema_idAn ID assigned to this schema
schemaThe schema to assign IDs to.
next_idAn id assignment function, which returns the next ID to assign.
Returns
A schema with new ids assigned by the next_id function.

◆ IndexParents()

ICEBERG_EXPORT std::unordered_map< int32_t, int32_t > iceberg::IndexParents ( const StructType root_struct)

Index parent field IDs for all fields in a struct hierarchy.

Parameters
root_structThe root struct type to analyze
Returns
A map from field ID to its parent struct field ID
Note
This function assumes the input StructType has already been validated:
  • All field IDs must be non-negative
  • All field IDs must be unique across the entire schema hierarchy If the struct is part of a Schema, these invariants are enforced by StructType::InitFieldById which checks for duplicate field IDs.

◆ IsPromotionAllowed()

ICEBERG_EXPORT bool iceberg::IsPromotionAllowed ( const std::shared_ptr< Type > &  from_type,
const std::shared_ptr< Type > &  to_type 
)

Check if type promotion from one type to another is allowed.

Type promotion rules:

  • int -> long
  • float -> double
  • decimal(P,S) -> decimal(P',S) where P' > P
Parameters
from_typeThe original type
to_typeThe target type
Returns
true if promotion is allowed, false otherwise