יצירה של טבלת Iceberg ב-Lakehouse ושליחת שאילתות אליה באמצעות מסוף Google Cloud

במדריך למתחילים הזה תשתמשו במסוף Google Cloud כדי ללמוד איך בעזרת Lakehouse ללא גבולות אפשר לנהל ולשתף טבלאות של Apache Iceberg ב- Google Cloud ובמנועי קוד פתוח, על ידי אחסון המטא-נתונים של הטבלאות, כולל סכימות, תמונות מצב ומיקומי אחסון, בקטלוג הייעודי לזמן ריצה של Lakehouse.

כדי להשלים את המדריך למתחילים, מבצעים את השלבים הבאים במסוףGoogle Cloud :

  1. יצירת קטגוריה של Cloud Storage: יוצרים קטגוריה ב-Cloud Storage כדי לאחסן את קובצי הנתונים והמטא-נתונים של טבלת Iceberg.
  2. יצירת קטלוג: יוצרים קטלוג עם כמה קטגוריות בקטלוג הייעודי לזמן ריצה של Lakehouse, שמגובה על ידי הקטגוריה שלכם עם הפצה של פרטי כניסה.
  3. יצירת מרחב שמות וטבלת Iceberg: משתמשים בדף Lakehouse במסוף Google Cloud כדי ליצור מרחב שמות וטבלת Iceberg עם שפת טיפול בנתונים (DML) של BigQuery.
  4. שינוי נתונים והרצת שאילתות בטבלה ב-BigQuery: משתמשים בהצהרות DML של BigQuery‏ (INSERT,‏ UPDATE ו-DELETE) כדי לשנות שורות בטבלת Iceberg, ומריצים שאילתות על התוצאות באמצעות התחביר P.C.N.T‏ (Project.Catalog.Namespace.Table) שמורכב מ-4 חלקים, בלי צורך ב-ETL או ברישום ידני של הטבלה.

לפני שמתחילים

  1. נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 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

יוצרים קטגוריה של Cloud Storage במסוף Google Cloud כדי לאחסן את קובצי הנתונים והמטא-נתונים של טבלת Iceberg:

  1. במסוף Google Cloud , נכנסים לדף Buckets של Cloud Storage.

    כניסה לדף Buckets

  2. לוחצים על יצירה.

  3. בקטע Get started, מזינים שם קטגוריה ייחודי ברמה גלובלית (לדוגמה, lakehouse-quickstart-UNIQUE_ID או PROJECT_ID-lakehouse) ולוחצים על Continue.

  4. בקטע Choose where to store your data, משאירים את ההגדרה Multi-region (us (multiple regions in United States)) בשדה Location type, ולוחצים על Create.

  5. אם מופיעה תיבת הדו-שיח Public access will be prevented, לוחצים על Confirm.

יצירת קטלוג בקטלוג הייעודי לזמן ריצה של Lakehouse

