Schema
Schema and field
Schemas, fields, and data types are provided in the deltalake.schema
submodule.
deltalake.Schema
Bases: deltalake._internal.StructType
A Delta Lake schema
Create using a list of :class:Field
:
Schema([Field("x", "integer"), Field("y", "string")]) Schema([Field(x, PrimitiveType("integer"), nullable=True), Field(y, PrimitiveType("string"), nullable=True)])
Or create from a PyArrow schema:
import pyarrow as pa Schema.from_pyarrow(pa.schema({"x": pa.int32(), "y": pa.string()})) Schema([Field(x, PrimitiveType("integer"), nullable=True), Field(y, PrimitiveType("string"), nullable=True)])
invariants
invariants: List[Tuple[str, str]] = <attribute 'invariants' of 'deltalake._internal.Schema' objects>
from_json
staticmethod
Create a new Schema from a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json |
str
|
a JSON string |
required |
from_pyarrow
staticmethod
to_json
method descriptor
to_pyarrow
method descriptor
Return equivalent PyArrow schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
as_large_types |
bool
|
get schema with all variable size types (list, binary, string) as large variants (with int64 indices). This is for compatibility with systems like Polars that only support the large versions of Arrow types. |
False
|
Returns:
Type | Description |
---|---|
Schema
|
a PyArrow Schema |
deltalake.Field
Field(name: str, type: DataType, *, nullable: bool = True, metadata: Optional[Dict[str, Any]] = None)
from_json
staticmethod
Create a Field from a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json |
str
|
the JSON string. |
required |
Returns:
Type | Description |
---|---|
Field
|
Field |
from_pyarrow
staticmethod
to_json
method descriptor
to_pyarrow
method descriptor
Convert to an equivalent PyArrow field Note: This currently doesn't preserve field metadata.
Returns:
Type | Description |
---|---|
Field
|
a pyarrow Field |
Data types
deltalake.schema.PrimitiveType
from_json
staticmethod
Create a PrimitiveType from a JSON string
The JSON representation for a primitive type is just a quoted string: PrimitiveType.from_json('"integer"')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json |
str
|
a JSON string |
required |
Returns:
Type | Description |
---|---|
PrimitiveType
|
a PrimitiveType type |
from_pyarrow
staticmethod
Create a PrimitiveType from a PyArrow datatype
Will raise TypeError
if the PyArrow type is not a primitive type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
DataType
|
A PyArrow DataType |
required |
Returns:
Type | Description |
---|---|
PrimitiveType
|
a PrimitiveType |
deltalake.schema.ArrayType
contains_null
element_type
from_json
staticmethod
Create an ArrayType from a JSON string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json |
str
|
a JSON string |
required |
Returns:
Type | Description |
---|---|
ArrayType
|
an ArrayType |
from_pyarrow
staticmethod
deltalake.schema.MapType
value_contains_null
value_contains_null: bool = <attribute 'value_contains_null' of 'deltalake._internal.MapType' objects>
from_json
staticmethod
Create a MapType from a JSON string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json |
str
|
a JSON string |
required |
Returns:
Type | Description |
---|---|
MapType
|
an ArrayType |
Example
The JSON representation for a map type is an object with type
(set to map
),
keyType
, valueType
, and valueContainsNull
:
from_pyarrow
staticmethod
to_json
method descriptor
Get JSON string representation of map type.
Returns:
Type | Description |
---|---|
str
|
a JSON string |
deltalake.schema.StructType
type
The string "struct"
from_json
staticmethod
Create a new StructType from a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json |
str
|
a JSON string |
required |
Returns:
Type | Description |
---|---|
StructType
|
a StructType |
from_pyarrow
staticmethod
Create a new StructType from a PyArrow struct type.
Will raise TypeError
if a different data type is provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
StructType
|
a PyArrow struct type. |
required |
Returns:
Type | Description |
---|---|
StructType
|
a StructType |