Skip to content

Commit 1855328

Browse files
authored
fix: mermaid complex types (#119)
* fix: match outermost parent type with deeper nested types Simplifying the regex expression. Previously from `a<b<c d, e f>>` it would ignore `a` and capture `b`, `c d` and `, e f`. Now it captures `a` and `b<c d, e f>`, which is disregarded as far as I can see. * feat: add test_mermaid_column_types * Revert "fix: match outermost parent type with deeper nested types" This reverts commit 3b9d1ee. * Revert "Revert "fix: match outermost parent type with deeper nested types"" This reverts commit 78d2891. * chore: formatting
1 parent eae4f9b commit 1855328

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

dbterd/adapters/targets/mermaid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def match_complex_column_type(column_type: str) -> Optional[str]:
4242
Returns:
4343
Optional[str]: Returns root type if input type is nested complex type, otherwise returns `None` for primitive types
4444
"""
45-
pattern = r"(\w+)<(\w+\s+\w+(\s*,\s*\w+\s+\w+)*)>"
45+
pattern = r"(\w+)<.*>"
4646
match = re.match(pattern, column_type)
4747
if match:
4848
return match.group(1)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
3+
from dbterd.adapters.targets import mermaid
4+
5+
complex_column_types = [
6+
("string", None),
7+
("struct<string a, string b>", "struct"),
8+
("array<struct<string a, string b>>", "array"),
9+
("array<struct<string a_id, string b_id>>", "array"),
10+
]
11+
column_types = [
12+
("string", "string"),
13+
("struct<string a, string b>", "struct[OMITTED]"),
14+
("array<struct<string a, string b>>", "array[OMITTED]"),
15+
("array<struct<string a_id, string b_id>>", "array[OMITTED]"),
16+
]
17+
18+
19+
@pytest.mark.parametrize("input,expected", complex_column_types)
20+
def test_match_complex_column_type(input, expected):
21+
assert mermaid.match_complex_column_type(input) == expected
22+
23+
24+
@pytest.mark.parametrize("input,expected", column_types)
25+
def test_replace_column_type(input, expected):
26+
assert mermaid.replace_column_type(input) == expected

0 commit comments

Comments
 (0)