יוצרים קטלוג עם כמה קטגוריות בקטלוג הייעודי לזמן ריצה של Lakehouse לטבלאות Apache Iceberg. בקטלוג עם כמה קטגוריות, אתם יכולים לתת לקטלוג שם שלא תלוי בשם של קטגוריה כלשהי, ולשייך כמה קטגוריות של Cloud Storage לקטלוג אחד. כדי לאבטח את הגישה לקטגוריות האלה, צריך להפעיל את מצב הנפקת פרטי הכניסה, כדי שהקטלוג יוכל להנפיק באופן אוטומטי פרטי כניסה זמניים לאחסון ישירות למנועי הלקוח.

  1. נכנסים לדף Lakehouse במסוף Google Cloud .

    מעבר אל Lakehouse

  2. לוחצים על Create catalog ובוחרים באפשרות Lakehouse runtime catalog.

  3. בקטע Catalog type and source, קובעים את ההגדרות הבאות:

    • Catalog type: בוחרים באפשרות Iceberg Rest Catalog.
    • Lakehouse catalog bucket options: בוחרים באפשרות Multiple bucket catalog.
    • ‫Default Catalog Cloud Storage path: לוחצים על Browse, בוחרים את הקטגוריה שיצרתם ולוחצים על Select.
    • מזהה קטלוג: מזינים quickstart_catalog.
    • Primary location: בוחרים באפשרות מספר אזורים ואז באפשרות US (multiple regions in United States). השדה Jurisdiction מאוכלס באופן אוטומטי על סמך הקטגוריה.
  4. לוחצים על Continue, ובקטע נתיבי נתונים לוחצים על Continue.

  5. בקטע שיטת אימות, בוחרים באפשרות Credential vending mode.

    באמצעות הנפקת פרטי כניסה, הקטלוג מנפיק באופן מאובטח אסימוני אחסון זמניים ברמת הטבלה למנועי לקוחות ול-BigQuery, כך שמנועים חיצוניים לא צריכים הרשאות IAM ישירות בקטגוריה.

  6. לוחצים על יצירה.

    הקטלוג נוצר ונפתח הדף Catalog details.

  7. בקטע שיטת אימות, לוחצים על Set bucket permissions (או על Set permissions for buckets אם הקטלוג כולל כמה קטגוריות), ואז לוחצים על Confirm בתיבת הדו-שיח.

    בשלב הזה, חשבון השירות של הקטלוג מקבל את ההרשאות הנדרשות בקטגוריה של Cloud Storage כדי להנפיק פרטי כניסה זמניים.

יצירת מרחב שמות וטבלת Iceberg

אחרי שיצרתם קטלוג, אתם יכולים להשתמש בדף Lakehouse במסוףGoogle Cloud כדי ליצור מרחב שמות וטבלת Iceberg.

יצירת מרחב שמות

  1. בדף Catalog details של quickstart_catalog, לוחצים על Create namespace.

  2. בשדה Namespace name, מזינים את הערך quickstart_namespace.

  3. משאירים את Location בנתיב ברירת המחדל של Cloud Storage, שמאוכלס אוטומטית בשדה.

  4. לוחצים על יצירה.

יצירת טבלת Iceberg

  1. בדף פרטי הקטלוג, לוחצים על quickstart_namespace.

    הדף Namespace details נפתח.

  2. לוחצים על Create Table.

  3. בחלונית Create table, קובעים את ההגדרות הבאות:

    • פורמט הטבלה: מוודאים שהאפשרות Iceberg מסומנת.
    • ‫Table name: מזינים quickstart_table.
    • Location: משאירים את נתיב ברירת המחדל של Cloud Storage.
  4. בקטע Schema, לוחצים פעמיים על Add field כדי להוסיף שתי עמודות לטבלה:

    • בשדה הראשון, בשדה Field name, מזינים id ובתפריט Type בוחרים באפשרות INTEGER.
    • בשדה השני, בשדה Field name מזינים name ובתפריט Type בוחרים באפשרות STRING.
  5. בקטע Properties, מוצאים את המאפיין המוגדר מראש gcp.biglake.bigquery-dml.enabled ומשנים את הערך שלו (Value) מ-false ל-true. משאירים את הערך false בשדה gcp.biglake.table-management.enabled.

    הגדרת gcp.biglake.bigquery-dml.enabled ל-true מאפשרת לשנות נתונים בטבלת Iceberg באמצעות הצהרות DML של BigQuery כמו INSERT,‏ UPDATE,‏ DELETE ו-MERGE. מידע נוסף זמין במאמר הגדרת אפשרויות טבלה.

  6. לוחצים על יצירה.

    טבלת Iceberg החדשה (quickstart_table) מופיעה בדף Namespace details, והקטלוג הייעודי לזמן ריצה של Lakehouse כותב את קובץ המטא-נתונים הראשוני של Iceberg בקטגוריה של Cloud Storage.

שינוי נתונים והרצת שאילתות בטבלה ב-BigQuery

