Tutorial: Auto-refresh a Parquet Direct table from Google Cloud Storage¶
Introduction¶
This tutorial shows you how to create a Parquet Direct table: a read-only Apache Iceberg™ table in Snowflake that queries Apache Parquet™ files in your Google Cloud Storage (GCS) bucket in place. You configure Google Cloud Pub/Sub so that Snowflake is notified when files are added to or removed from the bucket, and refreshes the table automatically.
What you’ll learn¶
In this tutorial, you’ll learn how to do the following:
- Create a Pub/Sub topic and subscription for GCS object events.
- Create a notification integration and grant Snowflake access to the subscription.
- Create an external volume that uses the subscription.
- Create a catalog integration for Parquet files.
- Create a Parquet Direct table with schema inference, schema evolution, and auto-refresh.
- Verify that new files are registered automatically, and monitor auto-refresh.
Prerequisites¶
-
A Snowflake role with the following privileges:
- CREATE EXTERNAL VOLUME on the account.
- CREATE INTEGRATION on the account, to create the notification integration and catalog integration.
- CREATE ICEBERG TABLE on the schema where you create the table.
- USAGE on a warehouse to query the table.
-
A GCS bucket that contains, or will contain, your Parquet files.
-
Administrative access to Google Cloud, to create a Pub/Sub topic and subscription and manage IAM permissions. If you aren’t a Google Cloud administrator, ask your administrator to complete the Google Cloud steps.
Note
Auto-refresh is billed as serverless compute, and each refresh incurs data registration charges for the files it adds. For more information, see Billing.
Step 1: Create a Pub/Sub topic and subscription¶
Set up Google Cloud Pub/Sub so that your GCS bucket sends event notifications to Snowflake.
Create the Pub/Sub topic¶
Use Cloud Shell or the Cloud SDK to create a Pub/Sub topic that listens for object create and delete events in your bucket:
Where:
topicis the name for the topic. If the topic already exists, the command uses it; otherwise, the command creates a new topic.bucket_nameis the name of your GCS bucket.
For more information, see Pub/Sub notifications for Cloud Storage.
Create the Pub/Sub subscription¶
Create a subscription with pull delivery to the Pub/Sub topic by using the Google Cloud console, the gcloud command-line
tool, or the Cloud Pub/Sub API. For instructions, see
Managing topics and subscriptions.
Note
Snowflake supports only Pub/Sub subscriptions that use the default pull delivery. Push delivery isn’t supported.
Retrieve the Pub/Sub subscription ID¶
Record the subscription ID. You use it when you create the notification integration and the external volume.
-
Sign in to the Google Cloud console as a project editor.
-
Navigate to Pub/Sub » Subscriptions.
-
Copy the ID in the Subscription ID column for the topic subscription. The full name has the following format:
Step 2: Create a notification integration¶
Create a notification integration by using the CREATE NOTIFICATION INTEGRATION command. Use the subscription ID that you recorded:
Step 3: Grant Snowflake access to the Pub/Sub subscription¶
Grant the Snowflake service account permission to consume messages from your Pub/Sub subscription.
-
Run the DESCRIBE INTEGRATION command:
Note the value in the
GCP_PUBSUB_SERVICE_ACCOUNTcolumn. This value is the email address of the Snowflake service account that you grant access to. -
In the Google Cloud console, navigate to Pub/Sub » Subscriptions.
-
Select the subscription that you created, and select Add Principal.
-
Add the Snowflake service account email address from the
GCP_PUBSUB_SERVICE_ACCOUNTcolumn. -
Grant the service account the Pub/Sub Subscriber role (
roles/pubsub.subscriber).
Step 4: Create an external volume with your Pub/Sub subscription¶
Complete the instructions in Configure an external volume for Google Cloud Storage to create an external volume and grant Snowflake read access to your bucket. When you create the external volume, specify the following additional parameter on the storage location:
GCP_PUBSUB_SUBSCRIPTION_NAME = 'subscription_id'Specifies the Google Cloud Pub/Sub subscription that handles event messages for your external volume location.
For example:
Parquet Direct only reads from your storage, so a read-only permission set is sufficient. For the read-only permissions for each cloud provider, see Read-only vs write access for Delta Direct on each storage provider.
Step 5: Create a catalog integration¶
Create a catalog integration by using the CREATE CATALOG INTEGRATION (Object storage) command. Choose the table format that matches how your files are organized:
-
If your files use Hive-style
key=valuepartitioning (for example,orders/year=2024/month=01/part-0000.parquet), useTABLE_FORMAT = HIVEso that Snowflake infers partition columns from the paths: -
Otherwise, use
TABLE_FORMAT = NONE:
Step 6: Create a Parquet Direct table¶
Create a table by using the CREATE ICEBERG TABLE (Parquet files in object storage) command with AUTO_REFRESH = TRUE.
The following example omits the column list, so Snowflake infers the schema from your Parquet files. It also sets
ENABLE_SCHEMA_EVOLUTION = TRUE so that Snowflake evolves the schema on later refreshes:
Give each table its own BASE_LOCATION that doesn’t overlap with other tables. For more information, see
Give each table its own storage folder.
Tip
If the base location already contains a very large number of files, create the table with REFRESH_ON_CREATE = FALSE and
AUTO_REFRESH = FALSE, then enable auto-refresh, so the table is queryable immediately while existing files register in
the background. For more information, see Use auto-refresh when creating large tables.
Step 7: Verify auto-refresh¶
-
Query the table to confirm that Snowflake registered the existing files:
-
Upload a new Parquet file to the table’s base location; for example, by using the Google Cloud CLI:
-
Check the auto-refresh status. An
executionStateofRUNNINGmeans auto-refresh is healthy:For a description of each field, see SYSTEM$PARQUET_DIRECT_AUTO_REFRESH_STATUS.
-
After a short time, confirm that the new file was registered:
Query the table again to see the new rows.
If the file doesn’t appear, see Troubleshooting. To set up ongoing monitoring and alerts, see Monitor refresh.
Clean up¶
To remove the objects that you created in this tutorial, run the following commands. Dropping the table doesn’t delete your Parquet files in Google Cloud Storage.
If you no longer need them, also delete the Pub/Sub subscription, the Pub/Sub topic, and the bucket notification configuration in Google Cloud.
What’s next¶
- Learn about best practices, monitoring, troubleshooting, and billing in Parquet Direct.
- Compare Parquet Direct with Delta Direct in Direct Iceberg tables.
- See all parameters in CREATE ICEBERG TABLE (Parquet files in object storage).