Membuat dan membuat kueri tabel Iceberg di Lakehouse menggunakan Google Cloud konsol

Dalam panduan memulai ini, Anda akan menggunakan Google Cloud konsol 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, dalam katalog runtime Lakehouse.

Untuk menyelesaikan panduan memulai ini, Anda akan melakukan langkah-langkah berikut di konsolGoogle Cloud :

  1. Buat bucket Cloud Storage: Buat bucket di Cloud Storage untuk menyimpan file data dan metadata tabel Iceberg Anda.
  2. Buat katalog: Buat katalog multi-bucket di katalog runtime Lakehouse yang didukung oleh bucket Anda dengan pengaktifan penyediaan kredensial.
  3. Buat 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. Ubah data dan kueri tabel di BigQuery: Gunakan pernyataan DML BigQuery (INSERT, UPDATE, dan DELETE) untuk mengubah baris dalam tabel Iceberg dan kueri hasilnya menggunakan sintaksis P.C.N.T (Project.Catalog.Namespace.Table) 4 bagian, tanpa perlu 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 file data dan metadata tabel Iceberg 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 disetel 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 terpisah dari nama bucket dan mengaitkan beberapa bucket Cloud Storage dengan satu katalog. Untuk mengamankan akses ke bucket ini, aktifkan mode pemberian kredensial sementara agar katalog dapat secara otomatis mengeluarkan kredensial penyimpanan sementara langsung ke mesin klien Anda.

  1. Di konsol Google Cloud , buka halaman Lakehouse.

    Buka Lakehouse

  2. Klik Buat katalog, lalu pilih Katalog runtime Lakehouse.

  3. Di bagian Detail katalog, konfigurasi setelan berikut:

    • Jenis katalog: Pilih Iceberg Rest Catalog.
    • Opsi bucket katalog lakehouse: Pilih Katalog beberapa bucket.
    • Jalur Cloud Storage Katalog Default: Klik Browse, pilih bucket yang Anda buat, lalu klik Select.
    • ID Katalog: Masukkan quickstart_catalog.
    • Lokasi utama: Pilih Multi-region, lalu pilih US (multiple regions in United States).
  4. Klik Lanjutkan, lalu di bagian Jalur data, klik Lanjutkan.

  5. Di bagian Metode autentikasi, pilih Mode penyediaan kredensial.

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

  6. Klik Create.

    Katalog Anda telah dibuat dan halaman Detail katalog akan terbuka.

  7. Di bagian Authentication method, klik Set bucket permissions, lalu di dialog, klik Confirm.

    Langkah ini memberikan izin yang diperlukan ke 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 disetel ke jalur Cloud Storage default yang diisi secara otomatis di kolom.

  4. Klik Create.

Membuat tabel Iceberg

  1. Di halaman Catalog Details, klik quickstart_namespace.

    Halaman Namespace Details akan terbuka.

  2. Klik Buat Tabel.

  3. Di panel Create Table, konfigurasi setelan berikut:

    • Table format: Pastikan Iceberg dipilih.
    • Nama tabel: 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, masukkan id di kolom Nama kolom, dan pilih INTEGER dari menu Jenis.
    • Untuk kolom kedua, masukkan name di kolom Field name, dan pilih STRING dari menu Type.
  5. Di bagian Properties, temukan properti gcp.biglake.bigquery-dml.enabled yang telah ditentukan sebelumnya dan ubah Value-nya dari false menjadi true. Biarkan gcp.biglake.table-management.enabled disetel ke false.

    Dengan menyetel gcp.biglake.bigquery-dml.enabled ke true, Anda dapat mengubah data di 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 Detail namespace, dan katalog runtime Lakehouse akan menulis file metadata Iceberg awal ke bucket Cloud Storage Anda.

Ubah data dan kueri tabel di BigQuery

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

  1. Di konsol Google Cloud , buka halaman BigQuery.

    Buka BigQuery

  2. Di editor kueri, klik Kueri SQL.

  3. Masukkan tiga baris data sampel:

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

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

  4. Ubah baris dalam tabel:

    UPDATE `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    SET name = 'updated'
    WHERE id = 1;

    Klik Run.

  5. Menghapus baris dari tabel:

    DELETE FROM `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    WHERE id = 3;

    Klik Run.

  6. Buat kueri tabel untuk memverifikasi perubahan Anda:

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

    Klik Run. 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 penyediaan kredensial diaktifkan, Anda juga dapat membaca atau menulis ke quickstart_table menggunakan mesin open source yang kompatibel dengan Iceberg, seperti Apache Spark, Trino, atau Apache Flink, tanpa memberikan akses IAM langsung ke bucket Anda.

Pembersihan

Agar tidak menimbulkan biaya yang tidak perlu pada akun Google Cloud Anda, 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 file data Parquet dan 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 tabel Namespace details, di baris untuk quickstart_table, klik More > Delete.
    3. Masukkan DELETE untuk mengonfirmasi, lalu klik Hapus.
  3. Hapus namespace dari katalog Anda:

    1. Kembali ke halaman Detail katalog untuk quickstart_catalog.
    2. Di baris untuk quickstart_namespace, klik Tindakan namespace lainnya > Hapus.
    3. Masukkan DELETE untuk mengonfirmasi, lalu klik Hapus.
  4. Menghapus katalog Anda:

    1. Kembali ke halaman Lakehouse.
    2. Di baris untuk quickstart_catalog, klik Tindakan katalog lainnya > Hapus.
    3. Masukkan DELETE untuk mengonfirmasi, lalu klik Hapus.
  5. Hapus bucket Cloud Storage 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. Masukkan DELETE untuk mengonfirmasi, lalu klik Hapus.

Langkah berikutnya