Patterns API¶
odibi.patterns.base
¶
odibi.patterns.scd2
¶
SCD2Pattern
¶
Bases: Pattern
SCD2 Pattern: Slowly Changing Dimension Type 2.
Tracks history by creating new rows for updates.
Configuration Options (via params dict): - keys (list): Business keys. - time_col (str): Timestamp column for versioning (default: current time). - valid_from_col (str): Name of start date column (default: valid_from). - valid_to_col (str): Name of end date column (default: valid_to). - is_current_col (str): Name of current flag column (default: is_current).
Source code in odibi/patterns/scd2.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 | |
execute(context)
¶
Execute the SCD2 pattern to track dimension history with versioning.
Implements Slowly Changing Dimension Type 2 logic by delegating to the scd2 transformer. The execution flow: 1. Load existing target dimension table 2. Compare source records with current dimension records using business keys 3. Expire changed records (set valid_to date, is_current=false) 4. Insert new versions for changed records (new valid_from, is_current=true) 5. Insert new records for keys not in target
The result includes version history with valid_from, valid_to, and is_current columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EngineContext
|
Engine context containing the source DataFrame and execution environment. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
DataFrame with SCD2 logic applied, including versioned records with valid_from, |
Any
|
valid_to, and is_current columns. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If SCD2 parameters are invalid or cannot be parsed. |
Exception
|
If target loading fails, change detection fails, or versioning fails. |
Source code in odibi/patterns/scd2.py
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 | |
validate()
¶
Validate SCD2 pattern configuration parameters.
Ensures that all required parameters are present for SCD Type 2 operations. Checks that: - keys are provided (business keys to track changes) - target is provided (existing dimension table for comparison)
Raises:
| Type | Description |
|---|---|
ValueError
|
If keys are missing or target is missing. |
Source code in odibi/patterns/scd2.py
odibi.patterns.merge
¶
MergePattern
¶
Bases: Pattern
Merge Pattern: Upsert/Merge logic.
Configuration Options (via params dict): - target (str): Target table/path. - keys (list): Join keys. - strategy (str): 'upsert', 'append_only', 'delete_match'.
Source code in odibi/patterns/merge.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 | |
execute(context)
¶
Execute the merge pattern to upsert data into the target table.
Performs a merge/upsert operation by delegating to the merge transformer. The merge strategy determines the behavior: - 'upsert': Insert new rows, update matching rows - 'append_only': Insert new rows only, never update - 'delete_match': Delete rows matching the keys
The merge transformer handles loading the target table, comparing keys, and applying the specified merge strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EngineContext
|
Engine context containing the source DataFrame and execution environment. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Source DataFrame (unchanged, as merge writes to target directly). |
Raises:
| Type | Description |
|---|---|
Exception
|
If merge operation fails, target loading fails, or parameters are invalid. |
Source code in odibi/patterns/merge.py
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 | |
validate()
¶
Validate merge pattern configuration parameters.
Ensures that all required parameters are present for merge operations. Checks that: - target (or path) is provided (destination table/path for merge) - keys are provided (columns to match source and target rows)
Raises:
| Type | Description |
|---|---|
ValueError
|
If target/path is missing or keys are missing. |
Source code in odibi/patterns/merge.py
odibi.patterns.dimension
¶
AuditConfig
¶
Bases: BaseModel
Configuration for audit columns.
Source code in odibi/patterns/dimension.py
DimensionPattern
¶
Bases: Pattern
Dimension Pattern: Builds complete dimension tables with surrogate keys and SCD support.
Features: - Auto-generate integer surrogate keys (MAX(existing) + ROW_NUMBER for new rows) - SCD Type 0 (static), 1 (overwrite), 2 (history tracking) - Optional unknown member row (SK=0) for orphan FK handling - Audit columns (load_timestamp, source_system)
Configuration Options (via params dict): - natural_key (str): Natural/business key column name - surrogate_key (str): Surrogate key column name to generate - scd_type (int): 0=static, 1=overwrite, 2=history tracking (default: 1) - track_cols (list): Columns to track for SCD1/2 changes - target (str): Target table path (required for SCD2 to read existing history) - unknown_member (bool): If true, insert a row with SK=0 for orphan FK handling - audit (dict): Audit configuration with load_timestamp and source_system
Supported target formats
Source code in odibi/patterns/dimension.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 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 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 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 | |
execute(context)
¶
Execute the dimension pattern to build a dimension table with surrogate keys.
Builds a complete dimension table with auto-generated surrogate keys and optional slowly changing dimension (SCD) support. The execution flow varies by SCD type: - SCD Type 0: Insert new records only, never update existing - SCD Type 1: Update existing records in-place, insert new records - SCD Type 2: Track full history with valid_from/valid_to dates and is_current flag
All modes generate surrogate keys starting from MAX(existing_sk) + 1 for new records. Optionally adds audit columns and ensures unknown member row (SK=0) exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EngineContext
|
Engine context containing the source DataFrame and execution environment. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
DataFrame with surrogate keys assigned and SCD logic applied as configured. |
Raises:
| Type | Description |
|---|---|
Exception
|
If target loading fails, SCD processing fails, or surrogate key generation encounters errors. |
Source code in odibi/patterns/dimension.py
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 | |
validate()
¶
Validate dimension pattern configuration parameters.
Ensures that all required parameters are present and valid. Checks that: - natural_key is provided (business key column(s)) - surrogate_key is provided (auto-generated primary key column name) - scd_type is valid (0, 1, or 2) - target is provided for SCD Type 2 (required for history comparison) - track_cols is provided for SCD Type 1 and 2 (columns to monitor for changes)
Raises:
| Type | Description |
|---|---|
ValueError
|
If natural_key or surrogate_key is missing, scd_type is invalid, target is missing for SCD2, or track_cols is missing for SCD1/2. |
Source code in odibi/patterns/dimension.py
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 | |
odibi.patterns.date_dimension
¶
DateDimensionPattern
¶
Bases: Pattern
Date Dimension Pattern: Generates a complete date dimension table.
Creates a date dimension with pre-calculated attributes useful for BI/reporting including day of week, quarter, fiscal year, etc.
Configuration Options (via params dict): - start_date (str): Start date in YYYY-MM-DD format - end_date (str): End date in YYYY-MM-DD format - date_key_format (str): Format for date_sk (default: "yyyyMMdd" -> 20240115) - fiscal_year_start_month (int): Month when fiscal year starts (1-12, default: 1) - include_time (bool): If true, generate time dimension (not implemented yet) - unknown_member (bool): If true, add unknown date row with date_sk=0
Generated Columns
- date_sk: Integer surrogate key (YYYYMMDD format)
- full_date: The actual date
- day_of_week: Day name (Monday, Tuesday, etc.)
- day_of_week_num: Day number (1=Monday, 7=Sunday)
- day_of_month: Day of month (1-31)
- day_of_year: Day of year (1-366)
- is_weekend: Boolean flag
- week_of_year: ISO week number (1-53)
- month: Month number (1-12)
- month_name: Month name (January, February, etc.)
- quarter: Calendar quarter (1-4)
- quarter_name: Q1, Q2, Q3, Q4
- year: Calendar year
- fiscal_year: Fiscal year
- fiscal_quarter: Fiscal quarter (1-4)
- is_month_start: First day of month
- is_month_end: Last day of month
- is_year_start: First day of year
- is_year_end: Last day of year
Source code in odibi/patterns/date_dimension.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 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 | |
execute(context)
¶
Execute the date dimension pattern to generate a date dimension table.
Generates a complete date dimension table with pre-calculated date attributes for the specified date range. The execution flow: 1. Parse start_date and end_date parameters 2. Generate one row per date in the range 3. Calculate all date attributes (day_of_week, quarter, fiscal_year, etc.) 4. Add unknown member row (date_sk=0) if configured
Generated columns include date_sk (surrogate key), full_date, day/week/month/quarter/year attributes, fiscal year/quarter, and boolean flags for period boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EngineContext
|
Engine context for DataFrame creation and execution environment. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
DataFrame containing one row per date with all calculated date attributes. |
Raises:
| Type | Description |
|---|---|
Exception
|
If date parsing fails or DataFrame generation encounters errors. |
Source code in odibi/patterns/date_dimension.py
validate()
¶
Validate date dimension pattern configuration parameters.
Ensures that all required parameters are present and valid. Checks that: - start_date is provided in YYYY-MM-DD format - end_date is provided in YYYY-MM-DD format - start_date is before or equal to end_date - fiscal_year_start_month is an integer between 1-12 if provided
Raises:
| Type | Description |
|---|---|
ValueError
|
If required dates are missing, dates are invalid/unparseable, start_date is after end_date, or fiscal_year_start_month is invalid. |
Source code in odibi/patterns/date_dimension.py
odibi.patterns.fact
¶
FactPattern
¶
Bases: Pattern
Enhanced Fact Pattern: Builds fact tables with automatic SK lookups.
Features: - Automatic surrogate key lookups from dimension tables - Orphan handling (unknown member, reject, or quarantine) - Grain validation (detect duplicates at PK level) - Audit columns (load_timestamp, source_system) - Deduplication support - Measure calculations and renaming
Basic Params (backward compatible): deduplicate (bool): If true, removes duplicates before insert. keys (list): Keys for deduplication.
Enhanced Params
grain (list): Columns that define uniqueness (validates no duplicates) dimensions (list): Dimension lookup configurations - source_column: Column in source data - dimension_table: Name of dimension in context - dimension_key: Natural key column in dimension - surrogate_key: Surrogate key to retrieve - scd2 (bool): If true, filter is_current=true orphan_handling (str): "unknown" | "reject" | "quarantine" quarantine (dict): Quarantine configuration (required if orphan_handling=quarantine) - connection: Connection name for quarantine writes - path: Path for quarantine data (or use 'table') - table: Table name for quarantine (or use 'path') - add_columns (dict): Metadata columns to add - _rejection_reason (bool): Add rejection reason column - _rejected_at (bool): Add rejection timestamp column - _source_dimension (bool): Add source dimension name column measures (list): Measure definitions (passthrough, rename, or calculated) audit (dict): Audit column configuration - load_timestamp (bool) - source_system (str)
Example Config
Example with Quarantine
Source code in odibi/patterns/fact.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 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 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 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 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
execute(context)
¶
Execute the fact pattern to build a fact table with surrogate key lookups.
Builds a fact table with automatic surrogate key lookups from dimension tables. The execution flow: 1. Deduplicate source data if configured 2. Perform dimension lookups to replace natural keys with surrogate keys 3. Handle orphan records (unknown SK=0, reject with error, or quarantine) 4. Apply measure calculations and transformations if configured 5. Validate grain (check for duplicates) if grain is specified 6. Add audit columns (load_timestamp, source_system) if configured
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EngineContext
|
Engine context containing the source DataFrame, dimension tables, and execution environment. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Fact DataFrame with surrogate keys from dimension lookups and all transformations applied. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If orphan records are found and orphan_handling='reject', if grain validation fails (duplicates found), or if dimension lookup fails. |
Exception
|
If quarantine write fails or measure calculations fail. |
Source code in odibi/patterns/fact.py
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 | |
validate()
¶
Validate fact pattern configuration parameters.
Ensures that all required parameters are present and valid. Checks that: - keys are provided when deduplicate is True - orphan_handling is valid ('unknown', 'reject', or 'quarantine') - quarantine config is complete when orphan_handling='quarantine' - all dimension lookups have required fields (source_column, dimension_table, etc.)
Raises:
| Type | Description |
|---|---|
ValueError
|
If keys are missing for deduplication, orphan_handling is invalid, quarantine config is incomplete, or dimension configs are missing required fields. |
Source code in odibi/patterns/fact.py
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 197 198 199 200 201 202 203 204 205 206 207 | |
odibi.patterns.aggregation
¶
AggregationPattern
¶
Bases: Pattern
Aggregation Pattern: Declarative aggregation with time-grain rollups.
Features: - Declare grain (GROUP BY columns) - Declare measures with aggregation functions - Incremental aggregation (merge new data with existing) - Time rollups (generate multiple grain levels) - Audit columns
Configuration Options (via params dict): - grain (list): Columns to GROUP BY (defines uniqueness) - measures (list): Measure definitions with name and aggregation expr - name: Output column name - expr: SQL aggregation expression (e.g., "SUM(amount)") - incremental (dict): Incremental merge configuration (optional) - timestamp_column: Column to identify new data - merge_strategy: "replace", "sum", "min", or "max" - having (str): Optional HAVING clause for filtering aggregates - audit (dict): Audit column configuration
Example Config
Source code in odibi/patterns/aggregation.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 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 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
execute(context)
¶
Execute the aggregation pattern on the input data.
Performs aggregation operations on the source DataFrame, optionally applying incremental merge with existing target data. The execution flow: 1. Aggregate source data by grain columns with specified measures 2. Apply HAVING clause filtering if configured 3. Merge with existing target data if incremental mode is enabled 4. Add audit columns (load_timestamp, source_system) if configured
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EngineContext
|
Engine context containing the source DataFrame and execution environment. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Aggregated DataFrame with measures computed at the specified grain level. |
Raises:
| Type | Description |
|---|---|
Exception
|
If aggregation fails, incremental merge fails, or target loading fails. |
Source code in odibi/patterns/aggregation.py
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 | |
validate()
¶
Validate aggregation pattern configuration parameters.
Ensures that all required parameters are present and valid. Checks that: - grain is specified (list of GROUP BY columns) - measures are provided with correct structure (list of dicts with 'name' and 'expr') - incremental config is valid if provided (requires 'timestamp_column' and valid merge_strategy)
Raises:
| Type | Description |
|---|---|
ValueError
|
If grain is missing, measures are missing/invalid, or incremental config is invalid. |
Source code in odibi/patterns/aggregation.py
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 | |