26#include <unordered_map>
27#include <unordered_set>
30#include "iceberg/iceberg_export.h"
31#include "iceberg/result.h"
34#include "iceberg/util/string_util.h"
45 std::unordered_map<int32_t, std::reference_wrapper<const SchemaField>>&
52 std::unordered_map<int32_t, std::reference_wrapper<const SchemaField>>& id_to_field_;
60 std::unordered_map<std::string, int32_t,
StringHash, std::equal_to<>>& name_to_id,
61 std::unordered_map<int32_t, std::string>* id_to_name,
bool case_sensitive =
true,
62 std::function<std::string(std::string_view)> quoting_func = {});
63 Status Visit(
const ListType& type,
const std::string& path,
64 const std::string& short_path);
65 Status
Visit(
const MapType& type,
const std::string& path,
66 const std::string& short_path);
68 const std::string& short_path);
70 const std::string& short_path);
72 const std::string& short_path);
76 std::string BuildPath(std::string_view prefix, std::string_view field_name,
81 std::unordered_map<std::string, int32_t, StringHash, std::equal_to<>>& name_to_id_;
82 std::unordered_map<int32_t, std::string>* id_to_name_;
83 std::unordered_map<std::string, int32_t, StringHash, std::equal_to<>> short_name_to_id_;
84 std::function<std::string(std::string_view)> quoting_func_;
95 std::unordered_map<int32_t, std::vector<size_t>> Finish();
98 constexpr static int32_t kUnassignedFieldId = -1;
99 int32_t current_field_id_ = kUnassignedFieldId;
100 std::vector<size_t> current_path_;
101 std::unordered_map<int32_t, std::vector<size_t>> position_path_;
115 bool select_full_types);
117 Result<std::shared_ptr<Type>> Visit(
const std::shared_ptr<Type>& type)
const;
120 Result<std::shared_ptr<Type>>
Visit(
const std::shared_ptr<StructType>& type)
const;
121 Result<std::shared_ptr<Type>>
Visit(
const std::shared_ptr<ListType>& type)
const;
122 Result<std::shared_ptr<Type>>
Visit(
const std::shared_ptr<MapType>& type)
const;
125 const std::unordered_set<int32_t>& selected_ids_;
126 const bool select_full_types_;
134 Status Visit(
const Type& type);
137 std::unordered_set<int32_t> Finish()
const;
139 static Result<std::unordered_set<int32_t>> GetProjectedIds(
140 const Type& type,
bool include_struct_ids =
false);
143 const bool include_struct_ids_;
144 std::unordered_set<int32_t> ids_;
155ICEBERG_EXPORT std::unordered_map<int32_t, int32_t> IndexParents(
163 std::shared_ptr<Type> Visit(
const std::shared_ptr<Type>& type)
const;
166 std::shared_ptr<MapType>
Visit(
const MapType& type)
const;
169 std::function<int32_t()> next_id_;
178ICEBERG_EXPORT Result<std::shared_ptr<Schema>> AssignFreshIds(
179 int32_t schema_id,
const Schema& schema, std::function<int32_t()> next_id);
192ICEBERG_EXPORT
bool IsPromotionAllowed(
const std::shared_ptr<Type>& from_type,
193 const std::shared_ptr<Type>& to_type);
Assigns fresh IDs to all fields in the schema.
Definition type_util.h:159
Visitor for getting projected field IDs.
Definition type_util.h:130
Visitor for building a map from field ID to SchemaField reference.
Definition type_util.h:42
A data type representing a list of values.
Definition type.h:156
A data type representing a dictionary of values.
Definition type.h:191
Visitor for building maps from field name to field ID and field ID to field name.
Definition type_util.h:57
A data type that has child fields.
Definition type.h:85
Visitor for building a map from field ID to position path.
Definition type_util.h:88
A data type that does not have child fields.
Definition type.h:78
Visitor for pruning columns based on selected field IDs.
Definition type_util.h:112
A type combined with a name.
Definition schema_field.h:39
A schema for a Table.
Definition schema.h:51
A data type representing a struct with nested fields.
Definition type.h:119
Interface for a data type for a field.
Definition type.h:44
A semi-structured type whose structure may vary across rows.
Definition type.h:233
Result< R > Visit(const std::shared_ptr< Expression > &expr, V &visitor)
Traverse an expression tree with a visitor.
Definition expression_visitor.h:283
Transparent hash function that supports std::string_view as lookup key.
Definition string_util.h:154