-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into cus3116-failing-cli-0.14.1
- Loading branch information
Showing
23 changed files
with
1,155 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
metadata-ingestion/src/datahub/ingestion/api/incremental_properties_helper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import logging | ||
from typing import Iterable, Optional | ||
|
||
from pydantic.fields import Field | ||
|
||
from datahub.configuration.common import ConfigModel | ||
from datahub.emitter.mce_builder import set_aspect | ||
from datahub.emitter.mcp import MetadataChangeProposalWrapper | ||
from datahub.ingestion.api.source_helpers import create_dataset_props_patch_builder | ||
from datahub.ingestion.api.workunit import MetadataWorkUnit | ||
from datahub.metadata.schema_classes import ( | ||
DatasetPropertiesClass, | ||
MetadataChangeEventClass, | ||
SystemMetadataClass, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def convert_dataset_properties_to_patch( | ||
urn: str, | ||
aspect: DatasetPropertiesClass, | ||
system_metadata: Optional[SystemMetadataClass], | ||
) -> MetadataWorkUnit: | ||
patch_builder = create_dataset_props_patch_builder(urn, aspect, system_metadata) | ||
mcp = next(iter(patch_builder.build())) | ||
return MetadataWorkUnit(id=MetadataWorkUnit.generate_workunit_id(mcp), mcp_raw=mcp) | ||
|
||
|
||
def auto_incremental_properties( | ||
incremental_properties: bool, | ||
stream: Iterable[MetadataWorkUnit], | ||
) -> Iterable[MetadataWorkUnit]: | ||
if not incremental_properties: | ||
yield from stream | ||
return # early exit | ||
|
||
for wu in stream: | ||
urn = wu.get_urn() | ||
|
||
if isinstance(wu.metadata, MetadataChangeEventClass): | ||
properties_aspect = wu.get_aspect_of_type(DatasetPropertiesClass) | ||
set_aspect(wu.metadata, None, DatasetPropertiesClass) | ||
if len(wu.metadata.proposedSnapshot.aspects) > 0: | ||
yield wu | ||
|
||
if properties_aspect: | ||
yield convert_dataset_properties_to_patch( | ||
urn, properties_aspect, wu.metadata.systemMetadata | ||
) | ||
elif isinstance(wu.metadata, MetadataChangeProposalWrapper) and isinstance( | ||
wu.metadata.aspect, DatasetPropertiesClass | ||
): | ||
properties_aspect = wu.metadata.aspect | ||
if properties_aspect: | ||
yield convert_dataset_properties_to_patch( | ||
urn, properties_aspect, wu.metadata.systemMetadata | ||
) | ||
else: | ||
yield wu | ||
|
||
|
||
# TODO: Use this in SQLCommonConfig. Currently only used in snowflake | ||
class IncrementalPropertiesConfigMixin(ConfigModel): | ||
incremental_properties: bool = Field( | ||
default=False, | ||
description="When enabled, emits dataset properties as incremental to existing dataset properties " | ||
"in DataHub. When disabled, re-states dataset properties on each run.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.