Skip to content

schemas

Arrow Flight schema definitions.

count

count()

Create an Arrow Flight schema for count.

Returns:

Type Description
Schema

The count schema.

Source code in arrakis/schemas.py
63
64
65
66
67
68
69
70
71
72
def count() -> pyarrow.Schema:
    """Create an Arrow Flight schema for `count`.

    Returns
    -------
    pyarrow.Schema
        The count schema.

    """
    return pyarrow.schema([pyarrow.field("count", pyarrow.int64())])

metadata

metadata(scope=None)

Create an Arrow Flight metadata schema.

Parameters:

Name Type Description Default
scope None | str

Metadata scope, currently accepts only None or "partition".

None

Returns:

Type Description
Schema

The metadata schema.

Source code in arrakis/schemas.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def metadata(scope: str | None = None) -> pyarrow.Schema:
    """Create an Arrow Flight metadata schema.

    Parameters
    ----------
    scope : None | str
        Metadata scope, currently accepts only None or "partition".

    Returns
    -------
    pyarrow.Schema
        The metadata schema.

    """
    fields = [
        "name",
        "data_type",
        "sample_rate",
        "partition_id",
        "partition_index",
    ]
    if scope != "partition":
        fields.extend(
            [
                "publisher",
                "stride",
                "max_latency",
                "replay_id",
            ]
        )
    schema_fields: list[pyarrow.Field] = [METADATA_FIELDS[f] for f in fields]
    return pyarrow.schema(schema_fields)

publish

publish()

Create an Arrow Flight schema for publish.

Returns:

Type Description
Schema

The publish schema.

Source code in arrakis/schemas.py
101
102
103
104
105
106
107
108
109
110
111
def publish() -> pyarrow.Schema:
    """Create an Arrow Flight schema for `publish`.

    Returns
    -------
    pyarrow.Schema
        The publish schema.

    """
    dtype = pyarrow.map_(pyarrow.string(), pyarrow.string())
    return pyarrow.schema([pyarrow.field("properties", dtype, nullable=False)])

stream

stream(channels)

Create an Arrow Flight schema for stream.

Parameters:

Name Type Description Default
channels Iterable[Channel]

The list of channels for the stream request.

required

Returns:

Type Description
Schema

The stream schema.

Source code in arrakis/schemas.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def stream(channels: Iterable[Channel]) -> pyarrow.Schema:
    """Create an Arrow Flight schema for `stream`.

    Parameters
    ----------
    channels : Iterable[Channel]
        The list of channels for the stream request.

    Returns
    -------
    pyarrow.Schema
        The stream schema.

    """
    columns: list[pyarrow.Field] = [
        pyarrow.field("time", pyarrow.int64(), nullable=False),
    ]
    for channel in channels:
        dtype = pyarrow.from_numpy_dtype(channel.data_type)  # type: ignore[arg-type]
        field = pyarrow.field(channel.name, pyarrow.list_(dtype)).with_metadata(
            {"rate": str(channel.sample_rate)}
        )
        columns.append(field)
    return pyarrow.schema(columns)