schema
Accessor
dataclass
¶
An accessor for a specific position in a container that implements the StructProtocol.
Source code in pyiceberg/schema.py
__repr__()
¶
__str__()
¶
get(container)
¶
Return the value at self.position in container
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container
|
StructProtocol
|
A container to access at position |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The value at position |
Source code in pyiceberg/schema.py
PartnerAccessor
¶
Bases: Generic[P]
, ABC
Source code in pyiceberg/schema.py
PreOrderSchemaVisitor
¶
Bases: Generic[T]
, ABC
Source code in pyiceberg/schema.py
PrimitiveWithPartnerVisitor
¶
Bases: SchemaWithPartnerVisitor[P, T]
Source code in pyiceberg/schema.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|
primitive(primitive, primitive_partner)
¶
Visit a PrimitiveType.
Source code in pyiceberg/schema.py
visit_binary(binary_type, partner)
abstractmethod
¶
visit_boolean(boolean_type, partner)
abstractmethod
¶
visit_date(date_type, partner)
abstractmethod
¶
visit_decimal(decimal_type, partner)
abstractmethod
¶
visit_double(double_type, partner)
abstractmethod
¶
visit_fixed(fixed_type, partner)
abstractmethod
¶
visit_float(float_type, partner)
abstractmethod
¶
visit_integer(integer_type, partner)
abstractmethod
¶
visit_long(long_type, partner)
abstractmethod
¶
visit_string(string_type, partner)
abstractmethod
¶
visit_time(time_type, partner)
abstractmethod
¶
visit_timestamp(timestamp_type, partner)
abstractmethod
¶
visit_timestamptz(timestamptz_type, partner)
abstractmethod
¶
Schema
¶
Bases: IcebergBaseModel
A table Schema.
Example
from pyiceberg import schema from pyiceberg import types
Source code in pyiceberg/schema.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
column_names: List[str]
property
¶
Return a list of all the column names, including nested fields.
Excludes short names.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: The column names. |
columns: Tuple[NestedField, ...]
property
¶
A tuple of the top-level fields.
field_ids: Set[int]
property
¶
Return the IDs of the current schema.
__eq__(other)
¶
Return the equality of two instances of the Schema class.
Source code in pyiceberg/schema.py
__len__()
¶
__repr__()
¶
Return the string representation of the Schema class.
__str__()
¶
accessor_for_field(field_id)
¶
Find a schema position accessor given a field ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field_id
|
int
|
The ID of the field. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
When the value cannot be found. |
Returns:
Name | Type | Description |
---|---|---|
Accessor |
Accessor
|
An accessor for the given field ID. |
Source code in pyiceberg/schema.py
as_arrow()
¶
as_struct()
¶
find_column_name(column_id)
¶
Find a column name given a column ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_id
|
int
|
The ID of the column. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Optional[str]
|
The column name (or None if the column ID cannot be found). |
Source code in pyiceberg/schema.py
find_field(name_or_id, case_sensitive=True)
¶
Find a field using a field name or field ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_id
|
Union[str, int]
|
Either a field name or a field ID. |
required |
case_sensitive
|
bool
|
Whether to perform a case-sensitive lookup using a field name. Defaults to True. |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
When the value cannot be found. |
Returns:
Name | Type | Description |
---|---|---|
NestedField |
NestedField
|
The matched NestedField. |
Source code in pyiceberg/schema.py
find_type(name_or_id, case_sensitive=True)
¶
Find a field type using a field name or field ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_id
|
Union[str, int]
|
Either a field name or a field ID. |
required |
case_sensitive
|
bool
|
Whether to perform a case-sensitive lookup using a field name. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
NestedField |
IcebergType
|
The type of the matched NestedField. |
Source code in pyiceberg/schema.py
identifier_field_names()
¶
Return the names of the identifier fields.
Returns:
Type | Description |
---|---|
Set[str]
|
Set of names of the identifier fields |
Source code in pyiceberg/schema.py
select(*names, case_sensitive=True)
¶
Return a new schema instance pruned to a subset of columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names
|
List[str]
|
A list of column names. |
()
|
case_sensitive
|
bool
|
Whether to perform a case-sensitive lookup for each column name. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
Schema |
Schema
|
A new schema with pruned columns. |
Raises:
Type | Description |
---|---|
ValueError
|
If a column is selected that doesn't exist. |
Source code in pyiceberg/schema.py
SchemaVisitor
¶
Bases: Generic[T]
, ABC
Source code in pyiceberg/schema.py
after_field(field)
¶
after_list_element(element)
¶
Override this method to perform an action immediately after visiting an element within a ListType.
after_map_key(key)
¶
Override this method to perform an action immediately after visiting a key within a MapType.
after_map_value(value)
¶
Override this method to perform an action immediately after visiting a value within a MapType.
before_field(field)
¶
before_list_element(element)
¶
Override this method to perform an action immediately before visiting an element within a ListType.
before_map_key(key)
¶
Override this method to perform an action immediately before visiting a key within a MapType.
before_map_value(value)
¶
Override this method to perform an action immediately before visiting a value within a MapType.
field(field, field_result)
abstractmethod
¶
list(list_type, element_result)
abstractmethod
¶
map(map_type, key_result, value_result)
abstractmethod
¶
primitive(primitive)
abstractmethod
¶
schema(schema, struct_result)
abstractmethod
¶
SchemaVisitorPerPrimitiveType
¶
Bases: SchemaVisitor[T]
, ABC
Source code in pyiceberg/schema.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
|
primitive(primitive)
¶
Visit a PrimitiveType.
Source code in pyiceberg/schema.py
visit_binary(binary_type)
abstractmethod
¶
visit_boolean(boolean_type)
abstractmethod
¶
visit_date(date_type)
abstractmethod
¶
visit_decimal(decimal_type)
abstractmethod
¶
visit_double(double_type)
abstractmethod
¶
visit_fixed(fixed_type)
abstractmethod
¶
visit_float(float_type)
abstractmethod
¶
visit_integer(integer_type)
abstractmethod
¶
visit_long(long_type)
abstractmethod
¶
visit_string(string_type)
abstractmethod
¶
visit_time(time_type)
abstractmethod
¶
visit_timestamp(timestamp_type)
abstractmethod
¶
visit_timestamptz(timestamptz_type)
abstractmethod
¶
SchemaWithPartnerVisitor
¶
Bases: Generic[P, T]
, ABC
Source code in pyiceberg/schema.py
after_field(field, field_partner)
¶
after_list_element(element, element_partner)
¶
Override this method to perform an action immediately after visiting an element within a ListType.
after_map_key(key, key_partner)
¶
Override this method to perform an action immediately after visiting a key within a MapType.
after_map_value(value, value_partner)
¶
Override this method to perform an action immediately after visiting a value within a MapType.
before_field(field, field_partner)
¶
before_list_element(element, element_partner)
¶
Override this method to perform an action immediately before visiting an element within a ListType.
before_map_key(key, key_partner)
¶
Override this method to perform an action immediately before visiting a key within a MapType.
before_map_value(value, value_partner)
¶
Override this method to perform an action immediately before visiting a value within a MapType.
field(field, field_partner, field_result)
abstractmethod
¶
list(list_type, list_partner, element_result)
abstractmethod
¶
map(map_type, map_partner, key_result, value_result)
abstractmethod
¶
primitive(primitive, primitive_partner)
abstractmethod
¶
schema(schema, schema_partner, struct_result)
abstractmethod
¶
assign_fresh_schema_ids(schema_or_type, next_id=None)
¶
Traverses the schema, and sets new IDs.
build_position_accessors(schema_or_type)
¶
Generate an index of field IDs to schema position accessors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_or_type
|
Union[Schema, IcebergType]
|
A schema or type to index. |
required |
Returns:
Type | Description |
---|---|
Dict[int, Accessor]
|
Dict[int, Accessor]: An index of field IDs to accessors. |
Source code in pyiceberg/schema.py
index_by_id(schema_or_type)
¶
Generate an index of field IDs to NestedField instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_or_type
|
Union[Schema, IcebergType]
|
A schema or type to index. |
required |
Returns:
Type | Description |
---|---|
Dict[int, NestedField]
|
Dict[int, NestedField]: An index of field IDs to NestedField instances. |
Source code in pyiceberg/schema.py
index_by_name(schema_or_type)
¶
Generate an index of field names to field IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_or_type
|
Union[Schema, IcebergType]
|
A schema or type to index. |
required |
Returns:
Type | Description |
---|---|
Dict[str, int]
|
Dict[str, int]: An index of field names to field IDs. |
Source code in pyiceberg/schema.py
index_name_by_id(schema_or_type)
¶
Generate an index of field IDs full field names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_or_type
|
Union[Schema, IcebergType]
|
A schema or type to index. |
required |
Returns:
Type | Description |
---|---|
Dict[int, str]
|
Dict[str, int]: An index of field IDs to full names. |
Source code in pyiceberg/schema.py
pre_order_visit(obj, visitor)
¶
Apply a schema visitor to any point within a schema.
The function traverses the schema in pre-order fashion. This is a slimmed down version compared to the post-order traversal (missing before and after methods), mostly because we don't use the pre-order traversal much.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Union[Schema, IcebergType]
|
An instance of a Schema or an IcebergType. |
required |
visitor
|
PreOrderSchemaVisitor[T]
|
An instance of an implementation of the generic PreOrderSchemaVisitor base class. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If attempting to visit an unrecognized object type. |
Source code in pyiceberg/schema.py
promote(file_type, read_type)
¶
Promotes reading a file type to a read type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_type
|
IcebergType
|
The type of the Avro file. |
required |
read_type
|
IcebergType
|
The requested read type. |
required |
Raises:
Type | Description |
---|---|
ResolveError
|
If attempting to resolve an unrecognized object type. |
Source code in pyiceberg/schema.py
prune_columns(schema, selected, select_full_types=True)
¶
Prunes a column by only selecting a set of field-ids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
Schema
|
The schema to be pruned. |
required |
selected
|
Set[int]
|
The field-ids to be included. |
required |
select_full_types
|
bool
|
Return the full struct when a subset is recorded |
True
|
Returns:
Type | Description |
---|---|
Schema
|
The pruned schema. |
Source code in pyiceberg/schema.py
sanitize_column_names(schema)
¶
Sanitize column names to make them compatible with Avro.
The column name should be starting with '' or digit followed by a string only contains '', digit or alphabet, otherwise it will be sanitized to conform the avro naming convention.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
Schema
|
The schema to be sanitized. |
required |
Returns:
Type | Description |
---|---|
Schema
|
The sanitized schema. |
Source code in pyiceberg/schema.py
visit(obj, visitor)
¶
Apply a schema visitor to any point within a schema.
The function traverses the schema in post-order fashion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Union[Schema, IcebergType]
|
An instance of a Schema or an IcebergType. |
required |
visitor
|
SchemaVisitor[T]
|
An instance of an implementation of the generic SchemaVisitor base class. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If attempting to visit an unrecognized object type. |