Google Cloud コンソールを使用して Lakehouse で Iceberg テーブルを作成してクエリを実行する

このクイックスタートでは、 Google Cloud コンソールを使用して、ボーダーレス Lakehouse で Apache Iceberg テーブルを管理し、 Google Cloud とオープンソース エンジン間で共有する方法を学習します。これには、スキーマ、スナップショット、ストレージ ロケーションなどのテーブル メタデータを Lakehouse ランタイム カタログに保存します。

このクイックスタートを完了するには、Google Cloud コンソールで次の操作を行います。

  1. Cloud Storage バケットを作成する: Cloud Storage にバケットを作成して、Iceberg テーブルのデータとメタデータ ファイルを保存します。
  2. カタログを作成する: 認証情報の自動販売が有効になっているバケットを基盤とする Lakehouse ランタイム カタログに、複数バケット カタログを作成します。
  3. 名前空間と Iceberg テーブルを作成する: Google Cloud コンソールの [Lakehouse] ページを使用して、BigQuery データ操作言語(DML)が有効になっている名前空間と Iceberg テーブルを作成します。
  4. BigQuery でデータを変更してテーブルをクエリする: BigQuery DML ステートメント(INSERT、UPDATE、DELETE)を使用して Iceberg テーブルの行を変更し、4 つの部分からなる P.C.N.T(Project.Catalog.Namespace.Table)構文を使用して結果をクエリします。ETL や手動のテーブル登録は必要ありません。

始める前に

  1. Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the BigLake, Cloud Storage, and BigQuery APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. Make sure that you have the following role or roles on the project: BigLake Admin (roles/biglake.admin), Storage Admin (roles/storage.admin), and BigQuery Job User (roles/bigquery.jobUser)

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. Verify that billing is enabled for your Google Cloud project.

  8. Enable the BigLake, Cloud Storage, and BigQuery APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  9. Make sure that you have the following role or roles on the project: BigLake Admin (roles/biglake.admin), Storage Admin (roles/storage.admin), and BigQuery Job User (roles/bigquery.jobUser)

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.

Cloud Storage バケットを作成する

Google Cloud コンソールで Cloud Storage バケットを作成し、Iceberg テーブルのデータとメタデータ ファイルを保存します。

  1. Google Cloud コンソールで Cloud Storage の [バケット] ページに移動します。

    [バケット] に移動

  2. [作成] をクリックします。

  3. [始める] セクションで、グローバルに一意のバケット名(lakehouse-quickstart-UNIQUE_ID や PROJECT_ID-lakehouse など)を入力し、[続行] をクリックします。

  4. [データの保存場所の選択] セクションで、[ロケーション タイプ] を [マルチリージョン](us(米国の複数のリージョン))に設定したまま、[作成] をクリックします。

  5. [公開アクセスの防止] ダイアログが表示されたら、[確認] をクリックします。

Lakehouse ランタイム カタログにカタログを作成する

Apache Iceberg テーブルの Lakehouse ランタイム カタログにマルチバケット カタログを作成します。複数バケット カタログを使用すると、バケット名とは別にカタログに名前を付け、複数の Cloud Storage バケットを 1 つのカタログに関連付けることができます。これらのバケットへのアクセスを保護するには、認証情報の自動販売モードを有効にして、カタログが一時ストレージ認証情報をクライアント エンジンに直接自動的に発行できるようにします。

  1. Google Cloud コンソールで、[Lakehouse] ページに移動します。

    [レイクハウス] に移動

  2. [カタログを作成] をクリックし、[Lakehouse ランタイム カタログ] を選択します。

  3. [カタログのタイプとソース] セクションで、次の設定を構成します。

    • カタログタイプ: [Iceberg Rest カタログ] を選択します。
    • Lakehouse カタログ バケットのオプション: [複数バケット カタログ] を選択します。
    • デフォルトのカタログの Cloud Storage パス: [参照] をクリックし、作成したバケットを選択して、[選択] をクリックします。
    • カタログ ID: 「quickstart_catalog」と入力します。
    • プライマリ ロケーション: [マルチリージョン] を選択してから、[US(米国の複数のリージョン)] を選択します。[Jurisdiction] フィールドは、バケットに基づいて自動的に入力されます。
  4. [続行] をクリックし、[データパス] セクションで [続行] をクリックします。

  5. [認証方法] セクションで、[認証情報の自動販売モード] を選択します。

    認証情報の提供により、カタログは一時的なテーブル スコープのストレージ トークンをクライアント エンジンと BigQuery に安全に発行します。そのため、外部エンジンはバケットに対する直接の IAM 権限を必要としません。

  6. [作成] をクリックします。

    カタログが作成され、[カタログの詳細] ページが開きます。

  7. [認証方法] で、[バケットの権限を設定](カタログが複数のバケットにまたがっている場合は [バケットの権限を設定])をクリックし、ダイアログで [確認] をクリックします。

    このステップでは、カタログのサービス アカウントに、一時的な認証情報を販売するために必要な Cloud Storage バケットに対する権限を付与します。

名前空間と Iceberg テーブルを作成する

カタログを作成したので、Google Cloud コンソールの [Lakehouse] ページを使用して、名前空間と Iceberg テーブルを作成します。

名前空間の作成

  1. quickstart_catalog の [カタログの詳細] ページで、[名前空間を作成] をクリックします。

  2. [Namespace name] フィールドに「quickstart_namespace」と入力します。

  3. [ロケーション] は、フィールドに自動的に入力されるデフォルトの Cloud Storage パスのままにします。

  4. [作成] をクリックします。

