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

fix: mermaid complex types #119

Merged
merged 5 commits into from
Jul 17, 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
2 changes: 1 addition & 1 deletion dbterd/adapters/targets/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def match_complex_column_type(column_type: str) -> Optional[str]:
Returns:
Optional[str]: Returns root type if input type is nested complex type, otherwise returns `None` for primitive types
"""
pattern = r"(\w+)<(\w+\s+\w+(\s*,\s*\w+\s+\w+)*)>"
pattern = r"(\w+)<.*>"
match = re.match(pattern, column_type)
if match:
return match.group(1)
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/adapters/targets/mermaid/test_mermaid_column_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from dbterd.adapters.targets import mermaid

complex_column_types = [
("string", None),
("struct<string a, string b>", "struct"),
("array<struct<string a, string b>>", "array"),
("array<struct<string a_id, string b_id>>", "array"),
]
column_types = [
("string", "string"),
("struct<string a, string b>", "struct[OMITTED]"),
("array<struct<string a, string b>>", "array[OMITTED]"),
("array<struct<string a_id, string b_id>>", "array[OMITTED]"),
]


@pytest.mark.parametrize("input,expected", complex_column_types)
def test_match_complex_column_type(input, expected):
assert mermaid.match_complex_column_type(input) == expected


@pytest.mark.parametrize("input,expected", column_types)
def test_replace_column_type(input, expected):
assert mermaid.replace_column_type(input) == expected
Loading