Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No source code #7

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [1.4.0] - 2024-05-23

### Changed

- Helper function that generates lineage files to omit empty properties

### Fixed

- Conversion tool for simple and advanced source code mappings

## [1.3.0] - 2024-01-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = custom-technical-lineage
version = 1.3.0
version = 1.4.0
author = Kristof Van Coillie
author_email = [email protected]
description = Helper scripts for custom technical lineage
Expand Down
2 changes: 1 addition & 1 deletion src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def generate_json_files(

# creating lineage.json
with open(custom_lineage_config.output_directory_path / "lineage.json", "w") as out_file:
json.dump(lineages, out_file, default=pydantic_encoder)
json.dump([lineage.model_dump(exclude_none=True) for lineage in lineages], out_file, default=pydantic_encoder)

# creating metadata.json
with open(custom_lineage_config.output_directory_path / "metadata.json", "w") as out_file:
Expand Down
25 changes: 22 additions & 3 deletions tests/test_data/conversion/lineage.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,27 @@
"column": "col2"
}
],
"mapping": "VIEW1 creation",
"source_code": "SELECT col1, col2 from T1;"
}]
"mapping_ref": {
"mapping": "VIEW1_creation",
"source_code": "transforms.sql",
"codebase_pos": [
{
"pos_start": 0,
"pos_len": 26
}
]
}
}
],
"codebase_files": {
"transforms.sql": {
"mapping_refs": {
"VIEW1_creation": {
"pos_start": 0,
"pos_len": 26
}
}
}
}
}

28 changes: 18 additions & 10 deletions tests/test_data/conversion/lineage_v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"leaf": {
"name": "col1",
"type": "Column"
},
"props": null
}
},
"trg": {
"nodes": [
Expand All @@ -47,10 +46,12 @@
"leaf": {
"name": "col1",
"type": "Column"
},
"props": null
}
},
"source_code": null
"source_code": {
"path": "source_codes/uuid.txt",
"transformation_display_name": "VIEW1 creation"
}
},
{
"src": {
Expand All @@ -75,8 +76,7 @@
"leaf": {
"name": "col2",
"type": "Column"
},
"props": null
}
},
"trg": {
"nodes": [
Expand All @@ -100,9 +100,17 @@
"leaf": {
"name": "col2",
"type": "Column"
},
"props": null
}
},
"source_code": null
"source_code": {
"path": "source_codes/uuid.txt",
"highlights": [
{
"start": 0,
"len": 26
}
],
"transformation_display_name": "VIEW1_creation"
}
}
]
102 changes: 102 additions & 0 deletions tests/test_data/conversion/lineage_v3_no_source_code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
{
"src": {
"nodes": [
{
"name": "snowflake",
"type": "System"
},
{
"name": "DB1",
"type": "Database"
},
{
"name": "PUBLIC",
"type": "Schema"
}
],
"parent": {
"name": "T1",
"type": "Table"
},
"leaf": {
"name": "col1",
"type": "Column"
}
},
"trg": {
"nodes": [
{
"name": "snowflake",
"type": "System"
},
{
"name": "DB1",
"type": "Database"
},
{
"name": "PUBLIC",
"type": "Schema"
}
],
"parent": {
"name": "VIEW1",
"type": "Table"
},
"leaf": {
"name": "col1",
"type": "Column"
}
}
},
{
"src": {
"nodes": [
{
"name": "snowflake",
"type": "System"
},
{
"name": "DB1",
"type": "Database"
},
{
"name": "PUBLIC",
"type": "Schema"
}
],
"parent": {
"name": "T1",
"type": "Table"
},
"leaf": {
"name": "col2",
"type": "Column"
}
},
"trg": {
"nodes": [
{
"name": "snowflake",
"type": "System"
},
{
"name": "DB1",
"type": "Database"
},
{
"name": "PUBLIC",
"type": "Schema"
}
],
"parent": {
"name": "VIEW1",
"type": "Table"
},
"leaf": {
"name": "col2",
"type": "Column"
}
}
}
]
1 change: 1 addition & 0 deletions tests/test_data/conversion/transforms.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT col1, col2 from T1;
15 changes: 5 additions & 10 deletions tests/test_data/csv/lineage_v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
"leaf": {
"name": "UI_2L",
"type": "Column"
},
"props": null
}
},
"source_code": {
"path": "source_codes/uuid.txt",
Expand Down Expand Up @@ -91,8 +90,7 @@
"leaf": {
"name": "USERID",
"type": "Column"
},
"props": null
}
},
"trg": {
"nodes": [
Expand All @@ -116,8 +114,7 @@
"leaf": {
"name": "UI_2L",
"type": "Column"
},
"props": null
}
},
"source_code": {
"path": "source_codes/uuid.txt",
Expand Down Expand Up @@ -181,9 +178,7 @@
"leaf": {
"name": "UI_2L",
"type": "Column"
},
"props": null
},
"source_code": null
}
}
}
]
33 changes: 32 additions & 1 deletion tests/test_translate_to_batch_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
from tools.translate_to_batch_format import convert


def test_translate_with_simple_and_advanced_source_code() -> None:
convert(
input_directory="./test_data/conversion",
output_directory="./test_data/conversion/v3",
migrate_source_code=True,
)

# compare converted with expected
with open("./test_data/conversion/metadata.json") as input_file:
expected_metadata = json.load(input_file)

with open("./test_data/conversion/v3/metadata.json") as input_file:
generated_metadata = json.load(input_file)

with open("./test_data/conversion/lineage_v3.json") as input_file:
expected_lineage = json.load(input_file)

with open("./test_data/conversion/v3/lineage.json") as input_file:
generated_lineage = json.load(input_file)

for lineage in generated_lineage:
if lineage.get("source_code"):
lineage["source_code"]["path"] = "source_codes/uuid.txt"

assert expected_metadata == generated_metadata
assert expected_lineage == generated_lineage

# cleanup
shutil.rmtree("./test_data/conversion/v3", ignore_errors=True)


def test_translat_without_source_code() -> None:
# convert input
convert(
Expand All @@ -19,7 +50,7 @@ def test_translat_without_source_code() -> None:
with open("./test_data/conversion/v3/metadata.json") as input_file:
generated_metadata = json.load(input_file)

with open("./test_data/conversion/lineage_v3.json") as input_file:
with open("./test_data/conversion/lineage_v3_no_source_code.json") as input_file:
expected_lineage = json.load(input_file)

with open("./test_data/conversion/v3/lineage.json") as input_file:
Expand Down
4 changes: 2 additions & 2 deletions tools/translate_to_batch_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _convert_lineage_source(
if "mapping_ref" in lineage_relationship_v1:
source_code_file_v1 = lineage_relationship_v1.get("mapping_ref", {}).get("source_code", "")
mapping_v1 = lineage_relationship_v1.get("mapping_ref", {}).get("mapping", "")
codebase_pos_v1 = lineage_relationship_v1.get("codebase_pos", [])
codebase_pos_v1 = lineage_relationship_v1.get("mapping_ref", {}).get("codebase_pos", [])
if not source_code_file_v1:
return None

Expand All @@ -88,7 +88,7 @@ def _convert_lineage_source(
custom_lineage_config=custom_lineage_config,
transformation_display_name=mapping_v1,
highlights=[
SourceCodeHighLight(start=highlight_v1["post_start"], len=highlight_v1["pos_len"])
SourceCodeHighLight(start=highlight_v1["pos_start"], len=highlight_v1["pos_len"])
for highlight_v1 in codebase_pos_v1
],
)
Expand Down
Loading