Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Membuat dan mengkueri tabel metastore dari Spark
Anda dapat membuat kueri tabel Apache Spark Iceberg di notebook BigQuery menggunakan mesin open source, seperti Spark. Tabel ini adalah tabel Iceberg reguler dengan metadata yang disimpan di metastore BigLake. Tabel yang sama dapat dikueri dari BigQuery dan Spark.
Sebelum memulai
Buat tabel Iceberg saat menggunakan Spark di notebook BigQuery. Skema tabel disimpan di
metastore BigLake. Misalnya, Anda dapat membuat tabel dengan
Dataproc, Dataproc Serverless, atau
prosedur tersimpan.
Pertimbangan
Hanya tabel Iceberg yang didukung.
Saat menjalankan kueri, jangan lupa untuk memetakan nama namespace dan database sebagai nama set data BigQuery. Tabel berikut mencantumkan
pemetaan tombol yang berlaku untuk digunakan:
Open source
BigQuery
Namespace
Set data BigQuery
Database
Set data BigQuery
Tabel (berpartisi atau tidak berpartisi)
Tabel BigQuery
Melihat dan membuat kueri tabel
Setelah membuat resource BigQuery di Spark, Anda dapat melihat dan membuat kueri di konsolGoogle Cloud . Contoh berikut menunjukkan langkah-langkah umum untuk membuat kueri tabel metastore menggunakan Spark interaktif:
Gunakan katalog Iceberg kustom:
USE`CATALOG_NAME`;
Ganti kode berikut:
CATALOG_NAME: nama katalog Spark yang Anda gunakan dengan tugas SQL.
Buat namespace
CREATENAMESPACEIFNOTEXISTSNAMESPACE_NAME;
Ganti kode berikut:
NAMESPACE_NAME: nama namespace yang
mereferensikan tabel Spark Anda.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-17 UTC."],[],[],null,["# Create and query metastore tables from Spark\n============================================\n\nYou can query Apache Spark Iceberg tables in a\nBigQuery notebook using open-source engines, such as\nSpark. These tables are regular\nIceberg tables with metadata stored in BigLake metastore. The\nsame table can be queried from both BigQuery and\nSpark.\n\nBefore you begin\n----------------\n\n- Create an Iceberg table while using Spark in a BigQuery notebook. The table schema is stored in BigLake metastore. For example, you can create the table with either [Dataproc](/bigquery/docs/blms-use-dataproc), [Dataproc Serverless](/bigquery/docs/blms-use-dataproc-serverless), or a [stored procedure](/bigquery/docs/blms-use-stored-procedures).\n\nView and query a table\n----------------------\n\nAfter creating your BigQuery resources in\nSpark, you can view and query them in the\nGoogle Cloud console. The following example shows you the general\nsteps to query a metastore table using interactive Spark:\n\n1. Use the custom Iceberg catalog:\n\n ```googlesql\n USE `\u003cvar translate=\"no\"\u003eCATALOG_NAME\u003c/var\u003e`;\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCATALOG_NAME\u003c/var\u003e: the name of the Spark catalog to that you're using with your SQL job.\n2. Create a namespace:\n\n ```googlesql\n CREATE NAMESPACE IF NOT EXISTS NAMESPACE_NAME;\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNAMESPACE_NAME\u003c/var\u003e: the namespace name that references your Spark table.\n3. Use the created namespace:\n\n ```googlesql\n USE NAMESPACE_NAME;\n ```\n4. Create an Iceberg table:\n\n ```googlesql\n CREATE TABLE TABLE_NAME (id int, data string) USING ICEBERG;\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e: a name for your Iceberg table.\n5. Insert a table row:\n\n ```googlesql\n INSERT INTO TABLE_NAME VALUES (1, \"first row\");\n ```\n6. Use the Google Cloud console to do one of the following:\n\n - [View the table metadata](/bigquery/docs/running-queries#queries)\n - [Query the table](/bigquery/docs/running-queries#queries)\n\n ```googlesql\n SELECT * FROM `\u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e`;\n ```\n\nWhat's next\n-----------\n\n- Set up [additional BigLake metastore features](/bigquery/docs/blms-features)."]]