Skip to content

Commit 7879089

Browse files
committed
test: document JDBC-compatible metadata backslash escaping
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent 2463ec8 commit 7879089

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎src/databricks/sql/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
def escape_metadata_catalog_name(
5050
catalog_name: Optional[str], enabled: bool
5151
) -> Optional[str]:
52-
"""Escape unescaped underscores, preserving existing escapes and % wildcards."""
52+
r"""Match JDBC: escape _ unless immediately preceded by \; preserve %."""
5353
if not enabled or catalog_name is None:
5454
return catalog_name
5555
return re.sub(r"(?<!\\)_", r"\\_", catalog_name)

‎tests/unit/test_kernel_client.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,17 @@ def test_sync_execute_leaves_rowcount_default_when_num_modified_rows_none():
18611861
("a_b_c", r"a\_b\_c"),
18621862
(r"my\_catalog", r"my\_catalog"),
18631863
(r"a\_b_c%", r"a\_b\_c%"),
1864+
# Match JDBC: preserve the final \_ pair regardless of backslash parity.
1865+
pytest.param(
1866+
r"my\\_cat_tail",
1867+
r"my\\_cat\_tail",
1868+
id="jdbc-even-backslash-run",
1869+
),
1870+
pytest.param(
1871+
r"my\\\_cat_tail",
1872+
r"my\\\_cat\_tail",
1873+
id="jdbc-odd-backslash-run",
1874+
),
18641875
],
18651876
)
18661877
def test_metadata_catalog_escaping(

‎tests/unit/test_thrift_backend.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ def retry_policy_factory():
7373
("a_b_c", r"a\_b\_c"),
7474
(r"my\_catalog", r"my\_catalog"),
7575
(r"a\_b_c%", r"a\_b\_c%"),
76+
# Match JDBC: preserve the final \_ pair regardless of backslash parity.
77+
pytest.param(
78+
r"my\\_cat_tail",
79+
r"my\\_cat\_tail",
80+
id="jdbc-even-backslash-run",
81+
),
82+
pytest.param(
83+
r"my\\\_cat_tail",
84+
r"my\\\_cat\_tail",
85+
id="jdbc-odd-backslash-run",
86+
),
7687
],
7788
)
7889
def test_metadata_catalog_escaping(

0 commit comments

Comments
 (0)