Skip to content

Commit 6a8301b

Browse files
committed
Move parse_full_table_name to utils with fixed regex
- Fix regex to use [^`]+ instead of \w+ to handle special prefixes (~, #) - Move function to datajoint.utils for reusability - Also fix same regex issue in get_master()
1 parent 70dcc31 commit 6a8301b

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

datajoint/lineage.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
"""
99

1010
import logging
11-
import re
1211

13-
from .errors import DataJointError
1412
from .heading import Heading
1513
from .table import Table
14+
from .utils import parse_full_table_name
1615

1716
logger = logging.getLogger(__name__.split(".")[0])
1817

@@ -116,19 +115,6 @@ def delete_table_lineage(self, table_name):
116115
(self & dict(table_name=table_name)).delete_quick()
117116

118117

119-
def parse_full_table_name(full_name):
120-
"""
121-
Parse a full table name like `schema`.`table` into (schema, table).
122-
123-
:param full_name: full table name in format `schema`.`table`
124-
:return: tuple (schema, table)
125-
"""
126-
match = re.match(r"`(\w+)`\.`(\w+)`", full_name)
127-
if not match:
128-
raise DataJointError(f"Invalid table name format: {full_name}")
129-
return match.group(1), match.group(2)
130-
131-
132118
def compute_lineage_from_dependencies(connection, schema, table_name, attribute_name):
133119
"""
134120
Compute lineage by traversing the FK graph.

datajoint/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_master(full_table_name: str) -> str:
5050
:return: Supposed master full table name or empty string if not a part table name.
5151
:rtype: str
5252
"""
53-
match = re.match(r"(?P<master>`\w+`.`\w+)__(?P<part>\w+)`", full_table_name)
53+
match = re.match(r"(?P<master>`[^`]+`.`[^`]+)__(?P<part>[^`]+)`", full_table_name)
5454
return match["master"] + "`" if match else ""
5555

5656

@@ -149,3 +149,19 @@ def parse_sql(filepath):
149149
statement = []
150150
if statement:
151151
yield " ".join(statement)
152+
153+
154+
def parse_full_table_name(full_name):
155+
"""
156+
Parse a full table name like `schema`.`table` into (schema, table).
157+
158+
Handles special table name prefixes like ~ (hidden), # (lookup), etc.
159+
160+
:param full_name: full table name in format `schema`.`table`
161+
:return: tuple (schema, table)
162+
:raises DataJointError: if the format is invalid
163+
"""
164+
match = re.match(r"`([^`]+)`\.`([^`]+)`", full_name)
165+
if not match:
166+
raise DataJointError(f"Invalid table name format: {full_name}")
167+
return match.group(1), match.group(2)

0 commit comments

Comments
 (0)