אחרי שיוצרים את quickstart_table ומפעילים את BigQuery DML, אפשר להוסיף, לעדכן, למחוק ולשלוח שאילתות לשורות ישירות ב-BigQuery באמצעות התחביר P.C.N.T (Project.Catalog.Namespace.Table) שמורכב מ-4 חלקים. בכל הצהרה, מחליפים את PROJECT_ID במזהה הפרויקט ב-Google Cloud :

  1. נכנסים לדף BigQuery במסוף Google Cloud .

    כניסה לדף BigQuery

  2. בעורך השאילתות, לוחצים על שאילתת SQL.

  3. כדי להוסיף נתונים לדוגמה, מזינים את ההצהרה הבאה בעורך השאילתות ולוחצים על Run:

    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.

  4. כדי לשנות שורה בטבלה, מזינים את ההצהרה הבאה בעורך השאילתות ולוחצים על Run:

    UPDATE `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    SET name = 'updated'
    WHERE id = 1;
  5. כדי למחוק שורה מהטבלה, מזינים את ההצהרה הבאה בעורך השאילתות ולוחצים על Run:

    DELETE FROM `PROJECT_ID.quickstart_catalog.quickstart_namespace.quickstart_table`
    WHERE id = 3;
  6. כדי לשלוח שאילתה לטבלה ולאמת את השינויים, מזינים את ההצהרה הבאה בעורך השאילתות ולוחצים על Run:

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

    בחלונית Query results מוצגות שתי השורות שנותרו, כולל הערך המעודכן של id = 1:

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

מכיוון שהקטלוג הייעודי לזמן ריצה של Lakehouse מנהל את המטא-נתונים של Iceberg והנפקת פרטי הכניסה מופעלת, אתם יכולים גם לקרוא מ-quickstart_table או לכתוב אליו באמצעות כל מנוע קוד פתוח שתואם ל-Iceberg, כמו Apache Spark,‏ Trino או Apache Flink, בלי לתת להם גישה ישירה ל-IAM לקטגוריה שלכם.

הסרת המשאבים

כדי למנוע חיובים מיותרים בחשבון Google Cloud , מחקו את המשאבים שיצרתם במדריך למתחילים הזה. כשמוחקים את הטבלה, מרחב השמות והקטלוג, רישום המטא-נתונים מוסר מהקטלוג הייעודי לזמן ריצה של Lakehouse. כשמוחקים את הקטגוריה, קובצי הנתונים של Parquet וקובצי המטא-נתונים של Iceberg שמאוחסנים ב-Cloud Storage מוסרים:

  1. נכנסים לדף Lakehouse במסוף Google Cloud .

    מעבר אל Lakehouse

  2. מוחקים את הטבלה מהקטלוג:

    1. לוחצים על quickstart_catalog ואז על quickstart_namespace.
    2. בשורה של quickstart_table, לוחצים על פעולות > מחיקה.
    3. בתיבת הדו-שיח לאישור, מזינים את הערך delete ולוחצים על Delete.
  3. מוחקים את מרחב השמות מהקטלוג:

    1. חוזרים לדף פרטי הקטלוג של quickstart_catalog.
    2. בשורה של quickstart_namespace, לוחצים על More namespace actions > Delete.
    3. בתיבת הדו-שיח לאישור, מזינים את הערך delete ולוחצים על Delete.
  4. כדי למחוק את הקטלוג:

    1. חוזרים לדף Lakehouse.
    2. בשורה של quickstart_catalog, לוחצים על פעולות נוספות בקטלוג > מחיקה.
    3. בתיבת הדו-שיח לאישור, מזינים את הערך delete ולוחצים על Delete.
  5. מוחקים את הקטגוריה של Cloud Storage ואת כל התוכן שלה:

    1. נכנסים לדף Buckets ב-Cloud Storage.

      כניסה לדף Buckets

    2. מסמנים את התיבה ליד הקטגוריה שיצרתם במדריך למתחילים, ולוחצים על Delete.

    3. בתיבת הדו-שיח לאישור, מזינים את הערך DELETE ולוחצים על Delete.

המאמרים הבאים