pyarrow
FileIO implementation for reading and writing table files that uses pyarrow.fs.
This file contains a FileIO implementation that relies on the filesystem interface provided
by PyArrow. It relies on PyArrow's from_uri
method that infers the correct filesystem
type to use. Theoretically, this allows the supported storage types to grow naturally
with the pyarrow library.
PyArrowFile
Bases: InputFile
, OutputFile
A combined InputFile and OutputFile implementation that uses a pyarrow filesystem to generate pyarrow.lib.NativeFile instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
str
|
A URI or a path to a local file. |
required |
Attributes:
Name | Type | Description |
---|---|---|
location(str) |
The URI or path to a local file for a PyArrowFile instance. |
Examples:
>>> from pyiceberg.io.pyarrow import PyArrowFile
>>> # input_file = PyArrowFile("s3://foo/bar.txt")
>>> # Read the contents of the PyArrowFile instance
>>> # Make sure that you have permissions to read/write
>>> # file_content = input_file.open().read()
>>> # output_file = PyArrowFile("s3://baz/qux.txt")
>>> # Write bytes to a file
>>> # Make sure that you have permissions to read/write
>>> # output_file.create().write(b'foobytes')
Source code in pyiceberg/io/pyarrow.py
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 |
|
__len__()
create(overwrite=False)
Create a writable pyarrow.lib.NativeFile for this PyArrowFile's location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overwrite |
bool
|
Whether to overwrite the file if it already exists. |
False
|
Returns:
Type | Description |
---|---|
OutputStream
|
pyarrow.lib.NativeFile: A NativeFile instance for the file located at self.location. |
Raises:
Type | Description |
---|---|
FileExistsError
|
If the file already exists at |
Note
This retrieves a pyarrow NativeFile by opening an output stream. If overwrite is set to False, a check is first performed to verify that the file does not exist. This is not thread-safe and a possibility does exist that the file can be created by a concurrent process after the existence check yet before the output stream is created. In such a case, the default pyarrow behavior will truncate the contents of the existing file when opening the output stream.
Source code in pyiceberg/io/pyarrow.py
exists()
open(seekable=True)
Open the location using a PyArrow FileSystem inferred from the location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seekable |
bool
|
If the stream should support seek, or if it is consumed sequential. |
True
|
Returns:
Type | Description |
---|---|
InputStream
|
pyarrow.lib.NativeFile: A NativeFile instance for the file located at |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the file at self.location does not exist. |
PermissionError
|
If the file at self.location cannot be accessed due to a permission error such as an AWS error code 15. |
Source code in pyiceberg/io/pyarrow.py
to_input_file()
Return a new PyArrowFile for the location of an existing PyArrowFile instance.
This method is included to abide by the OutputFile abstract base class. Since this implementation uses a single PyArrowFile class (as opposed to separate InputFile and OutputFile implementations), this method effectively returns a copy of the same instance.
Source code in pyiceberg/io/pyarrow.py
PyArrowFileIO
Bases: FileIO
Source code in pyiceberg/io/pyarrow.py
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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
delete(location)
Delete the file at the given location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
Union[str, InputFile, OutputFile]
|
The URI to the file--if an InputFile instance or an OutputFile instance is provided, the location attribute for that instance is used as the location to delete. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
When the file at the provided location does not exist. |
PermissionError
|
If the file at the provided location cannot be accessed due to a permission error such as an AWS error code 15. |
Source code in pyiceberg/io/pyarrow.py
new_input(location)
Get a PyArrowFile instance to read bytes from the file at the given location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
str
|
A URI or a path to a local file. |
required |
Returns:
Name | Type | Description |
---|---|---|
PyArrowFile |
PyArrowFile
|
A PyArrowFile instance for the given location. |
Source code in pyiceberg/io/pyarrow.py
new_output(location)
Get a PyArrowFile instance to write bytes to the file at the given location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
str
|
A URI or a path to a local file. |
required |
Returns:
Name | Type | Description |
---|---|---|
PyArrowFile |
PyArrowFile
|
A PyArrowFile instance for the given location. |
Source code in pyiceberg/io/pyarrow.py
parse_location(location)
staticmethod
Return the path without the scheme.
Source code in pyiceberg/io/pyarrow.py
PyArrowSchemaVisitor
Bases: Generic[T]
, ABC
Source code in pyiceberg/io/pyarrow.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)
after_map_value(value)
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)
before_map_value(value)
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
compute_statistics_plan(schema, table_properties)
Compute the statistics plan for all columns.
The resulting list is assumed to have the same length and same order as the columns in the pyarrow table. This allows the list to map from the column index to the Iceberg column ID. For each element, the desired metrics collection that was provided by the user in the configuration is computed and then adjusted according to the data type of the column. For nested columns the minimum and maximum values are not computed. And truncation is only applied to text of binary strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_properties |
from pyiceberg.table.metadata.TableMetadata
|
The Iceberg table metadata properties. They are required to compute the mapping of column position to iceberg schema type id. It's also used to set the mode for column metrics collection |
required |
Source code in pyiceberg/io/pyarrow.py
fill_parquet_file_metadata(data_file, parquet_metadata, stats_columns, parquet_column_mapping)
Compute and fill the following fields of the DataFile object.
- file_format
- column_sizes
- value_counts
- null_value_counts
- nan_value_counts
- lower_bounds
- upper_bounds
- split_offsets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file |
DataFile
|
A DataFile object representing the Parquet file for which metadata is to be filled. |
required |
parquet_metadata |
FileMetaData
|
A pyarrow metadata object. |
required |
stats_columns |
Dict[int, StatisticsCollector]
|
The statistics gathering plan. It is required to set the mode for column metrics collection |
required |
Source code in pyiceberg/io/pyarrow.py
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 |
|
parquet_path_to_id_mapping(schema)
Compute the mapping of parquet column path to Iceberg ID.
For each column, the parquet file metadata has a path_in_schema attribute that follows a specific naming scheme for nested columnds. This function computes a mapping of the full paths to the corresponding Iceberg IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema |
Schema
|
The current table schema. |
required |
Source code in pyiceberg/io/pyarrow.py
project_table(tasks, table, row_filter, projected_schema, case_sensitive=True, limit=None)
Resolve the right columns based on the identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tasks |
Iterable[FileScanTask]
|
A URI or a path to a local file. |
required |
table |
Table
|
The table that's being queried. |
required |
row_filter |
BooleanExpression
|
The expression for filtering rows. |
required |
projected_schema |
Schema
|
The output schema. |
required |
case_sensitive |
bool
|
Case sensitivity when looking up column names. |
True
|
limit |
Optional[int]
|
Limit the number of records. |
None
|
Raises:
Type | Description |
---|---|
ResolveError
|
When an incompatible query is done. |
Source code in pyiceberg/io/pyarrow.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 |
|
visit_pyarrow(obj, visitor)
Apply a pyarrow schema visitor to any point within a schema.
The function traverses the schema in post-order fashion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Union[DataType, Schema]
|
An instance of a Schema or an IcebergType. |
required |
visitor |
PyArrowSchemaVisitor[T]
|
An instance of an implementation of the generic PyarrowSchemaVisitor base class. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If attempting to visit an unrecognized object type. |