Membuat dan mengkueri tabel Iceberg di Lakehouse menggunakan konsol Google Cloud

Dalam panduan memulai ini, Anda akan menggunakan konsol Google Cloud untuk mempelajari cara Lakehouse tanpa batas memungkinkan Anda mengelola dan membagikan tabel Apache Iceberg di seluruh Google Cloud dan mesin open source dengan menyimpan metadata tabel, termasuk skema, snapshot, dan lokasi penyimpanan, di katalog runtime Lakehouse.

Untuk menyelesaikan panduan memulai ini, lakukan langkah-langkah berikut di konsolGoogle Cloud :

  1. Membuat bucket Cloud Storage: Buat bucket di Cloud Storage untuk menyimpan data tabel Iceberg dan file metadata Anda.
  2. Membuat katalog: Buat katalog multi-bucket di katalog runtime Lakehouse yang didukung oleh bucket Anda dengan mengaktifkan penyediaan kredensial.
  3. Membuat namespace dan tabel Iceberg: Gunakan halaman Lakehouse di konsol Google Cloud untuk membuat namespace dan tabel Iceberg dengan bahasa pengolahan data (DML) BigQuery diaktifkan.
  4. Mengubah data dan mengkueri tabel di BigQuery: Gunakan pernyataan DML BigQuery (INSERT, UPDATE, dan DELETE) untuk mengubah baris dalam tabel Iceberg dan mengkueri hasilnya menggunakan sintaksis 4 bagian P.C.N.T (Project.Catalog.Namespace.Table), tanpa memerlukan ETL atau pendaftaran tabel manual.

Sebelum memulai

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  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.

Membuat bucket Cloud Storage

Buat bucket Cloud Storage di konsol Google Cloud untuk menyimpan data tabel Iceberg dan file metadata Anda:

  1. Di konsol Google Cloud , buka halaman Buckets Cloud Storage.

    Buka Buckets

  2. Klik Create.

  3. Di bagian Get started, masukkan nama bucket yang unik secara global (misalnya, lakehouse-quickstart-UNIQUE_ID atau PROJECT_ID-lakehouse), lalu klik Continue.

  4. Di bagian Choose where to store your data, biarkan Location type ditetapkan ke Multi-region (us (multiple regions in United States)), lalu klik Create.

  5. Jika dialog Public access will be prevented muncul, klik Confirm.

Membuat katalog di katalog runtime Lakehouse

Buat katalog multi-bucket di katalog runtime Lakehouse untuk tabel Apache Iceberg Anda. Katalog multi-bucket memungkinkan Anda memberi nama katalog secara independen dari nama bucket mana pun dan mengaitkan beberapa bucket Cloud Storage dengan satu katalog. Untuk mengamankan akses ke bucket ini, aktifkan mode pemberian kredensial sementara agar katalog dapat otomatis menerbitkan kredensial penyimpanan sementara langsung ke mesin klien Anda.

  1. Di konsol Google Cloud , buka halaman Lakehouse.

    Buka Lakehouse

  2. Klik Create catalog, lalu pilih katalog runtime Lakehouse.

  3. Di bagian Catalog type and source, konfigurasikan setelan berikut:

    • Catalog type: Pilih Iceberg Rest Catalog.
    • Lakehouse catalog bucket options: Pilih Multiple bucket catalog.
    • Default Catalog Cloud Storage path: Klik Browse, pilih bucket yang Anda buat, lalu klik Select.
    • ID Katalog: Masukkan quickstart_catalog.
    • Primary location: Pilih Multi-region, lalu pilih US (multiple regions in United States). Kolom Jurisdiction diisi secara otomatis berdasarkan bucket.
  4. Klik Continue, lalu di bagian Jalur data, klik Continue.

  5. Di bagian Metode autentikasi, pilih Credential vending mode.

    Dengan penyediaan kredensial, katalog akan menerbitkan token penyimpanan sementara yang tercakup dalam tabel dengan aman ke mesin klien dan BigQuery, sehingga mesin eksternal tidak memerlukan izin IAM langsung di bucket Anda.

  6. Klik Create.

    Katalog Anda akan dibuat dan halaman Catalog details akan terbuka.

  7. Di bagian Metode autentikasi, klik Set bucket permissions (atau Set permissions for buckets jika katalog Anda mencakup beberapa bucket), lalu dalam dialog, klik Confirm.

    Langkah ini memberikan izin yang diperlukan kepada akun layanan katalog di bucket Cloud Storage Anda untuk menjual kredensial sementara.

Membuat namespace dan tabel Iceberg

Setelah memiliki katalog, gunakan halaman Lakehouse di konsolGoogle Cloud untuk membuat namespace dan tabel Iceberg.

Buat namespace

  1. Di halaman Catalog details untuk quickstart_catalog, klik Create namespace.

  2. Di kolom Namespace name, masukkan quickstart_namespace.

  3. Biarkan Location ditetapkan ke jalur Cloud Storage default yang otomatis diisi di kolom.

  4. Klik Create.

