Skip to content

Commit ed49b2e

Browse files
vuanhphungIsaac
andcommitted
test(e2e): cover hive_metastore and spark_catalog with escaped catalog names
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 86a6401 commit ed49b2e

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎tests/e2e/test_driver.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,32 @@ def test_escaped_catalog_name_matches_exact_catalog(self):
740740
escaped = sorted(tuple(r) for r in cursor.fetchall())
741741
assert escaped == unescaped
742742

743+
def test_hive_metastore_metadata_unchanged_by_escaping(self):
744+
# hive_metastore is the most common catalog name with `_`, so escaping must
745+
# not change its results; spark_catalog (its alias) must not lose rows.
746+
with self.connection({}) as escaped, self.connection(
747+
{"escape_catalog_name": False}
748+
) as raw:
749+
750+
def rows(conn, call, **filters):
751+
with conn.cursor() as cursor:
752+
getattr(cursor, call)(**filters)
753+
return {tuple(r) for r in cursor.fetchall()}
754+
755+
hms = {"catalog_name": "hive_metastore", "schema_name": "default"}
756+
expected = rows(raw, "schemas", **hms)
757+
if not expected:
758+
pytest.skip("hive_metastore.default is not visible")
759+
assert rows(escaped, "schemas", **hms) == expected
760+
761+
tables = rows(raw, "tables", **hms)
762+
if tables:
763+
one = dict(hms, table_name=min(t[2] for t in tables))
764+
assert rows(escaped, "tables", **one) == rows(raw, "tables", **one)
765+
766+
spark = {"catalog_name": "spark_catalog", "schema_name": "default"}
767+
assert rows(raw, "schemas", **spark) <= rows(escaped, "schemas", **spark)
768+
743769
@skipUnless(pysql_supports_arrow(), "arrow test need arrow support")
744770
@pytest.mark.parametrize(
745771
"extra_params",

‎tests/e2e/test_kernel_backend.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,21 @@ def test_tables_catalog_name_underscore_is_literal_by_default(
379379
assert all(row[0] == "system" for row in rows)
380380

381381

382+
def test_tables_hive_metastore_unchanged_by_escaping(kernel_conn_params):
383+
# Kernel tables() honours escape_catalog_name; hive_metastore is the most
384+
# common catalog name with `_`, so escaping must not change its results.
385+
def rows(extra_params, **filters):
386+
with sql.connect(**kernel_conn_params, **extra_params) as c, c.cursor() as cur:
387+
cur.tables(catalog_name="hive_metastore", schema_name="default", **filters)
388+
return {tuple(r) for r in cur.fetchall()}
389+
390+
listing = rows({"escape_catalog_name": False})
391+
if not listing:
392+
pytest.skip("hive_metastore.default is not visible")
393+
one = {"table_name": min(t[2] for t in listing)}
394+
assert rows({}, **one) == rows({"escape_catalog_name": False}, **one)
395+
396+
382397
def test_schemas_with_empty_string_filter_matches_nothing(conn):
383398
"""An empty string is a real pattern, distinct from absent ``None``."""
384399
with conn.cursor() as cur:

0 commit comments

Comments
 (0)