History¶
tangram_history
¶
get_typer
¶
get_typer() -> Typer
Source code in packages/tangram_history/src/tangram_history/__init__.py
15 16 17 18 | |
run_history
async
¶
run_history(backend_state: BackendState) -> None
Source code in packages/tangram_history/src/tangram_history/__init__.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
cli
¶
A history management CLI that operates safely regardless of whether the
tangram serve backend is running. Operations repsect the single-writer
principle of Delta Lake when ingestion is active, or function when offline.
When online, the CLI acts as a remote control, sending serialised commands via Redis, with the service orchestrating locks (pausing ingestion/maintenance). When offline, the CLI assumes exclusive access and operates directly on the file system via PyO3 bindings.
PathTangramConfig
module-attribute
¶
PathTangramConfig: TypeAlias = Annotated[
Path,
Option(
help="Path to the tangram.toml config file.",
envvar="TANGRAM_CONFIG",
default_factory=default_config_file,
exists=True,
dir_okay=False,
),
]
ForceOffline
module-attribute
¶
ForceOffline: TypeAlias = Annotated[
bool,
Option(
"--force-offline",
help="Force offline operation, bypassing the tangram service even if online.",
),
]
HistoryStatus
¶
Bases: Enum
Source code in packages/tangram_history/src/tangram_history/cli.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
to_message
¶
to_message() -> str
Source code in packages/tangram_history/src/tangram_history/cli.py
88 89 90 91 92 93 94 95 | |
SupportsSerde
¶
Bases: Protocol
Source code in packages/tangram_history/src/tangram_history/cli.py
113 114 115 116 | |
from_json_bytes
staticmethod
¶
Source code in packages/tangram_history/src/tangram_history/cli.py
114 115 | |
print_error
¶
print_error(v: Any) -> None
Source code in packages/tangram_history/src/tangram_history/cli.py
50 51 | |
print_note
¶
print_note(v: Any) -> None
Source code in packages/tangram_history/src/tangram_history/cli.py
54 55 | |
print_warning
¶
print_warning(v: Any) -> None
Source code in packages/tangram_history/src/tangram_history/cli.py
58 59 | |
parse_config
¶
parse_config(config_path: Path) -> _CfgResult
Source code in packages/tangram_history/src/tangram_history/cli.py
68 69 70 71 72 73 74 75 76 77 78 79 80 | |
get_service_status
¶
get_service_status(
redis_url: str, control_channel: str
) -> HistoryStatus
Source code in packages/tangram_history/src/tangram_history/cli.py
98 99 100 101 102 103 104 105 106 107 108 109 110 | |
send_command
¶
send_command(
config_result: _CfgResult,
sender_id: str,
message_bytes: bytes,
response_type: type[T],
*,
timeout: int = 10,
) -> T | None
Source code in packages/tangram_history/src/tangram_history/cli.py
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 | |
format_schema
¶
Source code in packages/tangram_history/src/tangram_history/cli.py
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 | |
ls
¶
ls(
config: PathTangramConfig,
show_schema: bool = True,
force_offline: ForceOffline = False,
) -> None
List all history tables found in the configured storage directory.
Source code in packages/tangram_history/src/tangram_history/cli.py
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 | |
rm
¶
rm(table_name: Annotated[str, Argument(help='Name of the history table.')], predicate: Annotated[str, Argument(help=f'DataFusion SQL condition for rows to delete. "
Examples: "timestamp < '{yesterday}'", "df == 17", "altitude > 54000 OR altitude < 0".
See: <https://datafusion.apache.org/user-guide/sql/index.html>')], config: PathTangramConfig, dry_run: Annotated[bool, Option(--dry - run, help='Perform a dry run only (skip execution).')] = False, force_offline: ForceOffline = False) -> None
Delete rows from a history table based on a condition.
Queries the count and preview using datafusion SessionContext.
If the tangram service is online, the service acquires a write lock and
acquires semaphores for optimisation/vaccuming before execution.
Source code in packages/tangram_history/src/tangram_history/cli.py
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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
config
¶
HistoryConfig
dataclass
¶
Source code in packages/tangram_history/src/tangram_history/config.py
7 8 9 10 11 12 13 | |
base_path
class-attribute
instance-attribute
¶
tangram_history._history
¶
ControlMessage
¶
Ping
¶
Bases: ControlMessage
RegisterTable
¶
Bases: ControlMessage
ListTables
¶
Bases: ControlMessage
DeleteRows
¶
Bases: ControlMessage
Deletes rows in a table using with a specified predicate.
WARNING:
The current implementation uses raw string formatting to query row counts and previews, with the following SQL operations disallowed
It may be prone to SQL injection.
__match_args__
class-attribute
instance-attribute
¶
__match_args__ = (
"sender_id",
"table_name",
"predicate",
"dry_run",
)
predicate
property
¶
predicate: str
The predicate expression, which must have Boolean type
See: https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html
ControlResponse
¶
TableRegistered
¶
Bases: ControlResponse
__match_args__
class-attribute
instance-attribute
¶
__match_args__ = ('request_id', 'table_name', 'table_uri')
RegistrationFailed
¶
Bases: ControlResponse
Pong
¶
Bases: ControlResponse
TableList
¶
DeleteOutput
¶
Bases: ControlResponse
Successful delete response with affected row count and optional preview.
__match_args__
class-attribute
instance-attribute
¶
__match_args__ = (
"request_id",
"dry_run",
"affected_rows",
"preview",
)
__new__
¶
__new__(
request_id: str,
dry_run: bool,
affected_rows: int,
preview: Optional[str],
) -> DeleteOutput
CommandFailed
¶
HistoryConfig
¶
__new__
¶
__new__(
redis_url: str,
control_channel: str,
base_path: str,
redis_read_count: int,
redis_read_block_ms: int,
) -> HistoryConfig
RegisterTable
¶
TableInfo
¶
delete_rows_offline
¶
delete_rows_offline(
base_path: str,
table_name: str,
predicate: str,
dry_run: bool,
) -> ControlResponse
Delete rows from a history table stored on disk.
Returns:
| Type | Description |
|---|---|
ControlResponse
|
ControlResponse.DeleteOutput on success, ControlResponse.CommandFailed on failure. |
Raises:
| Type | Description |
|---|---|
OSError
|
if the table does not exist or filesystem access fails. |
list_tables_offline
¶
list_tables_offline(base_path: str) -> list[TableInfo]
List history tables by inspecting the on-disk Delta Lake directory.
Raises:
| Type | Description |
|---|---|
OSError
|
if the table does not exist or filesystem access fails. |
run_history
¶
run_history(config: HistoryConfig) -> Any
Start the history ingest service.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the service fails to start or crashes. |