conversions
Utility module for various conversions around PrimitiveType implementations.
This module enables
- Converting partition strings to built-in python objects.
- Converting a value to a byte buffer.
- Converting a byte buffer to a value.
- Converting a json-single field serialized field
Note
Conversion logic varies based on the PrimitiveType implementation. Therefore conversion functions are defined here as generic functions using the @singledispatch decorator. For each PrimitiveType implementation, a concrete function is registered for each generic conversion function. For PrimitiveType implementations that share the same conversion logic, registrations can be stacked.
_(_, val)
¶
Convert JSON WKT string into WKB bytes per Iceberg spec.
Note: This requires WKT to WKB conversion which is not yet implemented. The Iceberg spec requires geography values to be represented as WKT strings in JSON, but PyIceberg stores geography as WKB bytes at runtime.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
WKT to WKB conversion is not yet supported. |
Source code in pyiceberg/conversions.py
from_bytes(primitive_type, b)
¶
Convert bytes to a built-in python value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitive_type
|
PrimitiveType
|
An implementation of the PrimitiveType base class. |
required |
b
|
bytes
|
The bytes to convert. |
required |
Source code in pyiceberg/conversions.py
from_json(primitive_type, val)
¶
Convert JSON value types into built-in python values.
https://iceberg.apache.org/spec/#json-single-value-serialization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitive_type
|
PrimitiveType
|
An implementation of the PrimitiveType base class. |
required |
val
|
Any
|
The arbitrary JSON value to convert into the right form |
required |
Source code in pyiceberg/conversions.py
handle_none(func)
¶
Handle cases where partition values are None or "HIVE_DEFAULT_PARTITION".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
A function registered to the singledispatch function |
required |
Source code in pyiceberg/conversions.py
partition_to_py(primitive_type, value_str)
¶
Convert a partition string to a python built-in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitive_type
|
PrimitiveType
|
An implementation of the PrimitiveType base class. |
required |
value_str
|
str
|
A string representation of a partition value. |
required |
Source code in pyiceberg/conversions.py
to_bytes(primitive_type, _)
¶
Convert a built-in python value to bytes.
This conversion follows the serialization scheme for storing single values as individual binary values defined in the Iceberg specification that can be found at https://iceberg.apache.org/spec/#appendix-d-single-value-serialization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitive_type
|
PrimitiveType
|
An implementation of the PrimitiveType base class. |
required |
_
|
bool | bytes | Decimal | date | datetime | float | int | str | time | UUID
|
The value to convert to bytes (The type of this value depends on which dispatched function is used--check dispatchable functions for type hints). |
required |
Source code in pyiceberg/conversions.py
to_json(primitive_type, val)
¶
Convert built-in python values into JSON value types.
https://iceberg.apache.org/spec/#json-single-value-serialization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitive_type
|
PrimitiveType
|
An implementation of the PrimitiveType base class. |
required |
val
|
Any
|
The arbitrary built-in value to convert into the right form |
required |