graphcast.architecture.transform
¶
Data transformation and mapping system for graph databases.
This module provides a flexible system for transforming and mapping data in graph databases. It supports both functional transformations and declarative mappings, with support for field switching and parameter configuration.
Key Components
- ProtoTransform: Base class for transform definitions
- Transform: Concrete transform implementation
- TransformException: Custom exception for transform errors
The transform system supports
- Functional transformations through imported modules
- Field mapping and switching
- Parameter configuration
- Input/output field specification
- Transform composition and inheritance
Example
transform = Transform( ... module="my_module", ... foo="process_data", ... input=("field1", "field2"), ... output=("result1", "result2") ... ) result = transform({"field1": 1, "field2": 2})
ProtoTransform
dataclass
¶
Bases: BaseDataclass
Base class for transform definitions.
This class provides the foundation for data transformations, supporting both functional transformations and declarative mappings.
Attributes:
Name | Type | Description |
---|---|---|
name |
Optional[str]
|
Optional name of the transform |
module |
Optional[str]
|
Optional module containing the transform function |
params |
dict
|
Dictionary of transform parameters |
foo |
Optional[str]
|
Optional name of the transform function |
input |
tuple[str, ...]
|
Tuple of input field names |
output |
tuple[str, ...]
|
Tuple of output field names |
_foo |
tuple[str, ...]
|
Internal reference to the transform function |
Source code in graphcast/architecture/transform.py
__lt__(other)
¶
Compare transforms for ordering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Other transform to compare with |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if this transform should be ordered before other |
Source code in graphcast/architecture/transform.py
__post_init__()
¶
Initialize the transform after dataclass initialization.
Sets up the transform function and input/output field specifications.
Source code in graphcast/architecture/transform.py
Transform
dataclass
¶
Bases: ProtoTransform
Concrete transform implementation.
This class extends ProtoTransform with additional functionality for field mapping, switching, and transform composition.
Attributes:
Name | Type | Description |
---|---|---|
fields |
tuple[str, ...]
|
Tuple of fields to transform |
map |
dict[str, str]
|
Dictionary mapping input fields to output fields |
switch |
dict[str, str]
|
Dictionary for field switching logic |
functional_transform |
dict[str, str]
|
Whether this is a functional transform |
Source code in graphcast/architecture/transform.py
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 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 |
|
is_dummy
property
¶
Check if this is a dummy transform.
Returns:
Name | Type | Description |
---|---|---|
bool |
True if this is a dummy transform |
__call__(*nargs, **kwargs)
¶
Execute the transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*nargs
|
Positional arguments for the transform |
()
|
|
**kwargs
|
Keyword arguments for the transform |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Transformed data |
Source code in graphcast/architecture/transform.py
__post_init__()
¶
Initialize the transform after dataclass initialization.
Sets up field specifications and validates transform configuration.
Raises:
Type | Description |
---|---|
ValueError
|
If transform configuration is invalid |
Source code in graphcast/architecture/transform.py
get_barebone(other)
¶
Get the barebone transform configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Optional[Transform]
|
Optional transform to use as base |
required |
Returns:
Type | Description |
---|---|
Optional[Transform]
|
tuple[Optional[Transform], Optional[Transform]]: Updated self transform |
Optional[Transform]
|
and transform to store in library |
Source code in graphcast/architecture/transform.py
update(t)
¶
Update this transform with another transform's configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
Transform
|
Transform to update from |
required |
Returns:
Name | Type | Description |
---|---|---|
Transform |
Updated transform |