DROP CONNECTION (外部カタログ)

適用対象:チェックマーク付き:はい Databricks SQL チェックマーク付き:はい Databricks Runtime 17.3 以降

Important

この機能はパブリック プレビュー段階であり、現時点では参加しているお客様のみが利用できます。 プレビューに参加するには、 このフォームに入力して申請します。 この機能では、Hive Metastore (HMS) と Glue Federation を使用した外部カタログの接続の削除のみがサポートされます。

DROP CONNECTION コマンドを使用して、外部カタログを Unity カタログの標準カタログに変換します。 接続を削除した後、カタログは外部カタログから外部テーブルを同期しなくなります。 代わりに、マネージド テーブルまたは外部テーブルを含む標準の Unity カタログ カタログのように機能します。 Unity カタログで、あなたのカタログは外部ではなく標準としてラベル付けされました。 このコマンドは、外部カタログ内のテーブルには影響しません。Unity カタログ内の外部カタログにのみ影響します。

カタログに対する OWNER または MANAGE、 USE_CATALOG、および BROWSE のアクセス許可が必要です。

構文

ALTER CATALOG catalog_name DROP CONNECTION { RESTRICT | FORCE }

パラメーター

  • catalog_name

    標準カタログに変換する外部カタログの名前。

  • 制限

    既定の動作 DROP CONNECTION を使用した場合、カタログ内に外部テーブルまたは外部ビューがあると、カタログを外国カタログから標準カタログに変換する際に、RESTRICT が失敗します。

    外部テーブルを Unity カタログのマネージド テーブルまたは外部テーブルにアップグレードするには、「 SQL を使用した外部テーブル 」または 「外部テーブルを外部 Unity カタログ テーブルに変換する」を参照してください。 外部ビューを変換するには、「 SET MANAGED (FOREIGN VIEW)」を参照してください。

  • フォース

    DROP CONNECTION FORCEでは、外部カタログを標準カタログに変換するときに、外部カタログ内の残りの外部テーブルまたはビューを削除します。 このコマンドは、外部カタログ内のデータやメタデータを削除しません。外部テーブルを作成するために Unity カタログに同期されたメタデータのみが削除されます。

    Warnung

    このコマンドをロールバックすることはできません。 外部テーブルを Unity カタログにフェデレーションする場合は、外部カタログを再作成する必要があります。

例示

-- 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.

外部テーブルとビューをチェックするためのスクリプト

注

DROP CONNECTION RESTRICTを使用する前に、これらの Python スクリプトを使用して、Unity カタログ REST API を使用してカタログ内の外部テーブルとビューを確認できます。

フェデレーション カタログのすべての外部テーブルとビューを一覧表示するスクリプト:

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)

ACTIVE プロビジョニング状態のすべての外部テーブルとビューを一覧表示するスクリプト:

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)