Schemas API
AdjacencyListConf
dataclass
Config for adjacency list structure.
Attributes:
| Name | Type | Description |
|---|---|---|
track_counts |
bool
|
If a counts column should be made. |
counts_dtype |
type[T_counts] | None
|
Dtype of the element count column. Defaults to np.uint8 |
Source code in src/packed_data_structures/schemas/foreign_key_col.py
AsciiStringColSchema
dataclass
Bases: ColSchemaLike[bytes_]
Schema for a fixed-length ASCII byte-string column.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
max_length |
int
|
The maximum allowed length for the string (in bytes). |
default |
bytes | str
|
The default byte-string value. |
Source code in src/packed_data_structures/schemas/ascii_string_col.py
ColSchemaLike
dataclass
Bases: ABC
Base class for all column schemas.
Column schemas are treated as object-identity singletons (id(self))
when used as dictionary keys or accessors. They define a single column
within a TableSchema.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
parent_table |
TableSchema
|
The TableSchema instance this column belongs to. |
Source code in src/packed_data_structures/schemas/col_schema_like.py
set_parent
Bind this column to a parent TableSchema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
TableSchema
|
The TableSchema that will own this column. |
required |
DataColSchema
dataclass
Bases: ColSchemaLike[T]
Schema for a standard data column containing raw values.
Defines the data type, default values, and shape of elements within the column. Maps directly to a PackedArray buffer at runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
dtype |
type[T]
|
The numpy data type of the column's elements. |
default |
Any | tuple[Any, ...]
|
The default value used to fill empty or newly allocated slots. |
shape |
tuple[*T_shape,]
|
The shape of individual elements. An empty tuple indicates scalar values. |
Source code in src/packed_data_structures/schemas/data_col.py
FksOnDeleteStyle
Bases: Enum
Various ForeignKeySchema on referenced row delete behaviors.
Source code in src/packed_data_structures/schemas/foreign_key_col.py
CASCADE
class-attribute
instance-attribute
Cascade the deletion by also deleting the FK row
RESTRICT
class-attribute
instance-attribute
Block the deletion and raise an exception
ForeignKeySchema
dataclass
Bases: ColSchemaLike[T]
Schema for a column of foreign keys that all point into one specific table.
When registered, this schema dynamically injects internal adjacency list columns:
- adj_head (in target table)
- adj_next (in source table)
- adj_prev (in source table)
- adj_count (optional, in target table)
NOTE: The true column names are more verbose
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
T
|
integer[Any]
|
The index dtype of the target table. |
required |
T_parent
|
integer[Any]
|
The index dtype of the parent table. And by extension the |
required |
T_counts
|
integer[Any]
|
The dtype of the counts column (if applicable). |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
target_table |
TableSchema
|
The TableSchema of the table the keys to. |
on_delete |
FksOnDeleteStyle
|
The policy to apply when something tries to delte a row referenced by this column. |
adjacency_conf |
AdjacencyListConf[T_counts]
|
Configuration for the injected adjacency list columns. |
adj_next |
AdjNextIdxColSchema[T_parent]
|
The injected next-pointer column in the parent table. |
adj_prev |
AdjPrevIdxColSchema[T_parent]
|
The injected previous-pointer column in the parent table. |
adj_head |
AdjHeadIdxColSchema[T]
|
The injected head-pointer column in the target table. |
adj_count |
AdjCountColSchema[T_counts]
|
The injected count column in the target table (if enabled). |
Source code in src/packed_data_structures/schemas/foreign_key_col.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 | |
set_parent
Bind this foreign key column to a parent table and inject adjacency columns.
This actively mutates both the parent and target table schemas by registering the hidden adjacency list management columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
TableSchema[T_parent]
|
The TableSchema that will own this foreign key column. |
required |
Source code in src/packed_data_structures/schemas/foreign_key_col.py
IndexSpec
dataclass
Specification for integer indices used to address rows.
Defines the underlying numpy data type, the sentinel value indicating a missing or null link, and the maximum valid row index.
Attributes:
| Name | Type | Description |
|---|---|---|
dtype |
type[T]
|
The numpy integer data type for the index. |
missing |
int
|
The sentinel integer value representing a missing index. |
max_value |
int
|
The maximum valid integer value for an index. |
Source code in src/packed_data_structures/schemas/index_spec.py
from_dtype
classmethod
Create an IndexSpec from a numpy data type.
By standard convention, the maximum representable value of the given integer type is reserved as the missing/sentinel value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
type[T]
|
A numpy integer data type. |
required |
Returns:
| Type | Description |
|---|---|
IndexSpec
|
A new IndexSpec instance. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided dtype is not an integer type. |
Source code in src/packed_data_structures/schemas/index_spec.py
new_array
Helper to allocate raw numpy arrays with correct initialization.
ObjectColSchema
dataclass
Bases: ColSchemaLike[object_]
Schema for a data column that uses numpy C-level object pointer arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
Source code in src/packed_data_structures/schemas/object_col.py
PolymorphicForeignKeySchema
dataclass
Bases: ColSchemaLike[integer[Any]]
Schema for a column of polymorphic foreign keys.
Each key can link to one of a set of tables.
Just like the non-polymorphic FK schema, it automatically injects adjacency list columns:
- adj_head (in target table)
- adj_next (in source table)
- adj_prev (in source table)
- adj_count (optional, in target table)
NOTE: The true column names are more verbose
It also injects a _type_id column, this column encodes which table each key points to.
The smallest possible uint dtype is chosen for the _type_id columm.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
T_parent
|
integer[Any]
|
The index dtype of the parent table. And by extension the |
required |
T_counts
|
integer[Any]
|
The dtype of the counts column (if applicable). |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
target_tables |
Sequence[TableSchema]
|
The ordered collection of TableSchemas that the keys can point to. |
on_delete |
FksOnDeleteStyle
|
The policy to apply when something tries to delete a row referenced by this column. |
adjacency_conf |
AdjacencyListConf[T_counts]
|
Configuration for the injected adjacency list columns. |
keys_idx_spec |
IndexSpec[unsignedinteger[Any]]
|
IndexSpec that holds the dtype and sentinel for the keys. Optmized to be only as big as needed to link into any row of the target tables. |
type_id_dtype |
type[unsignedinteger[Any]]
|
The dtype used for the |
type_id_sentinel |
int
|
The sentinel value for the |
type_id_mapping |
dict[TableSchema, int]
|
Mapping from table to its type id.
This is just a direct mapping to the index of each target in |
type_id_col |
PmFkTypeIdColSchema[unsignedinteger[Any]]
|
The injected |
adj_next |
AdjNextIdxColSchema[T_parent]
|
The injected next-pointer column in the parent table. |
adj_prev |
AdjPrevIdxColSchema[T_parent]
|
The injected previous-pointer column in the parent table. |
adj_head_columns |
list[AdjHeadIdxColSchema[T_parent]]
|
The injected head-pointer columns in the target tables, ordered by |
adj_count_columns |
list[AdjCountColSchema[T_counts]]
|
The injected count columns in the target table (if enabled).
Also ordered by |
Source code in src/packed_data_structures/schemas/pm_foreign_key_col.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 | |
set_parent
Bind this polymorphic foreign key column to a parent table.
This actively mutates both the parent and target table schemas by registering the hidden tag column and adjacency list management columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
TableSchema[T_parent]
|
The TableSchema that will own this foreign key. |
required |
Source code in src/packed_data_structures/schemas/pm_foreign_key_col.py
StringColSchema
dataclass
Bases: ColSchemaLike[str_]
Schema for a fixed-length Unicode string column.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the column. |
max_length |
int
|
The maximum allowed length for the string. |
default |
str
|
The default string value. |
Source code in src/packed_data_structures/schemas/string_col.py
SupportsGetTableSchema
Bases: ABC
Interface for objects that can provide a TableSchema.
Source code in src/packed_data_structures/schemas/table.py
get_table_schema
abstractmethod
Get the underlying TableSchema.
Returns:
| Type | Description |
|---|---|
TableSchema[T_idx]
|
The TableSchema instance. |
TableSchema
dataclass
Bases: SupportsGetTableSchema[T_idx]
Schema definition for a flat, column-oriented table.
A TableSchema aggregates multiple ColSchemaLike definitions and
dictates how the PackedArrayTable initializes its raw buffers.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The string identifier for the table. |
index_spec |
IndexSpec[T_idx]
|
The specification defining the table's index type and capacity. |
cols |
list[ColSchemaLike[Any]]
|
The list of column schemas defining the table structure. |
pre_allocate |
int
|
The initial element capacity to allocate for the table's arrays. |
Source code in src/packed_data_structures/schemas/table.py
register_new_column
Dynamically add a new column to the table schema.
This is primarily used by overlay features and foreign keys to inject hidden management columns prior to initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col
|
ColSchemaLike
|
The column schema to add. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the schema has already been initialized. |
Source code in src/packed_data_structures/schemas/table.py
subscribe
Register a foreign key that targets this table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_subscriber
|
ForeignKeySchema | PolymorphicForeignKeySchema
|
The foreign key schema pointing to this table. |
required |