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

Amazon Redshift で横串検索を実行する

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

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

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

始める前に

ワークスペースの要件:

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

コンピュートの要件:

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

必要な権限:

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

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

接続を作成する

接続では、外部データベースシステムにアクセスするためのパスと認証情報を指定します。接続を作成するには、カタログエクスプローラーを使用するか、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 details page of the Set up connection wizard, enter a user-friendly Connection name.

  4. Select a Connection type of Redshift.

  5. (Optional) Add a comment.

  6. Click Next.

  7. On the Authentication page, enter the following connection properties for your Redshift instance.

    • Host: For example, redshift-demo.us-west-2.redshift.amazonaws.com
    • Port: For example, 5439
    • User: For example, redshift_user
    • Password: For example, password123
  8. (Optional) Disable SSL hostname verification.

  9. Click Create connection.

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

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

  12. Click Create catalog.

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

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

  15. 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.
  16. Click Next.

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

  18. (Optional) Add a comment.

  19. Click Save.

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

注記

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.

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

次のプッシュダウンがサポートされています。

  • フィルター
  • 予測
  • 上限
  • テーブルのJOIN
  • 集計 (Average、Count、Max、Min、StddevPop、StddevSamp、Sum、VarianceSamp)
  • 関数 (文字列関数と、Alias、Cast、SortOrder などのその他の関数)
  • 分別

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

  • Windows の機能

データ型マッピング

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

Redshift タイプ

Spark タイプ

numeric

DecimalType

int2, int4

IntegerType

int8、oid、xid

LongType

float4

FloatType

double precision, float8, money

DoubleType

bpchar, char, character varying, name, super, text, tid, varchar

StringType

bytea, geometry, varbyte

BinaryType

bit, bool

BooleanType

日付

DateType

tabstime, time, time with time zone, timetz, time without time zone, timestamp with time zone, timestamp, timestamptz, timestamp without time zone*

TimestampType/TimestampNTZType

*Redshift から読み取ると、Redshift Timestamp は Spark TimestampType にマッピングされます ( infer_timestamp_ntz_type = false (デフォルト)。 Redshift Timestamp は、infer_timestamp_ntz_type = trueの場合、TimestampNTZType にマッピングされます。