Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Criar e consultar tabelas do metastore no Spark
É possível consultar tabelas do Apache Spark Iceberg em um notebook do BigQuery usando mecanismos de código aberto, como o Spark. Essas tabelas são tabelas regulares do Iceberg com metadados armazenados no metastore do BigLake. A mesma tabela pode ser consultada no BigQuery e no Spark.
Antes de começar
Crie uma tabela do Iceberg usando o Spark em um notebook do BigQuery. O esquema da tabela é armazenado no metastore do BigLake. Por exemplo, é possível criar a tabela com o
Dataproc, o Dataproc sem servidor ou um
procedimento armazenado.
Ver e consultar uma tabela
Depois de criar os recursos do BigQuery no
Spark, é possível conferir e consultar esses recursos no
consoleGoogle Cloud . O exemplo a seguir mostra as etapas gerais para consultar uma tabela do metastore usando o Spark interativo:
Use o catálogo personalizado do Iceberg:
USE`CATALOG_NAME`;
Substitua:
CATALOG_NAME: o nome do catálogo do Spark que você está usando com seu job do SQL.
Para criar um namespace:
CREATENAMESPACEIFNOTEXISTSNAMESPACE_NAME;
Substitua:
NAMESPACE_NAME: o nome do namespace que
referencia sua tabela do Spark.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 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)."]]