API Reference
This page provides auto-generated API documentation from docstrings.
Lake Managers
Core components for managing Delta Lake tables.
pdldb.lake_manager.LakeManager
Base class for managing a data lake with tables stored in Delta format.
This class provides the foundation for creating, reading, updating, and managing Delta tables in a data lake. It's designed to be extended by specific implementations like LocalLakeManager.
Source code in src/pdldb/lake_manager.py
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 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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
Functions
__init__(base_path, storage_options=None)
Initialize a new LakeManager.
PARAMETER | DESCRIPTION |
---|---|
base_path
|
The base path where the data lake will be stored
TYPE:
|
storage_options
|
Optional cloud storage-specific parameters
TYPE:
|
Source code in src/pdldb/lake_manager.py
append_table(table_name, df, delta_write_options=None)
Append data to an existing table.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to append to
TYPE:
|
df
|
DataFrame containing the data to append
TYPE:
|
delta_write_options
|
Optional configuration for the delta write operation
TYPE:
|
Notes
- The schema of the DataFrame must match the schema of the table
- Appending data to a table has been intialized but contains no data will create the table on your storage backend.
Source code in src/pdldb/lake_manager.py
create_table(table_name, table_schema, primary_keys)
Create a new table in the data lake.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to create
TYPE:
|
table_schema
|
Schema definition for the new table
TYPE:
|
primary_keys
|
Primary key column(s) for the table
TYPE:
|
Notes
- The schema is enforced for write operations.
- The primary keys are used to identify unique records for merge operations.
- The primary key can be a single column or a composite key (multiple columns).
- Primary keys can be specified as a string or a list of strings.
Single primary key
from pdldb import LocalLakeManager
import polars as pl
lake_manager = LocalLakeManager("data")
schema = {
"sequence": pl.Int32,
"value_1": pl.Float64,
"value_2": pl.Utf8,
"value_3": pl.Float64,
"value_4": pl.Float64,
"value_5": pl.Datetime("ns"),
}
primary_keys = "sequence"
lake_manager.create_table("my_table", schema, primary_keys)
Composite primary key
Source code in src/pdldb/lake_manager.py
delete_table(table_name)
Delete a table from the data lake. Deleted data files are not recoverable, so use with caution.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to delete
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the table was successfully deleted |
Notes
- This operation is irreversible, and deleted tables cannot be recovered.
- Use caution when deleting tables, especially in production environments.
- Ensure that you have backups or copies of important data before deletion.
- Deleting a table will remove all associated data files and metadata.
Source code in src/pdldb/lake_manager.py
get_data_frame(table_name)
Get an eager DataFrame from a table.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to read
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
A Polars DataFrame containing the table data |
Notes
- All table data is loaded into a Polars DataFrame in memory.
- This is suitable for small to medium-sized tables.
Source code in src/pdldb/lake_manager.py
get_lazy_frame(table_name)
Get a lazy DataFrame from a table for deferred execution.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to read
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LazyFrame
|
A Polars LazyFrame referencing the table data |
Notes
- LazyFrames allow for deferred execution and optimization of query plans.
- Table data is not loaded into memory until an action (like collect) is called.
- This is suitable for large tables or complex queries.
Example
Source code in src/pdldb/lake_manager.py
get_table_info(table_name)
Get detailed information about a specific table.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to get information for
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
A dictionary containing detailed table information |
Source code in src/pdldb/lake_manager.py
get_table_schema(table_name)
Get the schema definition for a specific table.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to get the schema for
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
A dictionary representing the table schema |
Source code in src/pdldb/lake_manager.py
list_tables()
List all tables in the data lake.
RETURNS | DESCRIPTION |
---|---|
Dict[str, Dict[str, Any]]
|
A dictionary mapping table names to their metadata |
Source code in src/pdldb/lake_manager.py
merge_table(table_name, df, merge_condition='insert', delta_write_options=None)
Merge data into an existing table based on the specified merge condition.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to merge data into
TYPE:
|
df
|
DataFrame containing the data to merge
TYPE:
|
merge_condition
|
Type of merge operation to perform (update, insert, delete, upsert, upsert_delete)
TYPE:
|
delta_write_options
|
Optional configuration for the delta write operation
TYPE:
|
merge_condition
- update: Update existing rows only from the new data
- insert: Insert new rows only from the new data
- delete: Delete existing rows that exist in the new data
- upsert: Update existing rows and insert new rows from the new data
- upsert_delete: Update existing rows, insert new rows, and delete rows that don't exist in the new data
Notes
- If the table has been intialized but contains no data, merge operations requiring existing data ('update', 'delete', 'upsert_delete') will fail with an error message.
- The 'insert' and upsert' operations will create the table on your storage backend if the table has been intialized but contains no data.
- Primary keys defined for the table are used to determine matching records.
Source code in src/pdldb/lake_manager.py
optimize_table(table_name, target_size=512 * 1024 * 1024, max_concurrent_tasks=None, writer_properties=None)
Optimize a table by compacting small files in to files of the target size. Optimizing a table can improve query performance and cloud costs.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to optimize
TYPE:
|
target_size
|
Target file size in bytes for optimization
TYPE:
|
max_concurrent_tasks
|
Maximum number of concurrent tasks for optimization
TYPE:
|
writer_properties
|
Optional writer properties for optimization
TYPE:
|
Notes
- The target size is the desired size of the output files after optimization.
- The default target size is 512 MB (512 * 1024 * 1024 bytes).
- The optimization process may take some time depending on the size of the table and the number of files.
Source code in src/pdldb/lake_manager.py
overwrite_table(table_name, df, delta_write_options=None)
Overwrite an existing table with new data.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to overwrite
TYPE:
|
df
|
DataFrame containing the new data
TYPE:
|
delta_write_options
|
Optional configuration for the delta write operation
TYPE:
|
Notes
- The schema of the DataFrame must match the schema of the table
- Overwriting a table that has been intialized but contains no data will create the table on your storage backend.
- Overwriting a table with existing data will replace the entire table.
Source code in src/pdldb/lake_manager.py
vacuum_table(table_name, retention_hours=168, enforce_retention_duration=False)
Clean up old data files from a table based on the retention period. Old data files are those that are no longer referenced by the table.
PARAMETER | DESCRIPTION |
---|---|
table_name
|
Name of the table to vacuum
TYPE:
|
retention_hours
|
Retention period in hours (0 means delete all unreferenced files)
TYPE:
|
enforce_retention_duration
|
Whether to enforce the retention period
TYPE:
|
Notes
- The retention period is the time duration for which files are retained.
- Files older than the retention period will be deleted.
- Setting retention_hours to 0 will delete all unreferenced files, regardless of age.
- The enforce_retention_duration flag ensures that the retention period is strictly enforced.
- Use caution when setting retention_hours to 0, as this will delete all unreferenced files.
- This operation is irreversible, deleted files cannot be recovered.
- The vacuum operation may take some time depending on the size of the table and the number of files.
Source code in src/pdldb/lake_manager.py
pdldb.lake_manager.LocalLakeManager
Bases: LakeManager
Implementation of LakeManager for local filesystem storage.
This class extends the base LakeManager to provide specific functionality for managing Delta tables in a local filesystem.
Source code in src/pdldb/lake_manager.py
Functions
__init__(base_path)
Initialize a new LocalLakeManager.
PARAMETER | DESCRIPTION |
---|---|
base_path
|
The local filesystem path where the data lake will be stored
TYPE:
|
Source code in src/pdldb/lake_manager.py
pdldb.lake_manager.S3LakeManager
Bases: LakeManager
Implementation of LakeManager for Amazon S3 storage.
This class extends the base LakeManager to provide specific functionality for managing Delta tables in Amazon S3.
Notes
Delta Lake normally guarantees ACID transactions when writing data; this is done by default when writing to all supported object stores except AWS S3.
When writing to S3, there are two approaches:
-
Using a DynamoDB locking provider (recommended for production): This ensures safe concurrent writes (ACID) by using a DynamoDB table to manage locks.
-
Allowing unsafe renames: This approach doesn't guarantee data consistency with concurrent writes.
Source code in src/pdldb/lake_manager.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
|
Functions
__init__(base_path, aws_region, aws_access_key, aws_secret_key, dynamodb_locking_table=None)
Initialize a new S3LakeManager.
PARAMETER | DESCRIPTION |
---|---|
base_path
|
The S3 bucket path where the data lake will be stored (e.g., "s3://bucket/prefix/")
TYPE:
|
aws_region
|
AWS region name (e.g., "us-east-1")
TYPE:
|
aws_access_key
|
AWS access key ID
TYPE:
|
aws_secret_key
|
AWS secret access key
TYPE:
|
dynamodb_locking_table
|
Optional name of DynamoDB table to use as locking provider. If not provided, unsafe renames will be enabled.
TYPE:
|
Notes
- For production use with concurrent writes, it's strongly recommended to provide a DynamoDB table for locking to ensure ACID guarantees.
- The DynamoDB table must have the following schema:
- Partition key: 'tablePath' (String)
- Sort key: 'fileName' (String)
- If no dynamodb_locking_table is provided, the S3LakeManager will use unsafe renames which doesn't guarantee data consistency with concurrent writes.
- You can create the required DynamoDB table with:
aws dynamodb create-table --table-name delta_log --attribute-definitions AttributeName=tablePath,AttributeType=S AttributeName=fileName,AttributeType=S --key-schema AttributeName=tablePath,KeyType=HASH AttributeName=fileName,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
- Consider setting a TTL on the DynamoDB table to avoid it growing indefinitely.
Example
from pdldb import S3LakeManager
# Using unsafe renames (not safe for concurrent writes)
lake_manager = S3LakeManager(
"s3://mybucket/mydatalake/",
aws_region="us-east-1",
aws_access_key="YOUR_ACCESS_KEY",
aws_secret_key="YOUR_SECRET_KEY"
)
# Using DynamoDB locking provider (safe for concurrent writes)
lake_manager = S3LakeManager(
"s3://mybucket/mydatalake/",
aws_region="us-east-1",
aws_access_key="YOUR_ACCESS_KEY",
aws_secret_key="YOUR_SECRET_KEY",
dynamodb_locking_table="delta_log"
)
Source code in src/pdldb/lake_manager.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
|