従来のワークスペースHive metastoreのHive metastoreフェデレーションを有効にする
この記事では、レガシDatabricksHive metastore をフェデレーションして、組織がHive metastore を使用してUnity Catalog テーブルを操作できるようにする方法について説明します。
Hive metastoreフェデレーションの概要については、Hiveメタストアフェデレーション:Hiveメタストアに登録されているテーブルをUnity Catalog で管理できるようにします
始める前に
Hive metastore フェデレーションでサポートされているサービスと機能の一覧 (要件、サポートされている機能、制限事項) を確認します。
各ステップの具体的な要件は、以下のとおりです。
ステップ 1: Unity Catalog をHive metastoreに接続する
この手順では、Unity Catalog接続Databricks (データベース システムにアクセスするためのパスと資格情報 (この場合は ワークスペースのレガシ) を指定する セキュリティ保護可能なオブジェクト)Hive metastore を作成します。
必要条件
- Unity Catalog メタストアに対する
CREATE CONNECTION
特権。
接続を作成する
接続では、外部データベースシステムにアクセスするためのパスと認証情報を指定します。接続を作成するには、カタログエクスプローラーを使用するか、Databricksノートブックまたは Databricks SQLクエリーエディタで CREATE CONNECTION
SQLコマンドを使用できます。
Databricks REST API または Databricks CLI を使用して接続を作成することもできます。 POST /api/2.1/unity-catalog/connections を参照してください。 および Unity Catalog コマンド。
必要な権限: メタストア管理者またはCREATE CONNECTION
権限を持つユーザー。
- Catalog Explorer
- SQL
-
In your Databricks workspace, click
Catalog.
-
On the Quick access page, click Add data > Add a connection.
-
On the Connection basics page of the Set up connection wizard, enter a user-friendly Connection name.
-
Select a Connection type of Hive Metastore and Metastore type of Internal.
-
(Optional) Add a comment.
-
Click Next.
-
(Optional) On the Connection details page, enter the fully qualified path to the Hive Warehouse directory.
You need this only if you don’t want to use the default location.
-
Click Create connection.
-
On the Catalog basics page, enter a name for the foreign catalog.
-
For Authorized paths, choose cloud storage paths that can be accessed via the catalog. Only tables falling under these paths can be queried via the federated catalog. Paths must be covered by external locations. For more information, see What are authorized paths?.
-
Click Create catalog.
-
On the Access page, select the workspaces in which users can access the catalog you created. You can select All workspaces have access, or click Assign to workspaces, select the workspaces, and then click Assign.
-
Add an Owner who will be able to manage access to all objects in the catalog. Start typing a user or group in the text box, and then click the user or group in the returned results.
-
Grant Privileges on the catalog.
- Click Grant.
- Specify the Principals who will have access to objects in the catalog. Start typing a user or group in the text box, and then click the user or group in the returned results.
- Select the Privilege presets to grant to each user or group. All account users are granted
BROWSE
by default.- Select Data Reader from the drop-down menu to grant
read
privileges on objects in the catalog. - Select Data Editor from the drop-down menu to grant
read
andmodify
privileges on objects in the catalog. - Manually select the privileges to grant.
- Select Data Reader from the drop-down menu to grant
- Click Grant.
-
Click Next.
-
On the Metadata page, optionally specify tags as key-value pairs. For more information, see Apply tags to Unity Catalog securable objects.
-
(Optional) Add a comment.
-
Click Save.
Run the following command in a notebook or the SQL query editor.
CREATE CONNECTION IF NOT EXISTS <connection-name> TYPE hive_metastore
OPTIONS (
builtin true,
warehouse_directory '/path/to/warehouse-directory' );
Include warehouse_directory
only if you don’t want to use the default Hive warehouse directory location for your Hive metastore from the cluster configuration. This path is used to derive the location of managed tables or schemas when they are created from the federated catalog.
ステップ 2: 内部レガシ システムのデータ用の外部ロケーションを作成する Hive metastore
この手順では、 Unity Catalog で外部ロケーションを設定して、従来の内部 Hive metastoreに登録されたデータを保持するクラウド ストレージ ロケーションへのアクセスを制御します。
外部ロケーション は、Unity Catalog ストレージ資格情報 をクラウド ストレージ コンテナー パスに関連付ける セキュリティ保護可能なオブジェクトです。外部ロケーションとストレージの認証情報を参照してください。
必要条件
クラウド ストレージとDatabricksのアクセス許可の要件については、「クラウド ストレージを Databricksに接続するための外部ロケーションを作成する」の「始める前に」を参照してください。
ワークスペースのレガシー DBFSルートの外部ロケーションを作成する場合は、「DBFSルート内のデータの外部ロケーションを作成する」の「始める前に」を参照してください。
外部ロケーションを作成するためのオプション
Databricks Unity Catalogで外部ロケーションを作成するために推奨されるプロセスは、状況によって異なります。
- Unity CatalogAWSでストレージ認証情報を作成していない場合は、IAM ロールとストレージ認証情報を作成する CloudFormation テンプレートを使用して外部ロケーションを作成できます。「AWS CloudFormation テンプレートを使用して S3 バケットの外部ロケーションを作成する」の手順に従います。
- Unity Catalogで作成したストレージ認証情報がすでにある場合は、外部ロケーションを手動で作成します。「カタログ エクスプローラーを使用して外部ロケーションを手動で作成する」または「SQL を使用して外部ロケーションを作成する」の手順に従います。
- DBFSマウント DatabricksHive metastoreまたはDBFSルート にデータを格納する内部 をフェデレーションする場合は、外部ロケーションを手動で作成し 、[Copy fromDBFS mount] オプションを使用します。これは、適用可能なストレージ資格情報が存在するかどうかには関係ありません。 「カタログ エクスプローラーを使用して外部ロケーションを手動で作成する」または「DBFSルート内のデータ用の外部ロケーションを作成する」の手順に従います。
外部ロケーションでフォールバックモードを有効にする
Unity Catalogで外部ロケーションを作成するとすぐに、その外部ロケーションで表されるパスへのアクセスは、Unity Catalog対応コンピュートでクエリを実行するときにUnity Catalog権限によって強制されます。これにより、パスにアクセスするための適切な Unity Catalog アクセス許可を持たない既存のワークロードが中断される可能性があります。
外部ロケーションがフォールバックモードの場合、システムはまず、そのロケーションに対するクエリプリンシパルの Unity Catalog アクセス許可を確認し、それが成功しない場合は、インスタンスプロファイルや Apache Spark 設定プロパティなど、既存のクラスターまたはノートブックスコープの認証情報を使用してフォールバックし、既存のワークロードが中断なく実行し続けるようにします。
フォールバックモードは、レガシーワークロードの移行中に便利です。 Unity Catalogアクセス許可を使用して正常に実行するようにワークロードを更新したら、フォールバック モードを無効にして、従来のクラスター スコープの資格情報がUnity Catalog データ ガバナンスのバイパスに使用されないようにする必要があります。
フォールバック モードは、Catalog Explorer または Unity Catalog 外部ロケーション REST APIを使用して有効にできます。
必要な権限 : 外部ロケーションの所有者。
- Catalog Explorer
- API
- In your Databricks workspace, click
Catalog.
- On the Quick access page, click External data >.
- Select the external location you want to update.
- Turn on the Fallback mode toggle and click Enable to confirm.
The following curl examples show how to enable fallback mode when you create an external location and when you update an existing external location.
Creating a new external location:
curl -X POST -H 'Authorization: Bearer <token>' \
https://<workspace-URL>/api/2.1/unity-catalog/external-locations \
--data
'{
"name": "fallback_mode_enabled_external_location",
"url": "s3://external_location_bucket/url",
"credential_name": "external_location_credential",
"fallback": true
"skip_validation": true
}'
Updating an external location:
curl -X PATCH \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
https://<workspace-URL>/api/2.1/unity-catalog/external-locations/<external-location-name> \
--data
'{
"comment": "fallback mode enabled",
"fallback": true
}'
ステップ3:フォーリンカタログを作成する
Catalog Explorer の接続作成ウィザードを使用してステップ 1 を完了した場合は、この手順をすでに完了している可能性があります。ステップ 1 の完了時にフォーリンカタログを作成しなかった場合、または SQL を使用して接続を作成した場合は、このセクションの指示に従う必要があります。
このステップでは、ステップ 1 で作成した接続を使用して、ステップ 2 で作成した外部ロケーションを指すフォーリンカタログを Unity Catalog で作成します。 フォーリンカタログ は、外部データ システム内のデータベースまたはカタログをミラーリングする Unity Catalog 内のセキュリティ保護可能なオブジェクトであり、 Databricks ワークスペース内のそのデータに対してクエリを実行し、アクセスは Unity Catalogによって管理されます。 この場合、ミラーリングされたカタログは、 Hive metastoreに登録されているデータです。
ユーザーまたはワークフローがフォーリンカタログと対話するたびに、メタデータは Hive metastoreから同期されます。
必要条件
権限要件 :
フォーリンカタログを作成するには:
- Unity Catalog メタストアに対する
CREATE CATALOG
特権。 - 接続の所有権または接続に対する
CREATE FOREIGN CATALOG
権限。 - フォーリンカタログの許可パスを入力するには、それらのパスをカバーする外部ロケーションに対する
CREATE FOREIGN SECURABLE
権限が必要です。 外部ロケーションの所有者は、デフォルトによってこの特権を持っています。
フォーリンカタログを操作するには:
- カタログの所有権
USE CATALOG
コンピュートの要件 :
- Catalog Explorerを使用してカタログを作成するには、コンピュートは必要ありません。
- SQL を使用してカタログを作成するには: Databricks Runtime 13.3 LTS 以降。
- カタログを操作するには: Databricks Runtime 13.3 LTS、14.3 LTS、15.1以降の標準アクセスモードのコンピュート。
フォーリンカタログの作成
フォーリンカタログを作成するには、カタログ エクスプローラー、または Databricks ノートブックまたは SQL クエリ エディターのCREATE FOREIGN CATALOG
SQL コマンドを使用できます。
フォーリンカタログの管理と操作も参照してください。
Unity Catalog API を使用することもできます。 Databricks REST API リファレンスの カタログの作成 を参照してください。
- Catalog Explorer
- SQL
-
In your Databricks workspace, click
Catalog to open Catalog Explorer.
-
On the Quick access page, click the Add data botton and select Add a catalog .
-
Enter a Catalog name and select a catalog Type of Foreign.
-
Select the Connection that you created in Step 1 from the drop-down.
-
In the Authorized paths field, enter paths to the cloud storage locations that you defined as external locations in Step 2. For example,
s3://demo, s3://depts/finance
.Authorized paths are an added layer of security for foreign catalogs backed by Hive metastore federation. See What are authorized paths?.
-
Click Create.
-
(Optional) Click Configure to open a wizard that walks you through granting permissions on the catalog and adding tags. You can also perform these steps later.
See Manage privileges in Unity Catalog and Apply tags to Unity Catalog securable objects.
-
(Optional) Bind the catalog to specific workspaces.
By default, catalogs can be accessed from any workspace attached to the Unity Catalog metastore (restricted by user privileges). If you want to allow access only from specific workspaces, go to the Workspaces tab and assign workspaces. See Limit catalog access to specific workspaces.
-
Populate the foreign catalog with the Hive metastore metadata.
Any time a user or workflow interacts with the foreign catalog, metadata is synced from the Hive metastore. The first interaction populates the catalog in Unity Catalog and makes its contents visible in the Catalog Explorer UI. You can populate the catalog by selecting and starting a supported compute resource in Catalog Explorer. You must be the catalog owner (which you are by virtue of creating the catalog) or a user with the
USE CATALOG
privilege.
Run the following SQL command in a notebook or the SQL query editor. Items in brackets are optional. Replace the placeholder values:
<catalog-name>
: Name for the catalog in Databricks.<connection-name>
: The name of the connection object that you created in Step 1.<path1>,<path2>
: Paths to the cloud storage locations that you defined as external locations in Step 2. For example,s3://demo, s3://depts/finance
. Authorized paths are an added layer of security for foreign catalogs backed by Hive metastore federation. See What are authorized paths?. See What are authorized paths?. If you don't add authorized paths when you create the catalog, you can useALTER CATALOG
to add them later. See ALTER CATALOG.
CREATE FOREIGN CATALOG [IF NOT EXISTS] <catalog-name> USING CONNECTION <connection-name>
OPTIONS (authorized_paths '<path1>,<path2>');
Any time a user or workflow interacts with the federated catalog, metadata is synced from the Hive metastore.
フォーリンテーブルのストレージロケーションが DBFSにあり、テーブルをバックアップする DBFS マウントポイントが最後にアクセスされてから別のパスに再マッピングされている場合、テーブルへのアクセスは失敗し、UC_RESOLVED_DBFS_PATH_MISMATCH
エラーコードが表示されます。 次のコマンドを使用して、解決された DBFS の場所を更新し、エラーを修正します。
REFRESH FOREIGN TABLE my_federated_catalog.schema.table RESOLVE DBFS LOCATION;
OWNER であるか、テーブルに対する MANAGE 権限を持っている必要があります。フォーリンカタログ、SCHEMA、TABLEREFRESHを参照してください。