-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): add stateful ingestion support for file source (#11804)
- Loading branch information
1 parent
8ca8fd9
commit 84c6776
Showing
6 changed files
with
186 additions
and
12 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
78 changes: 78 additions & 0 deletions
78
metadata-ingestion/tests/integration/file/metadata_file.json
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,78 @@ | ||
[ | ||
{ | ||
"entityType": "dataset", | ||
"entityUrn": "urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_1,PROD)", | ||
"changeType": "UPSERT", | ||
"aspectName": "datasetProperties", | ||
"aspect": { | ||
"json": { | ||
"name": "TABLE_1", | ||
"qualifiedName": "TEST_DB.TEST_SCHEMA.TABLE_1", | ||
"description": "Comment for Table", | ||
"tags": [] | ||
} | ||
}, | ||
"systemMetadata": { | ||
"lastObserved": 1615443388097, | ||
"runId": "snowflake-2023_12_18-10_16_09", | ||
"lastRunId": "no-run-id-provided" | ||
} | ||
}, | ||
{ | ||
"entityType": "dataset", | ||
"entityUrn": "urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_2,PROD)", | ||
"changeType": "UPSERT", | ||
"aspectName": "datasetProperties", | ||
"aspect": { | ||
"json": { | ||
"name": "TABLE_2", | ||
"qualifiedName": "TEST_DB.TEST_SCHEMA.TABLE_2", | ||
"description": "Comment for Table", | ||
"tags": [] | ||
} | ||
}, | ||
"systemMetadata": { | ||
"lastObserved": 1615443388097, | ||
"runId": "snowflake-2023_12_18-10_16_09", | ||
"lastRunId": "no-run-id-provided" | ||
} | ||
}, | ||
{ | ||
"entityType": "dataset", | ||
"entityUrn": "urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_3,PROD)", | ||
"changeType": "UPSERT", | ||
"aspectName": "datasetProperties", | ||
"aspect": { | ||
"json": { | ||
"name": "TABLE_3", | ||
"qualifiedName": "TEST_DB.TEST_SCHEMA.TABLE_3", | ||
"description": "Comment for Table", | ||
"tags": [] | ||
} | ||
}, | ||
"systemMetadata": { | ||
"lastObserved": 1615443388097, | ||
"runId": "snowflake-2023_12_18-10_16_09", | ||
"lastRunId": "no-run-id-provided" | ||
} | ||
}, | ||
{ | ||
"entityType": "dataset", | ||
"entityUrn": "urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_4,PROD)", | ||
"changeType": "UPSERT", | ||
"aspectName": "datasetProperties", | ||
"aspect": { | ||
"json": { | ||
"name": "TABLE_4", | ||
"qualifiedName": "TEST_DB.TEST_SCHEMA.TABLE_4", | ||
"description": "Comment for Table", | ||
"tags": [] | ||
} | ||
}, | ||
"systemMetadata": { | ||
"lastObserved": 1615443388097, | ||
"runId": "snowflake-2023_12_18-10_16_09", | ||
"lastRunId": "no-run-id-provided" | ||
} | ||
} | ||
] |
26 changes: 26 additions & 0 deletions
26
metadata-ingestion/tests/integration/file/state_golden.json
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,26 @@ | ||
[ | ||
{ | ||
"entityType": "dataJob", | ||
"entityUrn": "urn:li:dataJob:(urn:li:dataFlow:(file,dummy_stateful,prod),default_stale_entity_removal)", | ||
"changeType": "UPSERT", | ||
"aspectName": "datahubIngestionCheckpoint", | ||
"aspect": { | ||
"json": { | ||
"timestampMillis": 1730898142020, | ||
"partitionSpec": { | ||
"partition": "FULL_TABLE_SNAPSHOT", | ||
"type": "FULL_TABLE" | ||
}, | ||
"pipelineName": "dummy_stateful", | ||
"platformInstanceId": "", | ||
"config": "", | ||
"state": { | ||
"formatVersion": "1.0", | ||
"serde": "utf-8", | ||
"payload": "{\"urns\": [\"urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_1,PROD)\", \"urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_2,PROD)\", \"urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_3,PROD)\", \"urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.table_4,PROD)\"]}" | ||
}, | ||
"runId": "test-run" | ||
} | ||
} | ||
} | ||
] |
49 changes: 49 additions & 0 deletions
49
metadata-ingestion/tests/integration/file/test_file_source.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,49 @@ | ||
import pathlib | ||
from unittest import mock | ||
|
||
from datahub.ingestion.run.pipeline import Pipeline | ||
from datahub.ingestion.source.state.entity_removal_state import GenericCheckpointState | ||
from tests.test_helpers import mce_helpers | ||
|
||
|
||
def test_stateful_ingestion(tmp_path, pytestconfig): | ||
state_file_name = "state.json" | ||
golden_state_file_name = "state_golden.json" | ||
|
||
test_resources_dir: pathlib.Path = pytestconfig.rootpath / "tests/integration/file" | ||
pipeline_config = { | ||
"run_id": "test-run", | ||
"pipeline_name": "dummy_stateful", | ||
"source": { | ||
"type": "file", | ||
"config": { | ||
"filename": str(test_resources_dir / "metadata_file.json"), | ||
"stateful_ingestion": { | ||
"enabled": True, | ||
"remove_stale_metadata": True, | ||
"state_provider": { | ||
"type": "file", | ||
"config": { | ||
"filename": f"{tmp_path}/{state_file_name}", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"sink": { | ||
"type": "blackhole", | ||
"config": {}, | ||
}, | ||
} | ||
with mock.patch( | ||
"datahub.ingestion.source.state.stale_entity_removal_handler.StaleEntityRemovalHandler._get_state_obj" | ||
) as mock_state: | ||
mock_state.return_value = GenericCheckpointState(serde="utf-8") | ||
pipeline = Pipeline.create(pipeline_config) | ||
pipeline.run() | ||
|
||
mce_helpers.check_golden_file( | ||
pytestconfig, | ||
output_path=tmp_path / state_file_name, | ||
golden_path=f"{test_resources_dir}/{golden_state_file_name}", | ||
) |
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