Code examples: Apache Spark™¶
This section provides code examples for using Apache Spark™ to do the following tasks in Snowflake Open Catalog:
- Configure a service connection
- Use a catalog
- List catalogs
- List namespaces
- Create a namespace
- Use a namespace
- Drop a namespace
- Create a table
- Query a table
- Show table properties
- List tables
- Drop a table
Required privileges¶
To perform the commands included in the code examples, the following privileges must be bestowed to the service principal you use to connect Spark to Open Catalog:
| Command | Required privilege |
|---|---|
| Show Namespaces | NAMESPACE_LIST |
| Create namespace | NAMESPACE_CREATE |
| Use namespace | NAMESPACE_READ_PROPERTIES |
| Show tables | TABLE_LIST |
| Create or replace table |
|
| Drop namespace | NAMESPACE_DROP |
| Drop table | TABLE_DROP |
| Insert into table | TABLE_WRITE_DATA |
| Select from table | TABLE_READ_DATA |
Configure a service connection¶
Use catalog¶
Use the catalog catalog1:
List catalogs¶
List the catalogs you’re connected to:
List namespaces¶
List the namespaces for the catalog you’re connected to:
Create a namespace¶
Create the namespace namespace1:
Use a namespace¶
Use the namespace namespace1:
Drop a namespace¶
Drop the namespace namespace1 from the catalog:
Create a table¶
Create a customers table under the parent namespace namespace1:
Query a table¶
Query the customers table:
Show table properties¶
Show the table properties for the customers table:
List tables¶
List the tables for the catalog you’re connected to:
Drop a table¶
Drop the customers table under parent namespace namespace1: