Salesforce Data Cloudで横串検索を実行する
この記事では、 Databricksによって管理されていないSalesforce Data Cloudデータに対して横串検索を実行するようにレイクハウスフェデレーションを設定する方法について説明します。 レイクハウスフェデレーションの詳細については、「 レイクハウスフェデレーションとは」を参照してください。
レイクハウスフェデレーションを使用してSalesforce Data Cloudデータベースに接続するには、 Databricks Unity Catalog メタストアに次のものを作成する必要があります。
- Salesforce Data Cloud データベースへの接続。
- Salesforce Data CloudUnity Catalog Unity Catalogデータベースを にミラーリングする フォーリンカタログ で、 クエリ構文とデータガバナンスツールを使用してデータベースへのDatabricks ユーザーアクセスを管理できます。
始める前に
ワークスペースの要件:
- Unity Catalogのワークスペースが有効になっています。
コンピュートの要件:
- コンピュート・リソースからターゲット・データベース・システムへのネットワーク接続。 「レイクハウスフェデレーションのネットワーキングに関する推奨事項」を参照してください。
- Databricks コンピュートは、 Databricks Runtime 15.2 以降と Standard または Dedicated アクセス モードを使用する必要があります。
- SQLウェアハウスは Pro または サーバレスで、2024.30 以上を使用している必要があります。
必要な権限:
- 接続を作成するには、メタストア管理者か、ワークスペースに接続されているUnity Catalogメタストアの
CREATE CONNECTION
権限を持つユーザーである必要があります。 - フォーリンカタログを作成するには、メタストアに対する
CREATE CATALOG
権限を持ち、接続の所有者であるか、接続に対するCREATE FOREIGN CATALOG
権限を持っている必要があります。
追加の権限要件は、以下の各タスクベースのセクションに記載しています。
Salesforce 接続アプリケーションの作成
Salesforce 接続アプリケーションを使用すると、外部アプリケーションを APIs プロトコルと標準プロトコルを使用して Salesforce と統合できます。 このセクションでは、SSO を使用して接続アプリを作成し、Databricks が Salesforce で認証できるようにする方法について説明します。
詳細な手順については、Salesforce Data Cloud ドキュメントの「 接続アプリケーションの作成 」を参照してください。
Salesforce 接続アプリケーションを作成するには、次の手順を実行します。
-
Data Cloud の右上にある [ 設定 ] をクリックします。
-
[プラットフォームツール ] で、[ アプリ] > [アプリマネージャー ] をクリックします。
-
[新しい接続アプリケーション ] をクリックします。
-
[名前 ] と [Contact Eメール アドレス] を入力します。
-
OAuth 設定 を有効にします。
-
コールバック URL を
https://<databricks_instance_url>/login/oauth/salesforce.html
の形式で入力します。たとえば、https://cust-success.cloud.databricks.com/login/oauth/salesforce.html
のようになります。 -
(オプション)次のステップで SQL を使用して Databricks 接続とフォーリンカタログを作成する予定の場合、Salesforce 接続アプリケーションでリダイレクト URI
https://login.salesforce.com/services/oauth2/success
もサポートする必要があります。 Catalog Explorer を使用して [ Databricks ] 接続とフォーリンカタログを作成する予定の場合、この操作は必要ありません。 Databricks では、他の方法よりも手動の手順が少なくて済むため、Catalog Explorer の使用をお勧めします。 -
次の スコープ を追加します。
- すべてのデータ クラウド API リソースにアクセス ( cdp_api )
- APIs( api )によるユーザーデータの管理
- データクラウドデータに対するANSI SQLクエリの実行( cdp_query_api )
- いつでもリクエストを実行( 更新、offline_access )
-
[ 保存 ]をクリックします。
-
「 続行 」をクリックします。
-
-
[接続アプリケーションの概要 ] ページで、[ コンシューマの詳細の管理 ] をクリックします。認証を求められます。
-
認証が成功すると、 コンシューマキー と コンシューマシークレット が表示されます。 これらの値を保存します。 これらは、Databricks 接続を作成するときに必要になります。
Databricks 接続を作成する
接続では、外部データベースシステムにアクセスするためのパスと認証情報を指定します。接続を作成するには、カタログエクスプローラーを使用するか、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.
-
At the top of the Catalog pane, click the
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.
-
On the Connection basics page of the Set up connection wizard, enter a user-friendly Connection name.
-
Select a Connection type of Salesforce Data Cloud.
-
(Optional) Add a comment.
-
On the Authentication page, enter the following connection properties for your Salesforce Data Cloud:
- (Optional) Select Is sandbox.
- Client ID: Salesforce connected app consumer key.
- Client secret: Salesforce connected app consumer secret.
- Client scope:
cdp_api api cdp_query_api refresh_token offline_access
-
Click Sign in with Salesforce.
-
(OAuth) You are prompted to sign in to Salesforce Data Cloud using your SSO credentials.
-
Upon successful login you are directed back to the Databricks Set up connection wizard. The Sign in with Salesforce button has been replaced with a
Successfully authorized
message. -
Click Create connection.
-
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.
-
Enter the Salesforce data space.
-
(Optional) Click Test connection to confirm that it works.
-
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.
-
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.
-
Grant Privileges on the catalog. Click Grant:
- 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.
- 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
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, specify tags key-value pairs. For more information, see Apply tags to Unity Catalog securable objects.
-
(Optional) Add a comment.
-
Click Save.
Databricks recommends using Catalog Explorer to create the connection and the foreign catalog because it requires fewer manual steps than other methods.
If you plan to use SQL to create the Databricks connection and the foreign catalog, your Salesforce Connected App needs to support the redirect URI https://login.salesforce.com/services/oauth2/success
. This isn’t needed if you use Catalog Explorer.
-
Generate PKCE code verifier and code challenge codes. You can do this using an online tool such as https://tonyxu-io.github.io/pkce-generator/ or by running the following Python script:
Python%python
import base64
import re
import os
import hashlib
code_verifier = base64.urlsafe_b64encode(os.urandom(40)).decode('utf-8')
code_verifier = re.sub('[^a-zA-Z0-9]+', '', code_verifier)
code_challenge = hashlib.sha256(code_verifier.encode('utf-8')).digest()
code_challenge = base64.urlsafe_b64encode(code_challenge).decode('utf-8')
code_challenge = code_challenge.replace('=', '')
print(f"pkce_verifier = \"{code_verifier}\"")
print(f"code_challenge = \"{code_challenge}\"") -
Visit the following URL and authenticate with your Salesforce credentials to get the
authorization_code
(replace<client_id>
and<code_challenge>
with your parameters).https://login.salesforce.com/services/oauth2/authorize
?client_id=<client_id>
&redirect_uri=https://login.salesforce.com/services/oauth2/success
&response_type=code
&code_challenge=<code_challenge>A URL-encoded authorization code is visible in the redirected URL.
-
Run the following in a notebook or the Databricks SQL query editor:
SQLCREATE CONNECTION '<Connection name>' TYPE salesforce_data_cloud
OPTIONS (
client_id '<Consumer key from Salesforce Connected App>',
client_secret '<Consumer secret from Salesforce Connected App>',
pkce_verifier '<pkce_verifier from the last step>',
authorization_code '<URL decoded `authorization_code`, should end with == instead of %3D%3D>',
oauth_redirect_uri "https://login.salesforce.com/services/oauth2/success",
oauth_scope "cdp_api api cdp_query_api refresh_token offline access",
is_sandbox "false"
);Databricks recommends that you use Databricks secrets instead of plaintext strings for sensitive values like credentials. For example:
SQLCREATE CONNECTION '<Connection name>' TYPE salesforce_data_cloud
OPTIONS (
client_id secret ('<Secret scope>','<Secret key client id>'),
client_secret secret ('<Secret scope>','<Secret key client secret>'),
pkce_verifier '<pkce_verifier from the last step>',
authorization_code '<URL decoded `authorization_code`, should end with == instead of %3D%3D>',
oauth_redirect_uri "https://login.salesforce.com/services/oauth2/success",
oauth_scope "cdp_api api cdp_query_api refresh_token offline access",
is_sandbox "false"
);For information about setting up secrets, see Secret management.
フォーリンカタログの作成
UI を使用してデータソースへの接続を作成する場合は、フォーリンカタログの作成が含まれているため、この手順をスキップできます。
フォーリンカタログは、外部データシステム内のデータベースをミラーリングするため、DatabricksとUnity Catalogを使用して、そのデータベース内のデータへのアクセスを管理できます。フォーリンカタログを作成するには、すでに定義されているデータソースへの接続を使用します。
フォーリンカタログを作成するには、Catalog ExplorerCREATE FOREIGN CATALOG
SQL を使用するか、Databricks ノートブックまたは クエリSQL エディターの コマンドを使用します。Databricks REST API または Databricks CLI を使用してカタログを作成することもできます。 POST /api/2.1/unity-catalog/catalogs を参照してください。 および Unity Catalog コマンド。
必要な権限: メタストアの CREATE CATALOG
権限、接続の所有権または接続の CREATE FOREIGN CATALOG
権限。
- Catalog Explorer
- SQL
- In your Databricks workspace, click
Catalog to open Catalog Explorer.
- In the upper right, click Create Catalog.
- Enter the following properties for your Salesforce Data Cloud catalog.
- Catalog name: A user-friendly name for the catalog.
- Type:
Foreign
. - Connection name: The name of the connection the catalog will be created on.
- Dataspace: A Salesforce data space.
- Click Create.
Run the following SQL command in a notebook or the SQL query editor. Items in brackets are optional.
CREATE FOREIGN CATALOG [IF NOT EXISTS] '<catalog-name>' USING CONNECTION '<connection-name>'
OPTIONS (dataspace '<dataspace>');
Replace the following values:
<catalog-name>
:<connection-name>
:<dataspace>
: Salesforce data space. For example,default
.
サポートされているプッシュダウン
次のプッシュダウンがサポートされています。
- フィルター
- 予測
- 上限
- 集計
- offset
- キャスト
- 含む、開始、終了
データ型マッピング
Salesforce Data Cloud から Spark に読み取る場合、データ型は次のようにマップされます。
Salesforce Data Cloud タイプ | Spark タイプ |
---|---|
ブール値 | BooleanType |
日付 | DateType |
日時型 | TimestampType |
Eメール, 電話, テキスト, URL | StringType |
数、パーセント | 十進数タイプ (38、18) |
制限
- Databricks カタログごとに 1 つの Salesforce データ領域のみがサポートされています。
追加のリソース
レイクハウスフェデレーションは、Salesforce Sales Cloudへの読み取り専用接続 をサポートしていません が、 LakeFlow Connect では、Salesforce Sales Cloudから Databricks レイクハウスにデータを取り込むことができます。 「Salesforce からのデータの取り込み」を参照してください。