Operations
dve.core_engine.backends.metadata.rules
¶
Metadata classes for rule steps.
Stage = Literal['Pre-sync', 'Sync', 'Post-sync']
module-attribute
¶
The stage that the rule falls under.
Step = Union[AbstractStep, Literal['sync']]
module-attribute
¶
A step within a rule. This is either a rule config or the literal string 'sync'.
AbstractConditionalJoin
¶
Bases: AbstractJoin
An abstract table join configuration with a join condition.
This joins target into entity.
Source code in src/dve/core_engine/backends/metadata/rules.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
AbstractJoin
¶
Bases: AbstractStep
An abstract table join configuration. This joins target into entity.
Source code in src/dve/core_engine/backends/metadata/rules.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
AbstractNewColumnConditionalJoin
¶
Bases: AbstractConditionalJoin
A join type which adds new columns to the finished entity.
Source code in src/dve/core_engine/backends/metadata/rules.py
325 326 327 328 329 330 331 332 333 334 335 336 | |
new_columns = Field(default_factory=dict)
class-attribute
instance-attribute
¶
A mapping of SQL expressions to the names of the new columns to be added
to entity.
Expressions can access columns from the source and the target, and columns will be namespaced within the source and target dataset names.
AbstractStep
¶
Bases: BaseModel
An abstract transformation step.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
UNTEMPLATED_KEYS = {'id', 'description', 'parent'}
class-attribute
¶
A set of aliases which are exempted from templating.
description = None
class-attribute
instance-attribute
¶
An optional description for the step.
id = None
class-attribute
instance-attribute
¶
An ID for the rule step. This will not be templated.
parent = None
class-attribute
instance-attribute
¶
Data about the parent rule and the step's place within it.
Config
¶
pydantic configuration options
Source code in src/dve/core_engine/backends/metadata/rules.py
101 102 103 104 105 | |
get_created_entities()
abstractmethod
¶
Get a set of the entity names created by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
116 117 118 119 | |
get_removed_entities()
¶
Get a set of the entity names removed by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
121 122 123 | |
get_required_entities()
abstractmethod
¶
Get a set of the required entity names for the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
111 112 113 114 | |
template(local_variables, *, global_variables=None)
¶
Template the rule, given the global and local variables.
Source code in src/dve/core_engine/backends/metadata/rules.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
with_parent(parent)
¶
Return a new step with different parent metadata.
Source code in src/dve/core_engine/backends/metadata/rules.py
125 126 127 | |
Aggregation
¶
Bases: BaseStep
A transformation which performs aggregation.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
agg_columns = None
class-attribute
instance-attribute
¶
Multiple aggregate expressions to take from the group by (for spark backend)
agg_function = None
class-attribute
instance-attribute
¶
The aggregate function to apply to the agg_columns (for duckdb backend)
group_by
instance-attribute
¶
Multiple expressions to group by.
pivot_column = None
class-attribute
instance-attribute
¶
An optional pivot column for the table.
pivot_values = None
class-attribute
instance-attribute
¶
A list of values to translate to columns when pivoting.
AntiJoin
¶
Bases: AbstractConditionalJoin
A table join configuration. This keeps the rows in entity where the join
condition with target is not true.
The table join will result in all of the columns from entity being retained.
No rows can be added from target.
Source code in src/dve/core_engine/backends/metadata/rules.py
502 503 504 505 506 507 508 509 | |
BaseStep
¶
Bases: AbstractStep
A base transformation step which performs a transformation on an entity and provides for a new entity being created instead of modification.
Source code in src/dve/core_engine/backends/metadata/rules.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
entity_name
instance-attribute
¶
The entity to apply the step to.
new_entity_name = None
class-attribute
instance-attribute
¶
Optionally, a new entity to create after the operation.
get_created_entities()
¶
Get a set of the entity names created by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
187 188 189 | |
get_required_entities()
¶
Get a set of the required entity names for the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
183 184 185 | |
ColumnAddition
¶
Bases: BaseStep
A transformation step which adds a new column based on an expression.
Source code in src/dve/core_engine/backends/metadata/rules.py
339 340 341 342 343 344 345 | |
ColumnRemoval
¶
Bases: BaseStep
A transformation step which removes a column by name.
Source code in src/dve/core_engine/backends/metadata/rules.py
348 349 350 351 352 | |
column_name
instance-attribute
¶
The name of the column to be dropped.
ConfirmJoinHasMatch
¶
Bases: AbstractConditionalJoin
Add a boolean column with name column_name to entity. The new column
will indicate whether the entity has a corresponding row in target.
Source code in src/dve/core_engine/backends/metadata/rules.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
column_name
instance-attribute
¶
The name of the new column to add to entity. This will indicate whether
there is a corresponding match for each row.
perform_integrity_check = True
class-attribute
instance-attribute
¶
Whether to perform the integrity check on the number of records. If this is
disabled, it is not guaranteed that rows in entity will not be duplicated.
CopyEntity
¶
Bases: AbstractStep
A transformation which copies an entity.
Source code in src/dve/core_engine/backends/metadata/rules.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
entity_name
instance-attribute
¶
The entity to copy.
new_entity_name
instance-attribute
¶
The new name for the copied entity.
get_created_entities()
¶
Get a set of the entity names created by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
436 437 438 | |
get_removed_entities()
¶
Gets the entity which has been removed
Source code in src/dve/core_engine/backends/metadata/rules.py
440 441 442 | |
get_required_entities()
¶
Get a set of the required entity names for the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
432 433 434 | |
DeferredFilter
¶
Bases: AbstractStep
A filter which should be applied in a synchronised step with other filters for the same entity, providing feedback to users.
Messages will be emitted for each record that fails a filter according to the configured reporting, and any record-level errors will be removed from source entities at the end of the stage. This enables multiple issues with the same record to be flagged to a data provider.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
entity_name
instance-attribute
¶
The entity to apply the step to.
expression
instance-attribute
¶
The expression for the filter. Records for which this expression is falsey will be removed from the source entity if the reporting level is a record-level error.
reporting
instance-attribute
¶
The reporting information for the filter.
get_created_entities()
¶
Get a set of the required entity names for the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
256 257 258 | |
get_required_entities()
¶
Get a set of the required entity names for the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
252 253 254 | |
template(local_variables, *, global_variables=None)
¶
Template the rule, given the global and local variables.
Source code in src/dve/core_engine/backends/metadata/rules.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
EntityRemoval
¶
Bases: AbstractStep
A transformation which drops entities.
Source code in src/dve/core_engine/backends/metadata/rules.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
entity_name
instance-attribute
¶
The entity to drop.
get_created_entities()
¶
Get a set of the entity names created by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
413 414 415 | |
get_removed_entities()
¶
Get a set of the entity names created by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
417 418 419 420 421 | |
get_required_entities()
¶
Get a set of the required entity names for the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
409 410 411 | |
HeaderJoin
¶
Bases: AbstractJoin
Add a 'header' entity (target) to each row in entity. The header entity
must contain only a single row.
Source code in src/dve/core_engine/backends/metadata/rules.py
532 533 534 535 536 537 538 539 | |
header_column_name = '_Header'
class-attribute
instance-attribute
¶
The name of the column to add to entity, which will contain the header.
ImmediateFilter
¶
Bases: BaseStep
A filter which removes records from an entity (or creates a new entity without those rows) according to a provided expression. Only records for which the provided expression is truthy will be retained.
Source code in src/dve/core_engine/backends/metadata/rules.py
192 193 194 195 196 197 198 199 200 201 202 203 204 | |
expression
instance-attribute
¶
The expression for the filter. Records for which this expression is falsey will be removed.
InnerJoin
¶
Bases: AbstractNewColumnConditionalJoin
A table join configuration. This joins target into entity, retaining only
rows which match in both tables.
The table join will result in all of the columns from entity being retained,
new columns can be added based on data from target by adding SQL expressions
in new_columns.
Source code in src/dve/core_engine/backends/metadata/rules.py
463 464 465 466 467 468 469 470 471 | |
LeftJoin
¶
Bases: AbstractNewColumnConditionalJoin
A table join configuration. This joins target into entity.
The table join will result in all of the columns from entity being retained,
new columns can be added based on data from target by adding SQL expressions
in new_columns.
Source code in src/dve/core_engine/backends/metadata/rules.py
453 454 455 456 457 458 459 460 | |
Notification
¶
Bases: AbstractStep
An implementation of a notification according to a particular reporting configuration. This will emit notifications for all records that meet the expression, and will not modify the source entity.
NOTE: This is not intended to be used directly, but is used in the implementation of the sync filter stage.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
entity_name
instance-attribute
¶
The entity to apply the step to.
excluded_columns = Field(default_factory=list)
class-attribute
instance-attribute
¶
Columns to be excluded from the record in the report.
expression
instance-attribute
¶
The expression for the notification. Records for which this expression is truthy will emit notifications according to the reporting config.
reporting
instance-attribute
¶
The reporting information for the filter.
OneToOneJoin
¶
Bases: LeftJoin
A table join configuration. This joins target into entity. This
will not alter the number of rows in target.
The table join will result in all of the columns from entity being retained,
new columns can be added based on data from target by adding SQL expressions
in new_columns.
Source code in src/dve/core_engine/backends/metadata/rules.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
perform_integrity_check = True
class-attribute
instance-attribute
¶
Whether to perform the integrity check on the number of records. If this is disabled, it is not guaranteed that joins will be one to one.
OrphanIdentification
¶
Bases: AbstractConditionalJoin
Identify records in entity which don't have at least one corresponding
match in target. A new boolean column will be added to entity ('IsOrphaned')
indicating whether the condition matched.
If there is already an 'IsOrphaned' column in the entity, this will be set to the logical OR of its current value and the value it would have been set to otherwise.
Source code in src/dve/core_engine/backends/metadata/rules.py
554 555 556 557 558 559 560 561 562 | |
ParentMetadata
¶
Bases: BaseModel
Data about the parent rule for a step.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
index
instance-attribute
¶
The index of the step within the parent rule.
rule
instance-attribute
¶
The rule the step belongs to, or a string representing the rule.
stage
instance-attribute
¶
The name of the stage in the rule the step belongs to.
Config
¶
pydantic configuration options
Source code in src/dve/core_engine/backends/metadata/rules.py
80 81 82 83 84 | |
RenameEntity
¶
Bases: CopyEntity
A transformation which renames an entity.
Source code in src/dve/core_engine/backends/metadata/rules.py
445 446 447 448 449 450 | |
get_removed_entities()
¶
Get a set of the entity names removed by the transformation.
Source code in src/dve/core_engine/backends/metadata/rules.py
448 449 450 | |
Rule
¶
Bases: BaseModel
A rule, made up of multiple steps.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
name
instance-attribute
¶
The name of the rule.
post_sync_steps
instance-attribute
¶
The post-sync steps in the rule.
pre_sync_steps
instance-attribute
¶
The pre-sync steps in the rule.
sync_filter_steps
instance-attribute
¶
The sync filter steps in the rule.
from_step_list(name, steps)
classmethod
¶
Load the rule from a single step list.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
template(local_variables, *, global_variables=None)
¶
Template the rule, returning the new templated rule. This is only really useful for 'upfront' templating, as all stages of the rule will be templated at once.
Source code in src/dve/core_engine/backends/metadata/rules.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
RuleMetadata
¶
Bases: BaseModel
Metadata about the rules.
Source code in src/dve/core_engine/backends/metadata/rules.py
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 | |
global_variables = Field(default_factory=dict)
class-attribute
instance-attribute
¶
An optional mapping of global template variables.
local_variables = None
class-attribute
instance-attribute
¶
An optional list of local, rule-level template variables.
If provided, this must be the same length as rules.
reference_data_config
instance-attribute
¶
Per-entity configuration options for the reference data.
Options are likely to vary by backend (e.g. some backends will have a database and table name, some might have a remote URI).
rules
instance-attribute
¶
A list of rules to be applied to to the entities.
templating_strategy = 'upfront'
class-attribute
instance-attribute
¶
The templating strategy for the rules.
If 'upfront', template all rules at the beginning of the rule stage execution.
If 'runtime', template rules immediately before evaluating them.
Runtime templating doesn't currently add any value, but will provide the ability to set variables from data items in the future. With runtime rules, it is not possible to check that all entities are present before performing work.
__iter__()
¶
Iterate over the rules and local variables.
Source code in src/dve/core_engine/backends/metadata/rules.py
729 730 731 732 733 734 | |
SelectColumns
¶
Bases: BaseStep
A transformation step which selects columns from an entity.
Source code in src/dve/core_engine/backends/metadata/rules.py
355 356 357 358 359 360 361 | |
SemiJoin
¶
Bases: AbstractConditionalJoin
A table join configuration. This keeps the rows in entity where the join
condition with target is true.
The table join will result in all of the columns from entity being retained.
No rows can be added from target.
Source code in src/dve/core_engine/backends/metadata/rules.py
492 493 494 495 496 497 498 499 | |
TableUnion
¶
Bases: AbstractJoin
Union two tables together, taking the columns from each by name.
Where columns have the same name, they must be the same type or coerceable.
Where column casing differs, the casing from the source entity will be kept.
Column order will be preserved, with columns from source taken first and extra
columns in target added in order afterwards.
Source code in src/dve/core_engine/backends/metadata/rules.py
542 543 544 545 546 547 548 549 550 551 | |