DROP CONNECTION (buitenlandse catalogus)

Van toepassing op:vinkje geplaatst Databricks SQL vinkje geplaatst Databricks Runtime 17.3 en hoger

Belangrijk

Deze functie bevindt zich in openbare preview en is op dit moment alleen beschikbaar voor deelnemende klanten. Als u wilt deelnemen aan de preview, moet u dit formulier invullen. Deze functie ondersteunt alleen het verwijderen van de verbinding voor buitenlandse catalogi met behulp van Hive Metastore (HMS) en Glue Federation.

Gebruik de DROP CONNECTION opdracht om een refererende catalogus te converteren naar een standaardcatalogus in Unity Catalog. Na het verbreken van de verbinding synchroniseert de catalogus niet langer buitenlandse tabellen van de externe catalogus. In plaats daarvan fungeert het als een standaard Unity Catalog-catalogus die beheerde of externe tabellen bevat. Uw catalogus is nu gelabeld als standaard in plaats van buitenlands in Unity Catalog. Deze opdracht heeft geen invloed op tabellen in uw externe catalogus; het heeft alleen invloed op uw vreemde catalogus in Unity Catalog.

Vereist OWNER of MANAGE, USE_CATALOG, en BROWSE machtigingen voor de catalogus.

Syntaxis

ALTER CATALOG catalog_name DROP CONNECTION { RESTRICT | FORCE }

Parameterwaarden

  • catalog_name

    De naam van de buitenlandse catalogus om te converteren naar een standaardcatalogus.

  • BEPERKEN

    Standaardgedrag. DROP CONNECTION met RESTRICT mislukt bij het converteren van de buitenlandse catalogus naar een standaardcatalogus als er buitenlandse tabellen of buitenlandse weergaven in de catalogus zijn.

    Als u refererende tabellen wilt upgraden naar beheerde of externe tabellen in Unity Catalog, raadpleegt u Een refererende tabel converteren naar een beheerde Unity Catalog-tabel of converteert u een refererende tabel naar een externe Unity Catalog-tabel. Zie SET MANAGED (FOREIGN VIEW) als u externe weergaven wilt converteren.

  • KRACHT

    DROP CONNECTION verwijdert FORCE eventuele resterende vreemde tabellen of weergaven in een vreemde catalogus bij het converteren van de vreemde catalogus naar een standaardcatalogus. Met deze opdracht worden geen gegevens of metagegevens in uw externe catalogus verwijderd; alleen de metagegevens die zijn gesynchroniseerd met Unity Catalog worden verwijderd om de vreemde tabel te creëren.

    Waarschuwing

    U kunt deze opdracht niet terugdraaien. Als u de buitenlandse tabellen weer wilt federeren in Unity Catalog, moet u de buitenlandse catalogus opnieuw maken.

Voorbeelden

-- Convert an existing foreign catalog using default RESTRICT behavior
> ALTER CATALOG hms_federated_catalog DROP CONNECTION;
OK

-- Convert an existing foreign catalog using FORCE to drop foreign tables
> ALTER CATALOG hms_federated_catalog DROP CONNECTION FORCE;
OK

-- RESTRICT fails if foreign tables or views exist
> ALTER CATALOG hms_federated_catalog DROP CONNECTION RESTRICT;
[CATALOG_CONVERSION_FOREIGN_ENTITY_PRESENT] Catalog conversion from UC Foreign to UC Standard failed because catalog contains foreign entities (up to 10 are shown here): <entityNames>. To see the full list of foreign entities in this catalog, please refer to the scripts below.

-- FORCE fails if catalog type isn't supported
> ALTER CATALOG redshift_federated_catalog DROP CONNECTION FORCE;
[CATALOG_CONVERSION_UNSUPPORTED_CATALOG_TYPE] Catalog cannot be converted from UC Foreign to UC Standard. Only HMS and Glue Foreign UC catalogs can be converted to UC Standard.

Scripts voor het controleren van buitenlandse tabellen en weergaven

Opmerking

Voordat u DROP CONNECTION RESTRICT gebruikt, kunt u deze Python-scripts gebruiken om te controleren op vreemde tabellen en weergaven in uw catalogus met behulp van de Unity Catalog REST API.

Script om alle buitenlandse tabellen en weergaven uit de federatieve catalogus op te sommen:

import requests