Membuat tabel Iceberg

  1. Di halaman Catalog details, klik quickstart_namespace.

    Halaman Namespace details akan terbuka.

  2. Klik Create Table.

  3. Di panel Create table, konfigurasi setelan berikut:

    • Table format: Pastikan Iceberg dipilih.
    • Table name: Masukkan quickstart_table.
    • Location: Biarkan jalur Cloud Storage default.
  4. Di bagian Schema, klik Add field dua kali untuk menambahkan dua kolom ke tabel:

    • Untuk kolom pertama, di kolom Field name, masukkan id, dan dari menu Type, pilih INTEGER.
    • Untuk kolom kedua, di kolom Field name, masukkan name, dan dari menu Type, pilih STRING.
  5. Di bagian Properties, temukan properti gcp.biglake.bigquery-dml.enabled yang telah ditetapkan dan ubah Value-nya dari false menjadi true. Biarkan gcp.biglake.table-management.enabled ditetapkan ke false.

    Dengan menetapkan gcp.biglake.bigquery-dml.enabled ke true, Anda dapat mengubah data dalam tabel Iceberg menggunakan pernyataan DML BigQuery seperti INSERT, UPDATE, DELETE, dan MERGE. Untuk mengetahui informasi selengkapnya, lihat Mengonfigurasi opsi tabel.

  6. Klik Create.

    Tabel Iceberg baru Anda (quickstart_table) akan muncul di halaman Namespace details, dan katalog runtime Lakehouse akan menulis file metadata Iceberg awal ke bucket Cloud Storage Anda.

Mengubah data dan membuat kueri tabel di BigQuery

Setelah quickstart_table dibuat dan DML BigQuery diaktifkan, Anda dapat menyisipkan, memperbarui, menghapus, dan mengkueri baris langsung di BigQuery menggunakan sintaksis 4 bagian P.C.N.T (Project.Catalog.Namespace.Table). Dalam setiap pernyataan, ganti PROJECT_ID dengan project ID Google Cloud Anda:

  1. Di konsol Google Cloud , buka halaman BigQuery.

    Buka BigQuery

  2. Di editor kueri, klik Kueri SQL.

  3. Untuk menyisipkan data sampel, masukkan pernyataan berikut ke dalam editor kueri, lalu klik Run:

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

    Setelah pernyataan INSERT selesai, BigQuery akan menulis file data Parquet ke bucket Cloud Storage Anda dan meng-commit snapshot Iceberg baru ke katalog runtime Lakehouse.

  4. Untuk mengubah baris dalam tabel, masukkan pernyataan berikut ke dalam editor kueri, lalu klik Run:

    UPDATE `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    SET name = 'updated'
    WHERE id = 1;
  5. Untuk menghapus baris dari tabel, masukkan pernyataan berikut ke editor kueri, lalu klik Run:

    DELETE FROM `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    WHERE id = 3;
  6. Untuk mengkueri tabel dan memverifikasi perubahan Anda, masukkan pernyataan berikut ke editor kueri, lalu klik Run:

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

    Panel Query results menampilkan dua baris yang tersisa, termasuk nilai yang diperbarui untuk id = 1:

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

Karena katalog runtime Lakehouse mengelola metadata Iceberg dan penjualan kredensial diaktifkan, Anda juga dapat membaca dari atau menulis ke quickstart_table menggunakan mesin open source yang kompatibel dengan Iceberg, seperti Apache Spark, Trino, atau Apache Flink, tanpa memberi mereka akses IAM langsung ke bucket Anda.

Pembersihan

Agar akun Google Cloud Anda tidak dikenai biaya yang tidak perlu, hapus resource yang Anda buat dalam panduan memulai ini. Menghapus tabel, namespace, dan katalog akan menghapus pendaftaran metadata dari katalog runtime Lakehouse, sedangkan menghapus bucket akan menghapus data Parquet dan file metadata Iceberg yang mendasarinya yang disimpan di Cloud Storage:

  1. Di konsol Google Cloud , buka halaman Lakehouse.

    Buka Lakehouse

  2. Hapus tabel dari katalog Anda:

    1. Klik quickstart_catalog, lalu klik quickstart_namespace.
    2. Di baris untuk quickstart_table, klik Tindakan > Hapus.
    3. Dalam dialog konfirmasi, masukkan delete untuk mengonfirmasi, lalu klik Delete.
  3. Hapus namespace dari katalog Anda:

    1. Kembali ke halaman Catalog details untuk quickstart_catalog.
    2. Di baris untuk quickstart_namespace, klik Tindakan namespace lainnya > Hapus.
    3. Dalam dialog konfirmasi, masukkan delete untuk mengonfirmasi, lalu klik Delete.
  4. Menghapus katalog Anda:

    1. Kembali ke halaman Lakehouse.
    2. Di baris untuk quickstart_catalog, klik Tindakan katalog lainnya > Hapus.
    3. Dalam dialog konfirmasi, masukkan delete untuk mengonfirmasi, lalu klik Delete.
  5. Hapus bucket Cloud Storage Anda dan semua isinya:

    1. Buka halaman Bucket Cloud Storage.

      Buka Buckets

    2. Centang kotak di samping bucket yang Anda buat untuk panduan memulai ini, lalu klik Delete.

    3. Dalam dialog konfirmasi, masukkan DELETE untuk mengonfirmasi, lalu klik Delete.

Langkah berikutnya