メインコンテンツまでスキップ

Microsoft SQL Server でフェデレーション クエリを実行する

この記事では、 によって管理されていない データに対して横串検索を実行するようにレイクハウスフェデレーションを設定する方法について説明します。SQL ServerDatabricksレイクハウスフェデレーションの詳細については、「 レイクハウスフェデレーションとは」を参照してください。

レイクハウスフェデレーションを使用して SQL Server データベースに接続するには、 Databricks Unity Catalog メタストアに次のものを作成する必要があります。

  • SQL Server データベースへの接続。
  • SQL Server データベースを Unity Catalog にミラーリングして Unity Catalog クエリー構文とデータガバナンス ツールを使用してデータベースへの Databricks ユーザー アクセスを管理できるようにする フォーリンカタログ 。

レイクハウスフェデレーションは、 SQL Server、 Azure SQL Database、 Azure SQL Managed Instance をサポートしています。

始める前に

ワークスペースの要件:

  • Unity Catalogのワークスペースが有効になっています。

コンピュートの要件:

  • コンピュート・リソースからターゲット・データベース・システムへのネットワーク接続。 「レイクハウスフェデレーションのネットワーキングに関する推奨事項」を参照してください。
  • Databricks コンピュートは、 Databricks Runtime 13.3 LTS 以上、 および標準 または 専用 アクセスモードを使用する必要があります。
  • SQLウェアハウスはProまたはServerlessで、2023.40以上を使用している必要があります。

必要な権限:

  • 接続を作成するには、メタストア管理者か、ワークスペースに接続されているUnity Catalogメタストアの CREATE CONNECTION 権限を持つユーザーである必要があります。
  • フォーリンカタログを作成するには、メタストアに対する CREATE CATALOG 権限を持ち、接続の所有者であるか、接続に対する CREATE FOREIGN CATALOG 権限を持っている必要があります。

追加の権限要件は、以下の各タスクベースのセクションに記載しています。

  • OAuthを使用して認証する場合は、Microsoft Databricksの Entra ID アプリを登録する詳細については、次のセクションを参照してください。

(オプション)Databricks の Microsoft Entra ID にアプリを登録する

OAuth を使用して認証する場合は、SQL Server 接続を作成する前に、この手順に従ってください。 代わりにユーザー名とパスワードを使用して認証する場合は、このセクションをスキップしてください。

  1. Azure portal にサインインします。
  2. 左側のナビゲーションで、[ Microsoft Entra ID ] をクリックします。
  3. [アプリの登録] をクリックします。
  4. [ 新規登録 ] をクリックします。 新しいアプリの名前を入力し、リダイレクト URI を https://<workspace-url>/login/oauth/azure.htmlに設定します。
  5. 登録 をクリックします。
  6. [要点 ] ボックスで、 アプリケーション (クライアント) ID をコピーして保存します。この値を使用して、アプリケーションを構成します。
  7. 「証明書とシークレット 」をクリックします。
  8. クライアント シークレット タブで、 新しいクライアント シークレット をクリックします。
  9. シークレットの説明と有効期限を入力します (デフォルト設定は 180 日です)。
  10. [ 追加 ] をクリックします。
  11. クライアントシークレットに生成された値をコピーします。
  12. [ API のアクセス許可 ] をクリックします。
  13. [ 権限を追加 ] をクリックします。
  14. [Azure SQL Database ] を選択し 、[ 委任されたアクセス許可 ] で [user_impersonation] をクリックします。
  15. 権限を追加 」をクリックします。

接続を作成する

接続では、外部データベースシステムにアクセスするためのパスと認証情報を指定します。接続を作成するには、カタログエクスプローラーを使用するか、Databricksノートブックまたは Databricks SQLクエリーエディタで CREATE CONNECTION SQLコマンドを使用できます。

注記

Databricks REST API または Databricks CLI を使用して接続を作成することもできます。 POST /api/2.1/unity-catalog/connections を参照してください。 および Unity Catalog コマンド

