Layer 2: Storage
Single-purpose storage interfaces. Each store does one thing.
JournalStore
SQL statement buffer for write-ahead logging.
ftm_lakehouse.storage.JournalStore = SqlJournalStore
module-attribute
ParquetStore
Delta Lake parquet storage for statements. Uses a translog metadata table for tracking timestamps and soft deletes.
ftm_lakehouse.storage.ParquetStore
Bases: LakehouseApiMixin
Delta Lake parquet storage for entity statements.
Wraps ftmq's LakeStore to provide statement storage with: - Partitioned parquet files (by bucket, origin) - Delta Lake transaction log for versioning - Translog metadata table for timestamps and soft deletes - Change data capture (CDC) support - Efficient querying via DuckDB
Layout: statements/bucket={bucket}/origin={origin}/{auto-identifier}.parquet
Source code in ftm_lakehouse/storage/parquet.py
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 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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
exists
property
Check existence of deltatable
translog_version
property
Current version of the translog Delta table.
version
property
Current version of the main Delta table.
compact()
Apply translog to main table: remove deleted rows, update timestamps.
After compact the main table is self-contained (accurate first_seen/ last_seen, no deleted rows) and the translog only contains live entries. Caller should call optimize() afterwards for file compaction.
Source code in ftm_lakehouse/storage/parquet.py
destroy()
Destroy the deltalake by removing the transaction log in "_delta_log" directory. This is soft deleting, as the parquet files remain (but will be cleaned up on optimize --vacuum)
Source code in ftm_lakehouse/storage/parquet.py
export_csv(output_uri)
Export statements to a sorted, de-duplicated CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_uri
|
str
|
Destination URI for the CSV file |
required |
Source code in ftm_lakehouse/storage/parquet.py
get_changes(start_version=None, end_version=None)
Get statement changes for a version range using change data capture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_version
|
int | None
|
Starting version number (default: 0) |
None
|
end_version
|
int | None
|
Ending version number (default: latest) |
None
|
Yields:
| Type | Description |
|---|---|
tuple[datetime, str, dict]
|
Tuples of (commit_timestamp, change_type, row_dict) |
Source code in ftm_lakehouse/storage/parquet.py
get_deleted_entity_ids()
Get entity IDs that have been soft-deleted via translog.
Source code in ftm_lakehouse/storage/parquet.py
optimize(vacuum=False, vacuum_keep_hours=0, bucket=None, origin=None)
Optimize the store by compacting small files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vacuum
|
bool
|
Also delete old file versions |
False
|
vacuum_keep_hours
|
int
|
Hours of history to retain when vacuuming |
0
|
bucket
|
str | None
|
Filter optimization to specific bucket partition |
None
|
origin
|
str | None
|
Filter optimization to specific origin partition |
None
|
Source code in ftm_lakehouse/storage/parquet.py
query(q=None)
Query Entities from the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Query | None
|
Optional Query object with filters |
None
|
Yields:
| Type | Description |
|---|---|
StatementEntities
|
StatementEntity objects matching the query |
Source code in ftm_lakehouse/storage/parquet.py
query_raw(q=None)
Query entity dicts via aggregate_unsafe(), bypassing FtM object construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Select | None
|
Optional SQLAlchemy select (default: Query().sql.statements) |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, Any]
|
Entity dicts (id, schema, properties, caption, ...) |
Source code in ftm_lakehouse/storage/parquet.py
query_statements(q=None)
Query ordered Statements from the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Select | None
|
Optional SQLAlchemy query (default: Query().sql.statements) |
None
|
Yields:
| Type | Description |
|---|---|
Statements
|
Statement objects matching the query |
Source code in ftm_lakehouse/storage/parquet.py
stats()
view()
TranslogStore
Lightweight Delta table for per-statement metadata (first_seen, last_seen, deleted_at). Used internally by ParquetStore.
ftm_lakehouse.storage.parquet.TranslogStore
Bases: LakehouseApiMixin
Manages a lightweight translog Delta table for per-statement metadata.
Tracks first_seen, last_seen, and deleted_at per statement ID. The main parquet table stores immutable FtM statements; the translog provides mutable metadata via Delta Lake MERGE operations.
Source code in ftm_lakehouse/storage/parquet.py
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 | |
compact()
Remove deleted entries from translog.
Source code in ftm_lakehouse/storage/parquet.py
mark_deleted(table)
Set deleted_at on existing translog rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
PyArrow table with columns (id, deleted_at) |
required |
Source code in ftm_lakehouse/storage/parquet.py
upsert(table)
Insert or update translog rows. Updates last_seen on conflict.
Source code in ftm_lakehouse/storage/parquet.py
TagStore
Key-value freshness tracking.
ftm_lakehouse.storage.TagStore
Bases: Tags
Key-value store for freshness tracking.
Tags are timestamps stored as key-value pairs, used to track when resources were last updated and determine if processing is needed.
Layout: tags/{tenant}/{key}
This store has the "tags/{tenant}" key prefix set, so clients must use relative paths from there.
Source code in ftm_lakehouse/storage/tags.py
is_latest(key, dependencies)
Check if the tag is more recent than all dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Tag key to check |
required |
dependencies
|
Iterable[str]
|
Tag keys that this key depends on |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if key is newer than all dependencies, False otherwise |
Source code in ftm_lakehouse/storage/tags.py
set(key, timestamp=None)
Set a tag to the given timestamp (or now if not provided).
QueueStore
CRUD action queue for async processing.
ftm_lakehouse.storage.QueueStore
Bases: Queue
CRUD action queue for ordered mutation log.
All mutations (entity upsert/delete, file archive, mapping updates) go through this queue, ordered by UUID7 timestamp.
Layout: queue/{tenant}/{uuid7}.json
This store has the "queue/{tenant}" key prefix set, so clients must use relative paths from there.