Iceberg テーブルを作成する

  1. [カタログの詳細] ページで、quickstart_namespace をクリックします。

    [Namespace の詳細] ページが開きます。

  2. [テーブルを作成] をクリックします。

  3. [テーブルを作成] ペインで、次の設定を構成します。

    • テーブル形式: [Iceberg] が選択されていることを確認します。
    • テーブル名: 「quickstart_table」と入力します。
    • ロケーション: デフォルトの Cloud Storage パスのままにします。
  4. [スキーマ] で、[フィールドを追加] を 2 回クリックして、テーブルに 2 つの列を追加します。

    • 最初のフィールドの [フィールド名] フィールドに「id」と入力し、[タイプ] メニューから [INTEGER] を選択します。
    • 2 番目のフィールドの [フィールド名] フィールドに「name」と入力し、[タイプ] メニューから [STRING] を選択します。
  5. [プロパティ] で、事前定義された gcp.biglake.bigquery-dml.enabled プロパティを見つけて、その [値] を false から true に変更します。gcp.biglake.table-management.enabled は false に設定したままにします。

    gcp.biglake.bigquery-dml.enabled を true に設定すると、INSERT、UPDATE、DELETE、MERGE などの BigQuery DML ステートメントを使用して Iceberg テーブルのデータを変更できます。詳細については、テーブル オプションを構成するをご覧ください。

  6. [作成] をクリックします。

    新しい Iceberg テーブル(quickstart_table)が [名前空間の詳細] ページに表示され、Lakehouse ランタイム カタログが最初の Iceberg メタデータ ファイルを Cloud Storage バケットに書き込みます。

BigQuery でデータを変更してテーブルをクエリする

quickstart_table を作成して BigQuery DML を有効にすると、4 つの部分からなる P.C.N.T(Project.Catalog.Namespace.Table)構文を使用して、BigQuery で行を直接挿入、更新、削除、クエリできます。各ステートメントで、PROJECT_ID を実際のGoogle Cloud プロジェクト ID に置き換えます。

  1. Google Cloud コンソールで、[BigQuery] ページに移動します。

    [BigQuery] に移動

  2. クエリエディタで、[SQL クエリ] をクリックします。

  3. サンプルデータを挿入するには、クエリエディタに次のステートメントを入力し、[実行] をクリックします。

    INSERT INTO `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table` (id, name)
    VALUES (1, 'one'), (2, 'two'), (3, 'three');

    INSERT ステートメントが完了すると、BigQuery は Parquet データファイルを Cloud Storage バケットに書き込み、新しい Iceberg スナップショットを Lakehouse ランタイム カタログに commit します。

  4. テーブルの行を変更するには、クエリエディタに次のステートメントを入力し、[実行] をクリックします。

    UPDATE `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    SET name = 'updated'
    WHERE id = 1;
  5. テーブルから行を削除するには、クエリエディタに次のステートメントを入力して、[実行] をクリックします。

    DELETE FROM `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    WHERE id = 3;
  6. テーブルをクエリして変更を確認するには、クエリエディタに次のステートメントを入力し、[実行] をクリックします。

    SELECT * FROM `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    ORDER BY id;

    [クエリ結果] ペインには、id = 1 の更新された値を含む、残りの 2 行が表示されます。

    +----+---------+
    | id | name    |
    +----+---------+
    |  1 | updated |
    |  2 | two     |
    +----+---------+
    

Lakehouse ランタイム カタログが Iceberg メタデータを管理し、認証情報の提供が有効になっているため、Apache Spark、Trino、Apache Flink などの Iceberg 互換のオープンソース エンジンを使用して quickstart_table の読み取りや書き込みを行うこともできます。この場合、バケットへの直接の IAM アクセス権を付与する必要はありません。

クリーンアップ

Google Cloud アカウントに不要な課金が発生しないようにするには、このクイックスタートで作成したリソースを削除します。テーブル、名前空間、カタログを削除すると、Lakehouse ランタイム カタログからメタデータ登録が削除されます。一方、バケットを削除すると、Cloud Storage に保存されている基盤となる Parquet データと Iceberg メタデータ ファイルが削除されます。

  1. Google Cloud コンソールで、[Lakehouse] ページに移動します。

    [レイクハウス] に移動

  2. カタログからテーブルを削除します。

    1. [quickstart_catalog]、[quickstart_namespace] の順にクリックします。
    2. quickstart_table の行で、 [アクション] > [削除] をクリックします。
    3. 確認ダイアログで「delete」と入力して確認し、[削除] をクリックします。
  3. カタログから名前空間を削除します。

    1. quickstart_catalog の [カタログの詳細] ページに戻ります。
    2. quickstart_namespace の行で、 [名前空間のその他の操作] > [削除] をクリックします。
    3. 確認ダイアログで「delete」と入力して確認し、[削除] をクリックします。
  4. カタログを削除します。

    1. [Lakehouse] ページに戻ります。
    2. quickstart_catalog の行で、 [カタログのその他の操作] > [削除] をクリックします。
    3. 確認ダイアログで「delete」と入力して確認し、[削除] をクリックします。
  5. Cloud Storage バケットとその内容をすべて削除します。

    1. Cloud Storage バケットのページに移動します。

      [バケット] に移動

    2. このクイックスタート用に作成したバケットの横にあるチェックボックスをオンにして、[削除] をクリックします。

    3. 確認ダイアログで「DELETE」と入力して確認し、[削除] をクリックします。

次のステップ