必要な権限: メタストア管理者またはCREATE CONNECTION権限を持つユーザー。

  1. In your Databricks workspace, click Catalog icon Catalog.

  2. At the top of the Catalog pane, click the Add or plus icon Add icon and select Add a connection from the menu.

    Alternatively, from the Quick access page, click the External data button, go to the Connections tab, and click Create connection.

  3. On the Connection basics page of the Set up connection wizard, enter a user-friendly Connection name.

  4. Select a Connection type of SQL Server.

  5. Select an Auth type of OAuth or Username and password (basic authentication).

  6. (Optional) Add a comment.

  7. Click Next.

  8. On the Authentication page, enter the following connection properties for your SQL Server instance. Properties that are specific to the authentication method you selected are preceded by the Auth type in parentheses.

    • Host: Your SQL server.
    • (Basic authentication) Port
    • (Basic authentication) trustServerCertificate: Defaults to false. When set to true, the transport layer uses SSL to encrypt the channel and bypasses the certificate chain to validate trust. Leave this set to the default unless you have a specific need to bypass trust validation.
    • (Basic authentication) User
    • (Basic authentication) Password
    • (OAuth) Authorization Endpoint: Your Azure Entra authorization endpoint in the format https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/authorize.
    • (OAuth) Client ID from the app you created.
    • (OAuth) Client secret from the client secret you created.
    • (OAuth) OAuth scope: Enter the following value with no modifications: https://database.windows.net/.default offline_access.
    • (OAuth) Click Sign in with Azure Entra ID. Enter your Azure username and password. After you’re redirected to the Authentication page, the authorization code is populated in the UI.
  9. Click Create connection.

  10. (Basic authentication) On the Connection details page, specify the following:

    • Trust server certificate: This is deselected by default. When selected, the transport layer uses SSL to encrypt the channel and bypasses the certificate chain to validate trust. Leave this set to the default unless you have a specific need to bypass trust validation.
    • Application intent: The application workload type when connecting to a server.
  11. Click Next.

  12. On the Catalog basics page, enter a name for the foreign catalog. A foreign catalog mirrors a database in an external data system so that you can query and manage access to data in that database using Databricks and Unity Catalog.

  13. (Optional) Click Test connection to confirm that it works.

  14. Click Create catalog.

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

  16. Change the Owner who will be able to manage access to all objects in the catalog. Start typing a principal in the text box, and then click the principal in the returned results.

  17. Grant Privileges on the catalog. Click Grant:

    1. Specify the Principals who will have access to objects in the catalog. Start typing a principal in the text box, and then click the principal in the returned results.
    2. Select the Privilege presets to grant to each principal. 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 and modify privileges on objects in the catalog.
      • Manually select the privileges to grant.
    3. Click Grant.
  18. Click Next.

  19. On the Metadata page, specify tags key-value pairs. For more information, see Apply tags to Unity Catalog securable objects.

  20. (Optional) Add a comment.

  21. Click Save.

注記

(OAuth) The Azure Entra ID OAuth endpoint must be accessible from Databricks control plane IPs. See Databricks clouds and regions.

フォーリンカタログの作成

注記

UI を使用してデータソースへの接続を作成する場合は、フォーリンカタログの作成が含まれているため、この手順をスキップできます。

フォーリンカタログは、外部データシステム内のデータベースをミラーリングするため、DatabricksとUnity Catalogを使用して、そのデータベース内のデータへのアクセスを管理できます。フォーリンカタログを作成するには、すでに定義されているデータソースへの接続を使用します。

フォーリンカタログを作成するには、Catalog ExplorerCREATE FOREIGN CATALOGSQL を使用するか、Databricks ノートブックまたは クエリSQL エディターの コマンドを使用します。Databricks REST API または Databricks CLI を使用してカタログを作成することもできます。 POST /api/2.1/unity-catalog/catalogs を参照してください。 および Unity Catalog コマンド

必要な権限: メタストアの CREATE CATALOG 権限、接続の所有権または接続の CREATE FOREIGN CATALOG 権限。

  1. In your Databricks workspace, click Catalog icon Catalog to open Catalog Explorer.

  2. At the top of the Catalog pane, click the Add or plus icon Add icon and select Add a catalog from the menu.

    Alternatively, from the Quick access page, click the Catalogs button, and then click the Create catalog button.

  3. Follow the instructions for creating foreign catalogs in Create catalogs.

サポートされているプッシュダウン

次のプッシュダウンは、すべてのコンピュートでサポートされています。

  • フィルター
  • 予測
  • 上限
  • 関数: 部分的、フィルター式のみ。 (文字列関数、数学関数、データ関数、時刻関数、タイムスタンプ関数、およびエイリアス、キャスト、ソートオーダーなどのその他の関数)

次のプッシュダウンは、 Databricks Runtime 13.3 LTS 以降、および SQLウェアハウス コンピュートでサポートされています。

  • 集計
  • 次の Boolean 演算子: =、<、<=、>、>=、<=>
  • 次の数学関数 (ANSI が無効になっている場合はサポートされません): +、-、*、%、/
  • 次の雑多な演算子:^、|、~
  • ソート (制限付きで使用した場合)

次のプッシュダウンはサポートされていません。

  • テーブルのJOIN
  • Windows の機能

データ型マッピング

SQL Server から Spark に読み取る場合、データ型は次のようにマップされます。

SQL Server の種類

Spark タイプ

bigint (unsigned), decimal, money, numeric, smallmoney

DecimalType

smallint、tinyint

ShortType

int

IntegerType

bigint (signed)

LongType

real

FloatType

float

DoubleType

文字、n文字、一意の識別子

CharType

バーチャー、バーチャー

VarcharType

text, xml

StringType

binary, geography, geometry, image, timestamp, udt, varbinary

BinaryType

bit

BooleanType

日付

DateType

datetime, datetime, smalldatetime, time

TimestampType/TimestampNTZType

※ SQL Serverから読み込む場合、 SQL Server datetimesは Spark TimestampType``preferTimestampNTZ = false if (デフォルト)にマッピングされます。 SQL Server datetimes は、preferTimestampNTZ = trueの場合、TimestampNTZType にマップされます。