def list_foreign_uc_tables_and_views(catalog_name, pat_token, workspace_url):
    """
    Lists all foreign tables and views in the specified Unity Catalog.

    Args:
        catalog_name (str): The name of the catalog to search.
        pat_token (str): Personal Access Token for Databricks API authentication.
        workspace_url (str): Databricks workspace hostname (e.g., "https://adb-xxxx.x.azuredatabricks.net").

    Returns:
        list: A list of dictionaries containing information about the foreign tables/views.
    """
    base_url = f"{workspace_url}/api/2.1/unity-catalog"
    headers = {
        "Authorization": f"Bearer {pat_token}",
        "Content-Type": "application/json"
    }

    # Step 1: List all schemas in the catalog (GET request)
    schemas_url = f"{base_url}/schemas"
    schemas_params = {
        "catalog_name": catalog_name,
        "include_browse": "true"
    }

    schemas_resp = requests.get(schemas_url, headers=headers, params=schemas_params)
    schemas_resp.raise_for_status()
    schemas = schemas_resp.json().get("schemas", [])
    schema_names = [schema["name"] for schema in schemas]

    result = []

    # Step 2: For each schema, list all tables/views and filter (GET request)
    for schema_name in schema_names:
        tables_url = f"{base_url}/table-summaries"
        tables_params = {
            "catalog_name": catalog_name,
            "schema_name_pattern": schema_name,
            "include_manifest_capabilities": "true"
        }

        tables_resp = requests.get(tables_url, headers=headers, params=tables_params)
        tables_resp.raise_for_status()
        tables = tables_resp.json().get("tables", [])

        for table in tables:
            # Use OR for filtering as specified
            if (
                table.get("table_type") == "FOREIGN"
                or table.get("securable_kind") in {
                    "TABLE_FOREIGN_HIVE_METASTORE_VIEW",
                    "TABLE_FOREIGN_HIVE_METASTORE_DBFS_VIEW"
                }
            ):
                result.append(table.get("full_name"))

    return result

# Example usage:
# catalog = "hms_foreign_catalog"
# token = "dapiXXXXXXXXXX"
# workspace = "https://adb-xxxx.x.azuredatabricks.net"
# foreign_tables = list_foreign_uc_tables_and_views(catalog, token, workspace)
# for entry in foreign_tables:
#     print(entry)

Script voor het weergeven van alle vreemde tabellen en weergaven die zich in de actieve inrichtingstoestand bevinden.

import requests

def list_foreign_uc_tables_and_views(catalog_name, pat_token, workspace_url):
    """
    Lists all foreign tables and views in the specified Unity Catalog.

    Args:
        catalog_name (str): The name of the catalog to search.
        pat_token (str): Personal Access Token for Databricks API authentication.
        workspace_url (str): Databricks workspace hostname (e.g., "https://adb-xxxx.x.azuredatabricks.net").

    Returns:
        list: A list of dictionaries containing information about the foreign tables/views.
    """
    base_url = f"{workspace_url}/api/2.1/unity-catalog"
    headers = {
        "Authorization": f"Bearer {pat_token}",
        "Content-Type": "application/json"
    }

    # Step 1: List all schemas in the catalog (GET request)
    schemas_url = f"{base_url}/schemas"
    schemas_params = {
        "catalog_name": catalog_name,
        "include_browse": "true"
    }

    schemas_resp = requests.get(schemas_url, headers=headers, params=schemas_params)
    schemas_resp.raise_for_status()
    schemas = schemas_resp.json().get("schemas", [])
    schema_names = [schema["name"] for schema in schemas]

    result = []

    # Step 2: For each schema, list all tables/views and filter (GET request)
    for schema_name in schema_names:
        tables_url = f"{base_url}/table-summaries"
        tables_params = {
            "catalog_name": catalog_name,
            "schema_name_pattern": schema_name,
            "include_manifest_capabilities": "true"
        }

        tables_resp = requests.get(tables_url, headers=headers, params=tables_params)
        tables_resp.raise_for_status()
        tables = tables_resp.json().get("tables", [])

        for table in tables:
            # Use OR for filtering as specified
            if (
                table.get("table_type") == "FOREIGN"
                or table.get("securable_kind") in {
                    "TABLE_FOREIGN_HIVE_METASTORE_VIEW",
                    "TABLE_FOREIGN_HIVE_METASTORE_DBFS_VIEW"
                }
            ):
                table_full_name = table.get('full_name')
                get_table_url = f"{base_url}/tables/{table_full_name}"
                tables_params = {
                    "full_name": table_full_name,
                    "include_browse": "true",
                    "include_manifest_capabilities": "true"
                }

                table_resp = requests.get(get_table_url, headers=headers, params=tables_params)
                table_resp.raise_for_status()
                provisioning_info = table_resp.json().get("provisioning_info", dict()).get("state", "")

                if provisioning_info == "ACTIVE":
                    result.append(table_full_name)

    return result

# Example usage:
# catalog = "hms_foreign_catalog"
# token = "dapiXXXXXXXXXX"
# workspace = "https://adb-xxxx.x.azuredatabricks.net"
# foreign_tables = list_foreign_uc_tables_and_views(catalog, token, workspace)
# for entry in foreign_tables:
#     print(entry)